1. Go to this page and download the library: Download siriusphp/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/ */
siriusphp / middleware example snippets
$middlewares = array();
$middlewares[] = function(RequestInterface $request, ResponseInterface $response, callable $next = null) {
// do your thing
return $response;
};
$middlewares[] = function(RequestInterface $request, ResponseInterface $response, callable $next = null) {
// do your thing
return $response;
};
$runner = Sirius\Middleware\Runner::factory($middlewares);
$response = $runner(Zend\Diactoros\ServerRequestFactory::fromGlobals(), new Zend\Diactoros\Response);
// this is WRONG!!!!!!!!!
$runner = new Sirius\Middleware\Runner;
$runner->add(function(RequestInterface $request, ResponseInterface $response, callable $next = null) {
// do your thing
return $response;
});
$runner->add(function(RequestInterface $request, ResponseInterface $response, callable $next = null) {
// do your thing
return $response;
});
// this is CORRECT
$runner = (new Sirius\Middleware\Runner)
->add(function(RequestInterface $request, ResponseInterface $response, callable $next = null) {
// do your thing
return $response;
})
->add(function(RequestInterface $request, ResponseInterface $response, callable $next = null) {
// do your thing
return $response;
});
$middlewares = array();
// first middleware in the stack must return an response
$middlewares[] = function(RequestInterface $request, callable $next = null) {
return new Zend\Diactoros\Response;
};
$middlewares[] = function(RequestInterface $request, callable $next = null) {
// do your thing
return $response;
};
$middlewares[] = function(RequestInterface $request, callable $next = null) {
// do your thing
return $response;
};
$runner = Sirius\Middleware\FrameRunner::factory($middlewares);
$response = $runner(Zend\Diactoros\ServerRequestFactory::fromGlobals());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.