Class MiddlewareQueue
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.
Property Summary
-
$container protected
Cake\Core\ContainerInterface|null -
$position protected
intInternal position for iterator.
-
$queue protected
array<int, mixed>The queue of middlewares.
Method Summary
-
__construct() public
Constructor
-
add() public
Append a middleware to the end of the queue.
-
count() public
Get the number of connected middleware layers.
-
current() public
Returns the current middleware.
-
insertAfter() public
Insert a middleware object after the first matching class.
-
insertAt() public
Insert a middleware at a specific index.
-
insertBefore() public
Insert a middleware before the first matching class.
-
key() public
Return the key of the middleware.
-
next() public
Moves the current position to the next middleware.
-
prepend() public
Prepend a middleware to the start of the queue.
-
push() public
Alias for MiddlewareQueue::add().
-
resolve() protected
Resolve middleware name to a PSR 15 compliant middleware instance.
-
rewind() public
Rewinds back to the first element of the queue.
-
seek() public
Seeks to a given position in the queue.
-
valid() public
Checks if current position is valid.
Method Detail
__construct() ¶ public
__construct(array $middleware = [], Cake\Core\ContainerInterface $container = null)
Constructor
Parameters
-
array$middleware optional The list of middleware to append.
-
Cake\Core\ContainerInterface$container optional Container instance.
add() ¶ public
add(Psr\Http\Server\MiddlewareInterface|Closure|array|string $middleware): $this
Append a middleware to the end of the queue.
Parameters
-
Psr\Http\Server\MiddlewareInterface|Closure|array|string$middleware The middleware(s) to append.
Returns
$thiscount() ¶ public
count(): int
Get the number of connected middleware layers.
Implement the Countable interface.
Returns
intcurrent() ¶ public
current(): Psr\Http\Server\MiddlewareInterface
Returns the current middleware.
Returns
Psr\Http\Server\MiddlewareInterfaceSee Also
insertAfter() ¶ public
insertAfter(string $class, Psr\Http\Server\MiddlewareInterface|Closure|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 middleware after it. If the class is not found, this method will behave like add().
Parameters
-
string$class The classname to insert the middleware before.
-
Psr\Http\Server\MiddlewareInterface|Closure|string$middleware The middleware to insert.
Returns
$thisinsertAt() ¶ public
insertAt(int $index, Psr\Http\Server\MiddlewareInterface|Closure|string $middleware): $this
Insert a middleware at a specific index.
If the index already exists, the new middleware will be inserted, and the existing element will be shifted one index greater.
Parameters
-
int$index The index to insert at.
-
Psr\Http\Server\MiddlewareInterface|Closure|string$middleware The middleware to insert.
Returns
$thisinsertBefore() ¶ public
insertBefore(string $class, Psr\Http\Server\MiddlewareInterface|Closure|string $middleware): $this
Insert a middleware before the first matching class.
Finds the index of the first middleware that matches the provided class, and inserts the supplied middleware before it.
Parameters
-
string$class The classname to insert the middleware before.
-
Psr\Http\Server\MiddlewareInterface|Closure|string$middleware The middleware to insert.
Returns
$thisThrows
LogicExceptionIf middleware to insert before is not found.
next() ¶ public
next(): void
Moves the current position to the next middleware.
Returns
voidSee Also
prepend() ¶ public
prepend(Psr\Http\Server\MiddlewareInterface|Closure|array|string $middleware): $this
Prepend a middleware to the start of the queue.
Parameters
-
Psr\Http\Server\MiddlewareInterface|Closure|array|string$middleware The middleware(s) to prepend.
Returns
$thispush() ¶ public
push(Psr\Http\Server\MiddlewareInterface|Closure|array|string $middleware): $this
Alias for MiddlewareQueue::add().
Parameters
-
Psr\Http\Server\MiddlewareInterface|Closure|array|string$middleware The middleware(s) to append.
Returns
$thisSee Also
resolve() ¶ protected
resolve(Psr\Http\Server\MiddlewareInterface|Closure|string $middleware): Psr\Http\Server\MiddlewareInterface
Resolve middleware name to a PSR 15 compliant middleware instance.
Parameters
-
Psr\Http\Server\MiddlewareInterface|Closure|string$middleware The middleware to resolve.
Returns
Psr\Http\Server\MiddlewareInterfaceThrows
RuntimeExceptionIf Middleware not found.
rewind() ¶ public
rewind(): void
Rewinds back to the first element of the queue.
Returns
voidSee Also
seek() ¶ public
seek(int $position): void
Seeks to a given position in the queue.
Parameters
-
int$position The position to seek to.
Returns
voidSee Also
valid() ¶ public
valid(): bool
Checks if current position is valid.
Returns
bool