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
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
$thiscount()
Get the number of connected middleware layers.
public
count() : int
Implement the Countable interface.
Return values
intcurrent()
Returns the current middleware.
public
current() : MiddlewareInterface
Tags
Return values
MiddlewareInterfaceinsertAfter()
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
$thisinsertAt()
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
$thisinsertBefore()
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
Return values
$thiskey()
Return the key of the middleware.
public
key() : int
Tags
Return values
intnext()
Moves the current position to the next middleware.
public
next() : void
Tags
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
$thispush()
Alias for MiddlewareQueue::add().
public
push(MiddlewareInterface|Closure|array<string|int, mixed>|string $middleware) : $this
Parameters
- $middleware : MiddlewareInterface|Closure|array<string|int, mixed>|string
-
The middleware(s) to append.
Tags
Return values
$thisrewind()
Rewinds back to the first element of the queue.
public
rewind() : void
Tags
seek()
Seeks to a given position in the queue.
public
seek(int $position) : void
Parameters
- $position : int
-
The position to seek to.
Tags
valid()
Checks if current position is valid.
public
valid() : bool
Tags
Return values
boolresolve()
Resolve middleware name to a PSR 15 compliant middleware instance.
protected
resolve(MiddlewareInterface|Closure|string $middleware) : MiddlewareInterface
Parameters
- $middleware : MiddlewareInterface|Closure|string
-
The middleware to resolve.