Collection of PSR-15 Middleware.
PHP >= 7.1
composer require benvens/middleware
For test this library :
composer test
$responseFactory = new \Http\Factory\Guzzle\ResponseFactory();
$request = \GuzzleHttp\Psr7\ServerRequest::fromGlobals();
$response = (new Dispatcher())
->pipe(new TrailingSlashMiddleware($responseFactory))
->pipe(new MethodMiddleware())
->pipe(new CsrfMiddleware())
->pipe(new NotFoundMiddleware($responseFactory))
->process($request));
\Http\Response\send($response);
The dispatcher has the role of storing the middleware and then of executing them.
- TrailingSlashMiddleware : Middleware to remove the trailing slash.
- MethodMiddleware : Middleware to override the request method using parameter _method provided in the request body.
- CsrfMiddleware : Middleware for CSRF protection.
- NotFoundMiddleware : Middleware to return a 404 response with Error 404 body. This middleware must be at the end of the dispatcher.