0

Final Class Yiisoft\Queue\Message\Handler\HandlerResolver

InheritanceYiisoft\Queue\Message\Handler\HandlerResolver

Resolves message handlers from configuration, a DI container, or a callable factory.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Queue\Message\Handler\HandlerResolver
resolve() Get a handler for the given message type. Yiisoft\Queue\Message\Handler\HandlerResolver

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( (array|callable|\Yiisoft\Queue\Message\Handler\HandlerInterface|string)[] $handlers, \Psr\Container\ContainerInterface $container, \Psr\Container\ContainerInterface|null $callableDependencyContainer null )
$handlers (array|callable|\Yiisoft\Queue\Message\Handler\HandlerInterface|string)[]

Handler definitions indexed by message type.

$container \Psr\Container\ContainerInterface

Container used to resolve handlers.

$callableDependencyContainer \Psr\Container\ContainerInterface|null

Container used to resolve callable handler dependencies. If not set, the main container is used.

                public function __construct(
    private readonly array $handlers,
    private readonly ContainerInterface $container,
    ?ContainerInterface $callableDependencyContainer = null,
) {
    $this->callableFactory = new CallableFactory($this->container, $callableDependencyContainer);
}

            
resolve() public method

Get a handler for the given message type.

public Yiisoft\Queue\Message\Handler\HandlerInterface resolve ( string $messageType )
$messageType string

Message type. Must be a non-empty string.

throws Yiisoft\Queue\Message\Handler\HandlerNotFoundException

If no handler exists for the message type.

throws Yiisoft\Queue\Message\Handler\InvalidHandlerConfigurationException

If the handler definition is configured incorrectly.

                public function resolve(string $messageType): HandlerInterface
{
    if (array_key_exists($messageType, $this->cache)) {
        return $this->cache[$messageType];
    }
    $this->cache[$messageType] = $this->internalResolve($messageType);
    return $this->cache[$messageType];
}