PHP code example of viloveul / middleware
1. Go to this page and download the library: Download viloveul/middleware library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
viloveul / middleware example snippets
$collection = new Viloveul\Middleware\Collection();
$controller = function () {
// return Psr\Http\Message\ResponseInterface
};
$collection->add('new object from Psr\Http\Server\MiddlewareInterface');
$collection->add('new object of Closure');
$collection->add(function (Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Server\RequestHandlerInterface $next) : Psr\Http\Message\ResponseInterface {
// do something
return $next->handle($request);
}
);
$stack = new Viloveul\Middleware\Stack($controller, $collection);
$response = $stack->handle("object from Psr\Http\Message\ServerRequestInterface");
var_dump($response);