PHP Class Phly\Conduit\MiddlewarePipe

This class implements a pipe-line of middleware, which can be attached using the pipe() method, and is itself middleware. The request and response objects are decorated using the Phly\Conduit\Http variants in this package, ensuring that the request may store arbitrary properties, and the response exposes the convenience write(), end(), and isComplete() methods. It creates an instance of Next internally, invoking it with the provided request and response instances; if no $out argument is provided, it will create a FinalHandler instance and pass that to Next as well. Inspired by Sencha Connect.
See also: https://github.com/sencha/connect
Inheritance: implements Phly\Conduit\MiddlewareInterface
显示文件 Open project: phly/conduit Class Usage Examples

Protected Properties

Property Type Description
$pipeline SplQueue

Public Methods

Method Description
__construct ( ) Constructor
__invoke ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $out = null ) : Psr\Http\Message\ResponseInterface Handle a request
pipe ( string | callable | object $path, null | callable | object $middleware = null ) : self Attach middleware to the pipeline.

Private Methods

Method Description
decorateRequest ( Psr\Http\Message\ServerRequestInterface $request ) : Request Decorate the Request instance
decorateResponse ( Psr\Http\Message\ResponseInterface $response ) : Response Decorate the Response instance
normalizePipePath ( string $path ) : string Normalize a path used when defining a pipe

Method Details

__construct() public method

Initializes the queue.
public __construct ( )

__invoke() public method

Takes the pipeline, creates a Next handler, and delegates to the Next handler. If $out is a callable, it is used as the "final handler" when $next has exhausted the pipeline; otherwise, a FinalHandler instance is created and passed to $next during initialization.
public __invoke ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $out = null ) : Psr\Http\Message\ResponseInterface
$request Psr\Http\Message\ServerRequestInterface
$response Psr\Http\Message\ResponseInterface
$out callable
return Psr\Http\Message\ResponseInterface

pipe() public method

Each middleware can be associated with a particular path; if that path is matched when that middleware is invoked, it will be processed; otherwise it is skipped. No path means it should be executed every request cycle. A handler CAN implement MiddlewareInterface, but MUST be callable. Handlers with arity >= 4 or those implementing ErrorMiddlewareInterface are considered error handlers, and will be executed when a handler calls $next with an error or raises an exception.
See also: MiddlewareInterface
See also: ErrorMiddlewareInterface
See also: Next
public pipe ( string | callable | object $path, null | callable | object $middleware = null ) : self
$path string | callable | object Either a URI path prefix, or middleware.
$middleware null | callable | object Middleware
return self

Property Details

$pipeline protected_oe property

protected SplQueue $pipeline
return SplQueue