alexpts / psr15-next
Router for PSR-7 and PSR-15
0.5.0
2020-12-01 19:27 UTC
Requires
- php: ~8.0
- alexpts/php-simple-events: ^5.0
- alexpts/php-tools: ^4.0
- psr/http-message: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- alexpts/mutable-psr7: ^0.1
- alexpts/psr15-middlewares: ^2.0
- blackfire/php-sdk: ^1.23
- phpunit/phpunit: ^9.4
README
Runner for PSR-15 middlewares.
- Named routes with URL generation
- Responds to
OPTIONS
requests with allowed methods - Multiple route middleware
- Multiple routers
- Nestable routers
- PSR-15 middlewares
- PSR-7 request/response
- Flexible priority (low level)
- Dynamic endpoint (low level)
use Psr\Http\Message\ServerRequestInterface; use PTS\NextRouter\Resolver\LayerResolver; use PTS\NextRouter\Next; use PTS\PSR15\Middlewares\ErrorToJsonResponse; use PTS\ParserPsr7\SapiEmitter; use PTS\Psr7\Factory\Psr17Factory; use PTS\Psr7\Response\JsonResponse; require_once '../vendor/autoload.php'; $psr17Factory = new Psr17Factory; $app = new Next; $app->getRouterStore() ->get('/hello', function (ServerRequestInterface $request, $next) { return new JsonResponse(['message' => 'Hello world'], 200); }) ->use(function (ServerRequestInterface $request, $next) { return new JsonResponse(['message' => 'otherwise']); }); $request = $psr17Factory->fromGlobals(); $response = $app->handle($request); (new SapiEmitter)->emit($response);
Install
composer require alexpts/psr15-next