Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexpts/psr15-next
🚀 PSR-15 middleware runner
https://github.com/alexpts/psr15-next
middleware php psr-15
Last synced: 2 months ago
JSON representation
🚀 PSR-15 middleware runner
- Host: GitHub
- URL: https://github.com/alexpts/psr15-next
- Owner: alexpts
- License: mit
- Created: 2018-08-19T10:16:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-29T16:18:40.000Z (over 2 years ago)
- Last Synced: 2024-11-11T10:57:48.539Z (2 months ago)
- Topics: middleware, php, psr-15
- Language: PHP
- Homepage:
- Size: 137 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Next
[![phpunit](https://github.com/alexpts/psr15-next/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/alexpts/psr15-next/actions/workflows/phpunit.yml)
[![codecov](https://codecov.io/gh/alexpts/psr15-next/branch/master/graph/badge.svg?token=14L6IJA5UE)](https://codecov.io/gh/alexpts/psr15-next)Runner for PSR-15 middlewares.
[See examples](https://github.com/alexpts/psr15-next/tree/master/examples)
* 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)```php
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`
### Todo: add more examples