PHP code example of hannesvdvreken / psr7-middlewares
1. Go to this page and download the library: Download hannesvdvreken/psr7-middlewares 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/ */
hannesvdvreken / psr7-middlewares example snippets
function (RequestInterface $request, ResponseInterface $response, callable $next) {
// Do something with the request before passing it on.
...
// Pass on to next middleware.
$response = $next($request, $response);
// Do something with the response after the next middleware has been called.
...
// Return ultimate response object.
return $response;
}
use Psr7Stack\Builder;
$builder = new Builder();
$session = new SessionMiddleware();
$throttle = new TrottleMiddleware();
$app = new App();
$builder = $buider->push($session)->push($throttle)->push($app);
$stack = $builder->resolve();
use Psr7Stack\Stack;
$stack = Stack::create([$session, $throttle, $app]);
$psrResponse = $stack->handle($psrRequest);
use Psr7Stack\Core;
use Psr\Http\Message\RequestInterface;
class App implements Core
{
/**
* @param \Psr\Http\Message\RequestInterface $request
*
* @request \Psr\Http\Message\ResponseInterface
*/
public function handle(RequestInterface $request)
{
// Call the router and return the response.
return $response;
}
}
use Psr7Stack\Kernel;
use Psr7Stack\Traits\NextCore;
class SessionMiddleware implements Kernel
{
// Use trait to implement the setNextCore method.
use NextCore;
/**
* @param \Psr\Http\Message\RequestInterface $request
*
* @request \Psr\Http\Message\ResponseInterface
*/
public function handle(RequestInterface $request)
{
// Call the next core and return the response.
$response = $this->next->handle($request);
// Do something with the response and return it.
...
return $response;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.