MiddlewareFactory

Class MiddlewareFactory

Marshal middleware for use in the application.

This class provides a number of methods for preparing and returning middleware for use within an application.

If any middleware provided is already a MiddlewareInterface, it can be used verbatim or decorated as-is. Other middleware types acceptable are:

  • PSR-15 RequestHandlerInterface instances; these will be decorated as RequestHandlerMiddleware instances.
  • string service names resolving to middleware
  • arrays of service names and/or MiddlewareInterface instances
  • PHP callables that follow the PSR-15 signature

Additionally, the class provides the following decorator/utility methods:

  • callableMiddleware() will decorate the callable middleware passed to it using CallableMiddlewareDecorator.
  • handlerMiddleware() will decorate the request handler passed to it using RequestHandlerMiddleware.
  • lazyMiddleware() will decorate the string service name passed to it, along with the factory instance, as a LazyLoadingMiddleware instance.
  • pipeline() will create a MiddlewarePipe instance from the array of middleware passed to it, after passing each first to prepare().
package

LightMVC/ASCMVC

Methods

MiddlewareFactory constructor.

__construct(\Pimple\Container $container) 

Arguments

$container

\Pimple\Container

Decorate callable standards-signature middleware via a CallableMiddlewareDecorator.

callableMiddleware(callable $middleware) : \Zend\Stratigility\Middleware\CallableMiddlewareDecorator

Arguments

$middleware

callable

Response

\Zend\Stratigility\Middleware\CallableMiddlewareDecorator

Decorate a RequestHandlerInterface as middleware via RequestHandlerMiddleware.

handlerMiddleware(\Psr\Http\Server\RequestHandlerInterface $handler) : \Zend\Stratigility\Middleware\RequestHandlerMiddleware

Arguments

$handler

\Psr\Http\Server\RequestHandlerInterface

Response

\Zend\Stratigility\Middleware\RequestHandlerMiddleware

Create lazy loading middleware based on a service name.

lazyMiddleware(string $middleware) : \Ascmvc\Middleware\LazyLoadingMiddleware

Arguments

$middleware

string

Response

\Ascmvc\Middleware\LazyLoadingMiddleware

Create a middleware pipeline from an array of middleware.

pipeline(string|array|\Zend\Stratigility\MiddlewarePipe $middleware) : \Zend\Stratigility\MiddlewarePipe

This method allows passing an array of middleware as either:

  • discrete arguments
  • an array of middleware, using the splat operator: pipeline(...$array)
  • an array of middleware as the sole argument: pipeline($array)

Each item is passed to prepare() before being passed to the MiddlewarePipe instance the method returns.

Throws
\Exception

Arguments

$middleware

string|array|\Zend\Stratigility\MiddlewarePipe

Response

\Zend\Stratigility\MiddlewarePipe

Prepares the middleware according to type.

prepare(string|array|callable|\Psr\Http\Server\MiddlewareInterface|\Psr\Http\Server\RequestHandlerInterface $middleware) : \Psr\Http\Server\MiddlewareInterface
Throws
\Exception

if argument is not one of the specified types.

Arguments

$middleware

string|array|callable|\Psr\Http\Server\MiddlewareInterface|\Psr\Http\Server\RequestHandlerInterface

Response

\Psr\Http\Server\MiddlewareInterface

Properties

Contains an instance of the Pimple\Container class.

container : \Pimple\Container
var

Type(s)

\Pimple\Container