ellipse / middleware-callable
Psr-15 middleware proxying a callable
1.0.1
2018-03-04 22:03 UTC
Requires
- php: >=7.0
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- eloquent/phony-kahlan: ^1.0
- kahlan/kahlan: ^4.0
This package is auto-updated.
Last update: 2024-11-26 00:21:01 UTC
README
This package provides a Psr-15 middleware proxying a callable.
Require php >= 7.0
Installation composer require ellipse/middleware-callable
Run tests ./vendor/bin/kahlan
Using callables as middleware
The class Ellipse\Middleware\CallableMiddleware
can be wrapped around a callable in order to use it as a middleware.
As any middleware ->process()
method, the callable receive implementations of Psr\Http\Message\ServerRequestInterface
and Psr\Http\Server\RequestHandlerInterface
as parameters and should return an implementation of Psr\Http\Message\ResponseInterface
.
<?php namespace App; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use Ellipse\Middleware\CallableMiddleware; // This middleware is wrapped around the given callable. $middleware = new CallableMiddleware(function (ServerRequestInterface $request, RequestHandlerInterface $handler) { // ... return $handler->handle($request); }); // The middleware ->process() method proxy the callable. $response = $middleware->process($request, $handler);