2017 © Pedro Peláez
 

package infuse

psr7 middlware

image

lucid/infuse

psr7 middlware

  • Sunday, August 28, 2016
  • by iwyg
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Psr7 Middleware queue and interface

Author Source Code Software License, (*1)

Build Status Code Coverage HHVM, (*2)

Installation

> composer require lucid/infuse

Requirements

  • php >= 5.6
  • psr/http-message
  • lucid/signal

Usage

The middleware

Middlewares must implement Lucid\Infuse\MiddlewareInterface. They also must return an array of [Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $respoonse]., (*3)

<?php

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

The middleware queue

Use QueueInterface::add() to add middlewares to the execution queue. Middlewares are executed first in last out. The middleware queue itself implements Lucid\Infuse\MiddlewareInterface and acts as an entrypoint., (*4)

<?php

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

Intercept execution

During middleware exection, the eventdispatcher will fire a request event. Execution will stop if a middleware event is being stopped., (*5)

<?php

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

The Versions

28/08 2016

dev-develop

dev-develop

psr7 middlware

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar iwyg

23/04 2016

dev-master

9999999-dev

psr7 middlware

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar iwyg

21/04 2016

v0.0.2

0.0.2.0

psr7 middlware

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar iwyg

15/04 2016

v0.0.1

0.0.1.0

psr7 middlware

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar iwyg