From 73b113ff952ce3825b525b226b36ccdb2fdf194f Mon Sep 17 00:00:00 2001 From: Pavel Janda Date: Sun, 3 May 2020 23:07:27 +0200 Subject: [PATCH] ublaboo -> contributte --- .docs/README.md | 140 ++++++++++++++ README.md | 172 ++++-------------- composer.json | 10 +- src/ApiRoute.php | 8 +- src/ApiRouteSpec.php | 10 +- src/DI/ApiRouterExtension.php | 10 +- src/DI/ApiRoutesResolver.php | 10 +- .../ApiRouteWrongPropertyException.php | 2 +- .../ApiRouteWrongRouterException.php | 2 +- tests/cases/ApiRouteSpecTest.phpt | 14 +- tests/cases/ApiRouteTest.phpt | 4 +- tests/cases/ApiRoutesResolverTest.phpt | 8 +- 12 files changed, 204 insertions(+), 186 deletions(-) create mode 100644 .docs/README.md diff --git a/.docs/README.md b/.docs/README.md new file mode 100644 index 0000000..eb62faf --- /dev/null +++ b/.docs/README.md @@ -0,0 +1,140 @@ +# ApiRouter + +RESTful Router for your Apis in Nette Framework - created either directly or via annotation + +## Installation + +ApiRouter is available on composer: + +``` +composer require contributte/api-router +``` + +## Usage + +### Using annotation + +```php +namespace App\ResourcesModule\Presenters; + +use Nette; +use Contributte\ApiRouter\ApiRoute; + +/** + * API for managing users + * + * @ApiRoute( + * "/api-router/api/users[/]", + * parameters={ + * "id"={ + * "requirement": "\d+", + * "default": 10 + * } + * }, + * priority=1, + * presenter="Resources:Users" + * ) + */ +class UsersPresenter extends Nette\Application\UI\Presenter +{ + + /** + * Get user detail + * + * @ApiRoute( + * "/api-router/api/users/[/-]", + * parameters={ + * "id"={ + * "requirement": "\d+" + * } + * }, + * method="GET", + * } + * ) + */ + public function actionRead($id, $foo = NULL, $bar = NULL) + { + $this->sendJson(['id' => $id, 'foo' => $foo, 'bar' => $bar]); + } + + + public function actionUpdate($id) + { + $this->sendJson(['id' => $id]); + } + + + public function actionDelete($id) + { + $this->sendJson(['id' => $id]); + } +} +``` + +Now 3 routes will be created (well, 2, but the one accepts both PUT and DELETE method). + +If you don't want to create route with DELETE method, simply remove the `UsersPresenter::actionDelete()` method. + +### Using Nette Router + +```php +namespace App; + +use Nette; +use Nette\Application\Routers\RouteList; +use Nette\Application\Routers\Route; +use Contributte\ApiRouter\ApiRoute; + +class RouterFactory +{ + + /** + * @return Nette\Application\IRouter + */ + public function createRouter() + { + $router = new RouteList; + + /** + * Simple route with matching (only if methods below exist): + * GET => UsersPresenter::actionRead() + * POST => UsersPresenter::actionCreate() + * PUT => UsersPresenter::actionUpdate() + * DELETE => UsersPresenter::actionDelete() + */ + $router[] = new ApiRoute('/hello', 'Users'); + + /** + * Custom matching: + * GET => UsersPresenter::actionSuperRead() + * POST => UsersPresenter::actionCreate() + */ + $router[] = new ApiRoute('/hello', 'ApiRouter', [ + 'methods' => ['GET' => 'superRead', 'POST'] + ]); + + $router[] = new ApiRoute('/api-router/api/users[/]', 'Resources:Users', [ + 'parameters' => [ + 'id' => ['requirement' => '\d+', 'default' => 10] + ], + 'priority' => 1 + ]); + + $router[] = new ApiRoute('/api-router/api/users/[/-]', 'Resources:Users', [ + 'parameters' => [ + 'id' => ['requirement' => '\d+'] + ], + 'priority' => 1 + ]); + + $router[] = new Route('/', 'Homepage:default'); + + return $router; + } +} +``` + +### Api documentation + +There is another extension for Nette which works pretty well with ApiRouter: [ApiDocu](https://github.com/contributte/api-docu). +ApiDocu generates awesome api documentation from your RESTful routes. It can also show you documentation in application runtime! diff --git a/README.md b/README.md index 84c232d..5e3cfd9 100644 --- a/README.md +++ b/README.md @@ -1,147 +1,49 @@ -[![Build Status](https://travis-ci.org/ublaboo/api-router.svg?branch=master)](https://travis-ci.org/ublaboo/api-router) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ublaboo/api-router/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ublaboo/api-router/?branch=master) -[![Latest Stable Version](https://poser.pugx.org/ublaboo/api-router/v/stable)](https://packagist.org/packages/ublaboo/api-router) -[![License](https://poser.pugx.org/ublaboo/api-router/license)](https://packagist.org/packages/ublaboo/api-router) -[![Total Downloads](https://poser.pugx.org/ublaboo/api-router/downloads)](https://packagist.org/packages/ublaboo/api-router) -[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/ublaboo/help) +# RabbitMQ -# ApiRouter +Ultra easy-to-use [`RabbitMQ`](https://www.rabbitmq.com/) implementation for [`Nette Framework`](https://github.com/nette/). -RESTful Router for your Apis in Nette Framework - created either directly or via annotation +[![Build Status](https://img.shields.io/travis/contributte/api-router.svg?style=flat-square)](https://travis-ci.org/contributte/api-router) +[![Code coverage](https://img.shields.io/coveralls/contributte/api-router.svg?style=flat-square)](https://coveralls.io/r/contributte/api-router) +[![Licence](https://img.shields.io/packagist/l/contributte/api-router.svg?style=flat-square)](https://packagist.org/packages/contributte/api-router) +[![Downloads this Month](https://img.shields.io/packagist/dm/contributte/api-router.svg?style=flat-square)](https://packagist.org/packages/contributte/api-router) +[![Downloads total](https://img.shields.io/packagist/dt/contributte/api-router.svg?style=flat-square)](https://packagist.org/packages/contributte/api-router) +[![Latest stable](https://img.shields.io/packagist/v/contributte/api-router.svg?style=flat-square)](https://packagist.org/packages/contributte/api-router) +[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-brightgreen.svg?style=flat-square)](https://github.com/phpstan/phpstan) -## Installation +![](https://github.com/contributte/api-router/blob/master/.docs/assets/console.png "Console") -ApiRouter is available on composer: +## Discussion / Help -``` -composer require ublaboo/api-router -``` +[![Join the chat](https://img.shields.io/gitter/room/contributte/contributte.svg?style=flat-square)](http://bit.ly/ctteg) -## Usage +## Documentation -### Using annotation +- [Installation](.docs/README.md#installation) + - [Usage](.docs/README.md#usage) + - [Using annotation](.docs/README.md#using-annotation) + - [Using Nette Router](.docs/README.md#using-nette-router) + - [Api documentation](.docs/README.md#api-documentation) -```php -namespace App\ResourcesModule\Presenters; +## Versions -use Nette; -use Ublaboo\ApiRouter\ApiRoute; +| State | Version | Branch | Nette | PHP | +|--------|--------------|----------|--------|---------| +| stable | `^4.0.0` | `master` | `3.0+` | `^7.1` | -/** - * API for managing users - * - * @ApiRoute( - * "/api-router/api/users[/]", - * parameters={ - * "id"={ - * "requirement": "\d+", - * "default": 10 - * } - * }, - * priority=1, - * presenter="Resources:Users" - * ) - */ -class UsersPresenter extends Nette\Application\UI\Presenter -{ +## Maintainers - /** - * Get user detail - * - * @ApiRoute( - * "/api-router/api/users/[/-]", - * parameters={ - * "id"={ - * "requirement": "\d+" - * } - * }, - * method="GET", - * } - * ) - */ - public function actionRead($id, $foo = NULL, $bar = NULL) - { - $this->sendJson(['id' => $id, 'foo' => $foo, 'bar' => $bar]); - } + + + + + + +
+ + + +
+ Pavel Janda +
- - public function actionUpdate($id) - { - $this->sendJson(['id' => $id]); - } - - - public function actionDelete($id) - { - $this->sendJson(['id' => $id]); - } -} -``` - -Now 3 routes will be created (well, 2, but the one accepts both PUT and DELETE method). - -If you don't want to create route with DELETE method, simply remove the `UsersPresenter::actionDelete()` method. - -### Using Nette Router - -```php -namespace App; - -use Nette; -use Nette\Application\Routers\RouteList; -use Nette\Application\Routers\Route; -use Ublaboo\ApiRouter\ApiRoute; - -class RouterFactory -{ - - /** - * @return Nette\Application\IRouter - */ - public function createRouter() - { - $router = new RouteList; - - /** - * Simple route with matching (only if methods below exist): - * GET => UsersPresenter::actionRead() - * POST => UsersPresenter::actionCreate() - * PUT => UsersPresenter::actionUpdate() - * DELETE => UsersPresenter::actionDelete() - */ - $router[] = new ApiRoute('/hello', 'Users'); - - /** - * Custom matching: - * GET => UsersPresenter::actionSuperRead() - * POST => UsersPresenter::actionCreate() - */ - $router[] = new ApiRoute('/hello', 'ApiRouter', [ - 'methods' => ['GET' => 'superRead', 'POST'] - ]); - - $router[] = new ApiRoute('/api-router/api/users[/]', 'Resources:Users', [ - 'parameters' => [ - 'id' => ['requirement' => '\d+', 'default' => 10] - ], - 'priority' => 1 - ]); - - $router[] = new ApiRoute('/api-router/api/users/[/-]', 'Resources:Users', [ - 'parameters' => [ - 'id' => ['requirement' => '\d+'] - ], - 'priority' => 1 - ]); - - $router[] = new Route('/', 'Homepage:default'); - - return $router; - } -} -``` - -### Api documentation - -There is another extension for Nette which works pretty well with ApiRouter: [ApiDocu](https://github.com/contributte/api-docu). -ApiDocu generates awesome api documentation from your RESTful routes. It can also show you documentation in application runtime! +Thank you for testing, reporting and contributing. diff --git a/composer.json b/composer.json index 35b5fdf..71de1b8 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,12 @@ { - "name": "ublaboo/api-router", + "name": "contributte/api-router", "type": "library", "description": "RESTful Router for your Apis in Nette Framework - created either directly or via annotation", "keywords": ["rest", "api", "routes", "nette", "router", "restapi", "restrouter", "routing", "route"], - "homepage": "https://ublaboo.org/api-router", + "homepage": "https://github.com/contributte/api-router", "license": ["MIT"], "support": { - "issues": "https://github.com/ublaboo/api-router/issues" + "issues": "https://github.com/contributte/api-router/issues" }, "authors": [ { @@ -16,12 +16,12 @@ ], "autoload": { "psr-4": { - "Ublaboo\\ApiRouter\\": "src/" + "Contributte\\ApiRouter\\": "src/" } }, "autoload-dev": { "psr-4": { - "Ublaboo\\ApiRouter\\Tests\\": "tests" + "Contributte\\ApiRouter\\Tests\\": "tests" } }, "require": { diff --git a/src/ApiRoute.php b/src/ApiRoute.php index fa57465..caef533 100644 --- a/src/ApiRoute.php +++ b/src/ApiRoute.php @@ -2,13 +2,7 @@ declare(strict_types=1); -/** - * @copyright Copyright (c) 2016 ublaboo - * @author Pavel Janda - * @package Ublaboo - */ - -namespace Ublaboo\ApiRouter; +namespace Contributte\ApiRouter; use Nette; use Nette\Application\Request; diff --git a/src/ApiRouteSpec.php b/src/ApiRouteSpec.php index 49f0652..b9c7b2b 100644 --- a/src/ApiRouteSpec.php +++ b/src/ApiRouteSpec.php @@ -2,16 +2,10 @@ declare(strict_types=1); -/** - * @copyright Copyright (c) 2016 ublaboo - * @author Pavel Janda - * @package Ublaboo - */ - -namespace Ublaboo\ApiRouter; +namespace Contributte\ApiRouter; use Doctrine\Common\Annotations\Annotation\Enum; -use Ublaboo\ApiRouter\Exception\ApiRouteWrongPropertyException; +use Contributte\ApiRouter\Exception\ApiRouteWrongPropertyException; abstract class ApiRouteSpec { diff --git a/src/DI/ApiRouterExtension.php b/src/DI/ApiRouterExtension.php index d801332..dbd306c 100644 --- a/src/DI/ApiRouterExtension.php +++ b/src/DI/ApiRouterExtension.php @@ -2,13 +2,7 @@ declare(strict_types=1); -/** - * @copyright Copyright (c) 2016 ublaboo - * @author Pavel Janda - * @package Ublaboo - */ - -namespace Ublaboo\ApiRouter\DI; +namespace Contributte\ApiRouter\DI; use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\AnnotationRegistry; @@ -22,7 +16,7 @@ use Nette\PhpGenerator\ClassType as GClassType; use Nette\Reflection\ClassType; use Nette\Reflection\Method; -use Ublaboo\ApiRouter\ApiRoute; +use Contributte\ApiRouter\ApiRoute; class ApiRouterExtension extends CompilerExtension { diff --git a/src/DI/ApiRoutesResolver.php b/src/DI/ApiRoutesResolver.php index 4a6df8f..9156677 100644 --- a/src/DI/ApiRoutesResolver.php +++ b/src/DI/ApiRoutesResolver.php @@ -2,17 +2,11 @@ declare(strict_types=1); -/** - * @copyright Copyright (c) 2016 ublaboo - * @author Pavel Janda - * @package Ublaboo - */ - -namespace Ublaboo\ApiRouter\DI; +namespace Contributte\ApiRouter\DI; use Nette\Application\IRouter; use Nette\Application\Routers\RouteList; -use Ublaboo\ApiRouter\Exception\ApiRouteWrongRouterException; +use Contributte\ApiRouter\Exception\ApiRouteWrongRouterException; class ApiRoutesResolver { diff --git a/src/Exception/ApiRouteWrongPropertyException.php b/src/Exception/ApiRouteWrongPropertyException.php index dfa2659..f10cd1e 100644 --- a/src/Exception/ApiRouteWrongPropertyException.php +++ b/src/Exception/ApiRouteWrongPropertyException.php @@ -1,7 +1,7 @@ 'boo']); }, - 'Ublaboo\ApiRouter\Exception\ApiRouteWrongPropertyException', - 'Unknown property "foo" on annotation "Ublaboo\ApiRouter\ApiRoute"' + 'Contributte\ApiRouter\Exception\ApiRouteWrongPropertyException', + 'Unknown property "foo" on annotation "Contributte\ApiRouter\ApiRoute"' ); } @@ -28,21 +28,21 @@ final class ApiRouteSpecTest extends TestCase Assert::exception(function(){ new ApiRoute('/users', 'Users', ['parameters' => ['id' => ['type' => 'integer']]]); }, - 'Ublaboo\ApiRouter\Exception\ApiRouteWrongPropertyException', + 'Contributte\ApiRouter\Exception\ApiRouteWrongPropertyException', 'Parameter is not present in the url mask' ); Assert::exception(function(){ new ApiRoute('/users/', 'Users', ['parameters' => ['id' => ['foo' => 'integer']]]); }, - 'Ublaboo\ApiRouter\Exception\ApiRouteWrongPropertyException', + 'Contributte\ApiRouter\Exception\ApiRouteWrongPropertyException', 'You cat set only these description informations: [requirement, type, description, default] - "foo" given' ); Assert::exception(function(){ new ApiRoute('/users/', 'Users', ['parameters' => ['id' => ['type' => []]]]); }, - 'Ublaboo\ApiRouter\Exception\ApiRouteWrongPropertyException', + 'Contributte\ApiRouter\Exception\ApiRouteWrongPropertyException', 'You cat set only scalar parameters informations (key [type])' ); } diff --git a/tests/cases/ApiRouteTest.phpt b/tests/cases/ApiRouteTest.phpt index 135dd76..d757952 100755 --- a/tests/cases/ApiRouteTest.phpt +++ b/tests/cases/ApiRouteTest.phpt @@ -1,12 +1,12 @@