0 follower

Final Class Yiisoft\Queue\Middleware\CallableFactory

InheritanceYiisoft\Queue\Middleware\CallableFactory

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Queue\Middleware\CallableFactory
create() Create a real callable listener from definition. Yiisoft\Queue\Middleware\CallableFactory

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Psr\Container\ContainerInterface $container )
$container \Psr\Container\ContainerInterface

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

            
create() public method

Create a real callable listener from definition.

public callable create ( mixed $definition )
$definition mixed

Definition to create listener from.

throws Yiisoft\Queue\Middleware\InvalidCallableConfigurationException

Failed to create listener.

throws \Psr\Container\ContainerExceptionInterface

Error while retrieving the entry from container.

                public function create(mixed $definition): callable
{
    if ($definition === null) {
        throw new InvalidCallableConfigurationException();
    }
    if ($definition instanceof Closure) {
        return $definition;
    }
    if (is_string($definition) && $this->container->has($definition)) {
        $result = $this->container->get($definition);
        if (is_callable($result)) {
            return $result;
        }
        throw new InvalidCallableConfigurationException();
    }
    if (is_array($definition)
        && array_keys($definition) === [0, 1]
        && is_string($definition[1])
    ) {
        if (is_object($definition[0])) {
            $callable = $this->fromObjectDefinition($definition[0], $definition[1]);
            if ($callable !== null) {
                return $callable;
            }
        }
        /** @psalm-suppress PossiblyUndefinedArrayOffset array_keys($definition) === [0, 1] was checked above */
        if (is_string($definition[0])) {
            $callable = $this->fromDefinition($definition[0], $definition[1]);
            if ($callable !== null) {
                return $callable;
            }
        }
    }
    if (is_callable($definition)) {
        return $definition;
    }
    throw new InvalidCallableConfigurationException();
}