Zend Framework  3.0
Public Member Functions | Protected Attributes | List of all members
MiddlewarePipe Class Reference

Pipe middleware like unix pipes. More...

Public Member Functions

 __construct ()
 Constructor.
 
 __invoke (Request $request, Response $response, callable $out=null)
 Handle a request.
 
 pipe ($path, $middleware=null)
 Attach middleware to the pipeline.
 

Protected Attributes

 $pipeline
 

Detailed Description

Pipe middleware like unix pipes.

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 Zend 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

Constructor & Destructor Documentation

__construct ( )

Constructor.

Initializes the queue.

Member Function Documentation

__invoke ( Request  $request,
Response  $response,
callable  $out = null 
)

Handle a request.

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.

Parameters
Request$request
Response$response
callable$out
Returns
Response

Implements MiddlewareInterface.

pipe (   $path,
  $middleware = null 
)

Attach middleware to the pipeline.

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
ErrorMiddlewareInterface
Next
Parameters
string | callable | object$pathEither a URI path prefix, or middleware.
null | callable | object$middlewareMiddleware
Returns
self

Member Data Documentation

$pipeline
protected