0 follower

Final Class Yiisoft\Queue\Middleware\Push\MiddlewareFactoryPush

InheritanceYiisoft\Queue\Middleware\Push\MiddlewareFactoryPush
ImplementsYiisoft\Queue\Middleware\Push\MiddlewareFactoryPushInterface

Creates a middleware based on the definition provided.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Psr\Container\ContainerInterface $container, Yiisoft\Queue\Middleware\CallableFactory $callableFactory )
$container \Psr\Container\ContainerInterface

Container to use for resolving definitions.

$callableFactory Yiisoft\Queue\Middleware\CallableFactory

                public function __construct(
    private readonly ContainerInterface $container,
    private readonly CallableFactory $callableFactory,
) {
}

            
createPushMiddleware() public method

public Yiisoft\Queue\Middleware\Push\MiddlewarePushInterface createPushMiddleware ( array|callable|Yiisoft\Queue\Middleware\Push\MiddlewarePushInterface|string $middlewareDefinition )
$middlewareDefinition array|callable|Yiisoft\Queue\Middleware\Push\MiddlewarePushInterface|string

Middleware definition in one of the following formats:

  • A middleware object.
  • A name of a middleware class. The middleware instance will be obtained from container and executed.
  • A callable with function(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface signature.
  • A controller handler action in format [TestController::class, 'index']. TestController instance will be created and index() method will be executed.
  • A function returning a middleware. The middleware returned will be executed.

For handler action and callable typed parameters are automatically injected using dependency injection container. Current request and handler could be obtained by type-hinting for {@see \Yiisoft\Queue\Middleware\Push\ServerRequestInterface} and {@see \Yiisoft\Queue\Middleware\Push\RequestHandlerInterface}.

throws Yiisoft\Queue\Middleware\InvalidMiddlewareDefinitionException

                public function createPushMiddleware(
    MiddlewarePushInterface|callable|array|string $middlewareDefinition
): MiddlewarePushInterface {
    if ($middlewareDefinition instanceof MiddlewarePushInterface) {
        return $middlewareDefinition;
    }
    if (is_string($middlewareDefinition)) {
        return $this->getFromContainer($middlewareDefinition);
    }
    return $this->tryGetFromCallable($middlewareDefinition)
        ?? $this->tryGetFromArrayDefinition($middlewareDefinition)
        ?? throw new InvalidMiddlewareDefinitionException($middlewareDefinition);
}