PHP code example of lucid / infuse

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

    

lucid / infuse example snippets




namespace Acme\Middleware;

use Lucid\Infuse\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

class SessoionHandler implements MiddlewareInterface
{
    public function handle(Request $request, Response $response)
    {
        // ...

        return [$request, $response];
    }
}



use Lucid\Infuse\Queue;
use Lucid\Signale\EventDispatcher;

$queue = new Queue(new EventDispatcher);

$queue->add($middlewareOmega); // will execute last
// …
$queue->add($middlewareAlpha); // fill execute first

// …
list ($request, $response) = $queue->handle($request, $response);




use Lucid\Infuse\Queue;
use Lucid\Signale\EventDispatcher;
use Lucid\Infuse\Events\RequestEvent;

$queue = new Queue($events = new EventDispatcher, 'middleware');

$events->addHandler('middleware', function (RequestEvent $event) {
    $req = $event->getRequest();
    $res = $event->getResponse();

    if (…) {
        $event->setResponse(…);
        $event->stop();
    }
});