PHP code example of ajgarlag / psr15-dispatcher

1. Go to this page and download the library: Download ajgarlag/psr15-dispatcher 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/ */

    

ajgarlag / psr15-dispatcher example snippets


/* @var $requestHandler RequestHandlerInterface */
$requestHandler = new YourApp();

use Ajgarlag\Psr15\Dispatcher\Pipe;

$pipe = Pipe::create()
    ->withConnectedMiddleware(new FirstMiddleware())
    ->withConnectedMiddleware(new MiddleMiddleware())
    ->withConnectedMiddleware(new LastMiddleware())
;

$response = $pipe->process($request, $requestHandler);

$pipe = Pipe::create([
    new FirstMiddleware(),
    new MiddleMiddleware(),
    new LastMiddleware(),
]);

use Ajgarlag\Psr15\Dispatcher\Stack;

$stack = Stack::create($requestHandler)
    ->withPushedMiddleware(new LastMiddleware())
    ->withPushedMiddleware(new MiddleMiddleware())
    ->withPushedMiddleware(new FirstMiddleware())
;

$response = $stack->handle($request);

$stack = Stack::create($requestHandler, [
    new LastMiddleware(),
    new MiddleMiddleware(),
    new FirstMiddleware(),
]);

$stack = Stack::create($requestHandler);
$pipe = Pipe::create()
    ->withConnectedMiddleware(new FirstMiddleware())
    ->withConnectedMiddleware(new MiddleMiddleware())
    ->withConnectedMiddleware(new LastMiddleware())
;

$application = $stack->withPushedMiddleware($pipe);