PHP code example of jerowork / aura-router-nested-middleware

1. Go to this page and download the library: Download jerowork/aura-router-nested-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/ */

    

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;
    }
}