Collection of PSR-15 middleware

1.0.0 2017-09-27 20:45 UTC

This package is not auto-updated.

Last update: 2020-06-03 00:48:15 UTC


Build Status Coverage Status

Collection of PSR-15 Middleware.


PHP >= 7.1


composer require benliev/middleware


For test this library :

composer test

Usage example

$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))

The dispatcher has the role of storing the middleware and then of executing them.

Available middlewares

  • 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.