Skip to content

benvens/middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP middleware

Build Status Coverage Status

Collection of PSR-15 Middleware.

Requirements

PHP >= 7.1

Installation

composer require benvens/middleware

Test

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))
    ->process($request));
\Http\Response\send($response);

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.

About

Collection of PSR-15 middleware

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages