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.

Namespace: Cake\Http

Properties summary

  • $callables protected
    callable[]

    The queue of middleware callables.

  • $queue protected
    array

    The queue of middlewares.

Method Summary

  • __construct() public

    Constructor

  • add() public

    Append a middleware callable to the end of the queue.

  • count() public

    Get the number of connected middleware layers.

  • get() public

    Get the middleware at the provided index.

  • insertAfter() public

    Insert a middleware object after the first matching class.

  • insertAt() public

    Insert a middleware callable at a specific index.

  • insertBefore() public

    Insert a middleware object before the first matching class.

  • prepend() public

    Prepend a middleware to the start of the queue.

  • push() public

    Alias for MiddlewareQueue::add().

  • resolve() protected

    Resolve middleware name to callable.

Method Detail

__construct() public

__construct(array $middleware)

Constructor

Parameters

array $middleware optional

The list of middleware to append.

add() public

add(mixed $middleware)

Append a middleware callable to the end of the queue.

Parameters

callable|string|array $middleware

The middleware(s) to append.

Returns

$this

count() public

count()

Get the number of connected middleware layers.

Implement the Countable interface.

Returns

int

get() public

get(mixed $index)

Get the middleware at the provided index.

Parameters

int $index

The index to fetch.

Returns

callable|null

Either the callable middleware or null if the index is undefined.

insertAfter() public

insertAfter(mixed $class, mixed $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() public

insertAt(mixed $index, mixed $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

int $index

The index to insert at.

callable|string $middleware

The middleware to insert.

Returns

$this

insertBefore() public

insertBefore(mixed $class, mixed $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

LogicException
If middleware to insert before is not found.

prepend() public

prepend(mixed $middleware)

Prepend a middleware to the start of the queue.

Parameters

callable|string|array $middleware

The middleware(s) to prepend.

Returns

$this

push() public

push(mixed $middleware)

Alias for MiddlewareQueue::add().

Parameters

callable|string|array $middleware

The middleware(s) to append.

Returns

$this

See Also

\Cake\Http\MiddlewareQueue::add()

resolve() protected

resolve(mixed $index)

Resolve middleware name to callable.

Parameters

int $index

The index to fetch.

Returns

callable|null

Either the callable middleware or null if the index is undefined.

Property Detail

$callables protected

The queue of middleware callables.

Type

callable[]

$queue protected

The queue of middlewares.

Type

array

© 2005–present 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.9/class-Cake.Http.MiddlewareQueue.html