1. Go to this page and download the library: Download middlewares/request-handler 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/ */
middlewares / request-handler example snippets
// Create the routing dispatcher
$fastRouteDispatcher = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
$r->get('/hello/{name}', HelloWorldController::class);
});
$dispatcher = new Dispatcher([
new Middlewares\FastRoute($fastRouteDispatcher),
// ...
new Middlewares\RequestHandler(),
]);
$response = $dispatcher->dispatch(new ServerRequest('/hello/world'));
// Use a PSR-11 container to create the intances of the request handlers
$container = new RequestHandlerContainer();
$dispatcher = new Dispatcher([
// ...
new Middlewares\RequestHandler($container),
]);
// Use the default PSR-11 container to create the intances of the request handlers
$handler = new Middlewares\RequestHandler();
// Use a custom PSR-11 container
$container = new RequestHandlerContainer();
$handler = new Middlewares\RequestHandler($container);
Dispatcher::run([
(new Middlewares\RequestHandler())->handlerAttribute('route'),
]);
Dispatcher::run([
//Try this, and if it's empty, continue
(new Middlewares\RequestHandler())->continueOnEmpty(),
//So we can try that
(new Middlewares\RequestHandler())->handlerAttribute('other'),
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.