<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jerowork / aura-router-nested-middleware example snippets
use Aura\Router\RouterContainer;
use Jerowork\AuraRouterNestedMiddleware\AuraRouterNestedMiddleware;
// setup Aura Router
$router = new RouteContainer();
// add middleware to your general middleware queue
$middleware[] = new AuraRouterNestedMiddleware($router);
// add routes with middleware
$map = $router->getMap();
$map->get('home', '/', [
new SomeMiddleware(),
new AnotherMiddleware(),
new HomeAction(),
]);
// route with no other middleware than the blog action
$map->get('blog', '/blog', new BlogAction());
use Interop\Http\Server\MiddlewareInterface;
class HomeAction implements MiddlewareInterface
{
/**
* @inheritDoc
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = $handler->handle($request);
$response->getBody()->write('Hello world!');
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.