\Cake\HttpMiddlewareQueue

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.

Summary

Methods
Properties
Constants
__construct()
get()
add()
push()
prepend()
insertAt()
insertBefore()
insertAfter()
count()
No public properties found
No constants found
resolve()
$queue
$callables
N/A
No private methods found
No private properties found
N/A

Properties

$queue

$queue : array

The queue of middlewares.

Type

array

$callables

$callables : array<mixed,callable>

The queue of middleware callables.

Type

array<mixed,callable>

Methods

__construct()

__construct(array  $middleware = array()) 

Constructor

Parameters

array $middleware

The list of middleware to append.

get()

get(integer  $index) : callable|null

Get the middleware at the provided index.

Parameters

integer $index

The index to fetch.

Returns

callable|null —

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

add()

add(callable|string|array  $middleware) : $this

Append a middleware callable to the end of the queue.

Parameters

callable|string|array $middleware

The middleware(s) to append.

Returns

$this

push()

push(callable|string|array  $middleware) : $this

Alias for MiddlewareQueue::add().

Parameters

callable|string|array $middleware

The middleware(s) to append.

Returns

$this

prepend()

prepend(callable|string|array  $middleware) : $this

Prepend a middleware to the start of the queue.

Parameters

callable|string|array $middleware

The middleware(s) to prepend.

Returns

$this

insertAt()

insertAt(integer  $index, callable|string  $middleware) : $this

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()

insertBefore(string  $class, callable|string  $middleware) : $this

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.

Throws

\LogicException

If middleware to insert before is not found.

Returns

$this

insertAfter()

insertAfter(string  $class, callable|string  $middleware) : $this

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

count()

count() : integer

Get the number of connected middleware layers.

Implement the Countable interface.

Returns

integer

resolve()

resolve(integer  $index) : callable|null

Resolve middleware name to callable.

Parameters

integer $index

The index to fetch.

Returns

callable|null —

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