Slim and simple PSR-15 compliant middleware runner library for PHP.
Install via the composer utility.
composer require "phoole/middleware"or add the following lines to your composer.json
{
"require": {
"phoole/middleware": "1.*"
}
}Able to use PSR-15 compliant middlewares out there.
Able to use a middleware queue (a group of middlewares) as a generic middleware in another(or the main) queue.
Create the middleware queue, then process all the middlewares.
usePhoole\Middleware\Queue;
useGuzzleHttp\Psr7\Response;
useGuzzleHttp\Psr7\ServerRequest;
// create middleware queue with 404 response as default(last)$mws = newQueue(newResponse(404));
// add middlewares$mws->add(
newLoggerMiddleware(),
newDispatcherMiddleware()
);
// process the request with middlewares$response = $mws->handle(newServerRequest('GET', 'http://bingo.com/get'));Phoole\Middleware\Queueimplements thePsr\Http\Server\MiddlewareInterface, so the queue itself can be used as a generic middleware.// subqueue may need no default response if not the last in the main queue$subQueue = (newQueue())->add( newResponseTimeMiddleware(), newLoggingMiddleware() ); // main middleware queue$mws = (newQueue(newResponse(404)))->add( $subQueue, newDispatcherMiddleware() );
$ composer testPHP >= 7.2.0
phoole/base 1.*
A PSR-7 HTTP message implementation, such as guzzle/psr7.
