Final Class Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareDispatcher
| Inheritance | Yiisoft\ |
|---|
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| dispatch() | Dispatch request through middleware to get response. | Yiisoft\ |
| hasMiddlewares() | Yiisoft\ |
|
| withMiddlewares() | Returns new instance with middleware handlers replaced with the ones provided. | Yiisoft\ |
Method Details
| public mixed __construct ( Yiisoft\ | ||
| $middlewareFactory | Yiisoft\ |
|
| $middlewareDefinitions | array|callable|string|Yiisoft\ |
|
public function __construct(
private readonly ConsumeMiddlewareFactoryInterface $middlewareFactory,
array|callable|string|ConsumeMiddlewareInterface ...$middlewareDefinitions,
) {
$this->middlewareDefinitions = array_reverse($middlewareDefinitions);
}
Dispatch request through middleware to get response.
| public Yiisoft\ | ||
| $request | Yiisoft\ |
Request to pass to middleware. |
| $finishHandler | Yiisoft\ |
Handler to use in case no middleware produced a response. |
public function dispatch(
ConsumeRequest $request,
ConsumeHandlerInterface $finishHandler,
): ConsumeRequest {
$type = $request->getMessage()->getType();
if (!array_key_exists($type, $this->stack)) {
$this->stack[$type] = new ConsumeMiddlewareStack($this->buildMiddlewares(), $finishHandler);
}
return $this->stack[$type]->handleConsume($request);
}
| public boolean hasMiddlewares ( ) | ||
| return | boolean |
Whether there are middleware defined in the dispatcher. |
|---|---|---|
public function hasMiddlewares(): bool
{
return $this->middlewareDefinitions !== [];
}
Returns new instance with middleware handlers replaced with the ones provided.
The last specified handler will be executed first.
| public self withMiddlewares ( array[]|callable[]|Yiisoft\ | ||
| $middlewareDefinitions | array[]|callable[]|Yiisoft\ |
Each array element is:
For callables typed parameters are automatically injected using dependency injection container. |
| return | self |
New instance of the {@see \ |
|---|---|---|
public function withMiddlewares(array $middlewareDefinitions): self
{
$instance = clone $this;
$instance->middlewareDefinitions = array_reverse($middlewareDefinitions);
// Fixes a memory leak.
unset($instance->stack);
$instance->stack = [];
return $instance;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.