sunrise/http-router-annotations-support

This package is abandoned and no longer maintained. No replacement package was suggested.

Annotations support for Sunrise HTTP Router

v1.0.3 2019-05-20 23:45 UTC

README

Gitter Build Status CodeFactor Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads License

Installation (via composer)

composer require sunrise/http-router-annotations-support

How to use?

QuickStart

$router = new \Sunrise\Http\Router\Router();
$loader = new \Sunrise\Http\Router\AnnotationRouteLoader();

$routes = $loader->load(__DIR__ . '/src/Http/Controller/Foo');
$router->addRoutes($routes);

$routes = $loader->load(__DIR__ . '/src/Http/Controller/Bar');
$router->addRoutes($routes);

$response = $router->handle(...);

ExampleController

declare(strict_types=1);
namespace App\Http\Controller;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

/**
 * @Route(
 *   id="resource.update",
 *   path="/resource/{id<\d+>}",
 *   methods={"PATCH"},
 *   before={
 *     "App\Http\Middleware\FooMiddleware",
 *     "App\Http\Middleware\BarMiddleware"
 *   },
 *   after={
 *     "App\Http\Middleware\BazMiddleware",
 *     "App\Http\Middleware\QuxMiddleware"
 *   }
 * )
 */
class ResourceUpdate implements MiddlewareInterface
{
    public function process(
        ServerRequestInterface $request,
        RequestHandlerInterface $handler
    ) : ResponseInterface {
        $response = $handler->handle($request);
        $resourceId = $request->getAttribute('id');

        // some code...

        return $response;
    }
}

Test run

php vendor/bin/phpunit

Api documentation

https://phpdoc.fenric.ru/