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.
__construct(array $middleware)
Constructor
array
$middleware optional The list of middleware to append.
add(mixed $middleware)
Append a middleware to the end of the queue.
string|array|\Closure|\Psr\Http\Server\MiddlewareInterface
$middleware The middleware(s) to append.
$this
count()
Get the number of connected middleware layers.
Implement the Countable interface.
int
current()
Returns the current middleware.
\Psr\Http\Server\MiddlewareInterface
insertAfter(string $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 middleware after it. If the class is not found, this method will behave like add().
string
$class The classname to insert the middleware before.
string|\Closure|\Psr\Http\Server\MiddlewareInterface
$middleware The middleware to insert.
$this
insertAt(int $index, mixed $middleware)
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.
int
$index The index to insert at.
string|\Closure|\Psr\Http\Server\MiddlewareInterface
$middleware The middleware to insert.
$this
insertBefore(string $class, mixed $middleware)
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.
string
$class The classname to insert the middleware before.
string|\Closure|\Psr\Http\Server\MiddlewareInterface
$middleware The middleware to insert.
$this
LogicException
key()
Return the key of the middleware.
int
next()
Moves the current position to the next middleware.
prepend(mixed $middleware)
Prepend a middleware to the start of the queue.
string|array|\Closure|\Psr\Http\Server\MiddlewareInterface
$middleware The middleware(s) to prepend.
$this
push(mixed $middleware)
Alias for MiddlewareQueue::add().
string|array|\Closure|\Psr\Http\Server\MiddlewareInterface
$middleware The middleware(s) to append.
$this
resolve(mixed $middleware)
Resolve middleware name to a PSR 15 compliant middleware instance.
string|\Closure|\Psr\Http\Server\MiddlewareInterface
$middleware The middleware to resolve.
\Psr\Http\Server\MiddlewareInterface
RuntimeException
rewind()
Rewinds back to the first element of the queue.
seek(mixed $position)
Seeks to a given position in the queue.
int
$position The position to seek to.
valid()
Checks if current position is valid.
bool
Internal position for iterator.
int
The queue of middlewares.
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/4.1/class-Cake.Http.MiddlewareQueue.html