Fr3nch13/CakePHP Utilities

MiddlewareQueue
in package
implements Countable, SeekableIterator

Provides methods for creating and manipulating a "queue" of middlewares.

This queue is used to process a request and generate response via \Cake\Http\Runner.

Tags
template-implements

\SeekableIterator<int, \Psr\Http\Server\MiddlewareInterface>

Table of Contents

Interfaces

Countable
SeekableIterator

Properties

$position  : int
Internal position for iterator.
$queue  : array<int, mixed>
The queue of middlewares.

Methods

__construct()  : mixed
Constructor
add()  : $this
Append a middleware to the end of the queue.
count()  : int
Get the number of connected middleware layers.
current()  : MiddlewareInterface
Returns the current middleware.
insertAfter()  : $this
Insert a middleware object after the first matching class.
insertAt()  : $this
Insert a middleware at a specific index.
insertBefore()  : $this
Insert a middleware before the first matching class.
key()  : int
Return the key of the middleware.
next()  : void
Moves the current position to the next middleware.
prepend()  : $this
Prepend a middleware to the start of the queue.
push()  : $this
Alias for MiddlewareQueue::add().
rewind()  : void
Rewinds back to the first element of the queue.
seek()  : void
Seeks to a given position in the queue.
valid()  : bool
Checks if current position is valid.
resolve()  : MiddlewareInterface
Resolve middleware name to a PSR 15 compliant middleware instance.

Properties

$position

Internal position for iterator.

protected int $position = 0

$queue

The queue of middlewares.

protected array<int, mixed> $queue = []

Methods

__construct()

Constructor

public __construct([array<string|int, mixed> $middleware = [] ]) : mixed
Parameters
$middleware : array<string|int, mixed> = []

The list of middleware to append.

add()

Append a middleware to the end of the queue.

public add(MiddlewareInterface|Closure|array<string|int, mixed>|string $middleware) : $this
Parameters
$middleware : MiddlewareInterface|Closure|array<string|int, mixed>|string

The middleware(s) to append.

Return values
$this

count()

Get the number of connected middleware layers.

public count() : int

Implement the Countable interface.

Return values
int

insertAfter()

Insert a middleware object after the first matching class.

public insertAfter(string $class, MiddlewareInterface|Closure|string $middleware) : $this

Finds the index of the first middleware that matches the provided class, and inserts the supplied middleware after it. If the class is not found, this method will behave like add().

Parameters
$class : string

The classname to insert the middleware before.

$middleware : MiddlewareInterface|Closure|string

The middleware to insert.

Return values
$this

insertAt()

Insert a middleware at a specific index.

public insertAt(int $index, MiddlewareInterface|Closure|string $middleware) : $this

If the index already exists, the new middleware will be inserted, and the existing element will be shifted one index greater.

Parameters
$index : int

The index to insert at.

$middleware : MiddlewareInterface|Closure|string

The middleware to insert.

Return values
$this

insertBefore()

Insert a middleware before the first matching class.

public insertBefore(string $class, MiddlewareInterface|Closure|string $middleware) : $this

Finds the index of the first middleware that matches the provided class, and inserts the supplied middleware before it.

Parameters
$class : string

The classname to insert the middleware before.

$middleware : MiddlewareInterface|Closure|string

The middleware to insert.

Tags
throws
LogicException

If middleware to insert before is not found.

Return values
$this

key()

Return the key of the middleware.

public key() : int
Tags
see
Iterator::key()
Return values
int

next()

Moves the current position to the next middleware.

public next() : void
Tags
see
Iterator::next()

prepend()

Prepend a middleware to the start of the queue.

public prepend(MiddlewareInterface|Closure|array<string|int, mixed>|string $middleware) : $this
Parameters
$middleware : MiddlewareInterface|Closure|array<string|int, mixed>|string

The middleware(s) to prepend.

Return values
$this

rewind()

Rewinds back to the first element of the queue.

public rewind() : void
Tags
see
Iterator::rewind()

seek()

Seeks to a given position in the queue.

public seek(int $position) : void
Parameters
$position : int

The position to seek to.

Tags
see
SeekableIterator::seek()

valid()

Checks if current position is valid.

public valid() : bool
Tags
see
Iterator::valid()
Return values
bool

        
On this page

Search results