Class MiddlewareQueue
Provides methods for creating and manipulating a "queue" of middleware callables. This queue is used to process a request and response via \Cake\Http\Runner.
- Cake\Http\MiddlewareQueue implements Countable
Properties summary
-
$callables
protectedThe queue of middleware callables.callable[]
-
$queue
protectedThe queue of middlewares.array
Method Summary
- __construct() publicConstructor
- add() publicAppend a middleware callable to the end of the queue.
- count() publicGet the number of connected middleware layers.
- get() publicGet the middleware at the provided index.
- insertAfter() publicInsert a middleware object after the first matching class.
- insertAt() publicInsert a middleware callable at a specific index.
- insertBefore() publicInsert a middleware object before the first matching class.
- prepend() publicPrepend a middleware to the start of the queue.
- push() publicAlias for MiddlewareQueue::add().
- resolve() protectedResolve middleware name to callable.
Method Detail
__construct()source public
__construct( array $middleware [] )
Constructor
Parameters
- array
$middleware
optional [] - The list of middleware to append.
add()source public
add( callable|string|array $middleware )
Append a middleware callable to the end of the queue.
Parameters
- callable|string|array
$middleware
- The middleware(s) to append.
Returns
$this
count()source public
count( )
Get the number of connected middleware layers.
Implement the Countable interface.
Returns
integerImplementation of
Countable::count()
get()source public
get( integer $index )
Get the middleware at the provided index.
Parameters
- integer
$index
- The index to fetch.
Returns
callable|nullEither the callable middleware or null if the index is undefined.
insertAfter()source public
insertAfter( string $class , callable|string $middleware )
Insert a middleware object after the first matching class.
Finds the index of the first middleware that matches the provided class, and inserts the supplied callable after it. If the class is not found, this method will behave like add().
Parameters
- string
$class
- The classname to insert the middleware before.
- callable|string
$middleware
- The middleware to insert.
Returns
$this
insertAt()source public
insertAt( integer $index , callable|string $middleware )
Insert a middleware callable at a specific index.
If the index already exists, the new callable will be inserted, and the existing element will be shifted one index greater.
Parameters
- integer
$index
- The index to insert at.
- callable|string
$middleware
- The middleware to insert.
Returns
$this
insertBefore()source public
insertBefore( string $class , callable|string $middleware )
Insert a middleware object before the first matching class.
Finds the index of the first middleware that matches the provided class, and inserts the supplied callable before it.
Parameters
- string
$class
- The classname to insert the middleware before.
- callable|string
$middleware
- The middleware to insert.
Returns
$this
Throws
LogicExceptionIf middleware to insert before is not found.
prepend()source public
prepend( callable|string|array $middleware )
Prepend a middleware to the start of the queue.
Parameters
- callable|string|array
$middleware
- The middleware(s) to prepend.
Returns
$this
push()source public
push( callable|string|array $middleware )
Alias for MiddlewareQueue::add().
Parameters
- callable|string|array
$middleware
- The middleware(s) to append.
Returns
$this
See
MiddlewareQueue::add()resolve()source protected
resolve( integer $index )
Resolve middleware name to callable.
Parameters
- integer
$index
- The index to fetch.
Returns
callable|nullEither the callable middleware or null if the index is undefined.
Properties detail
© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.4/class-Cake.Http.MiddlewareQueue.html