Invoker\CallableResolver::resolveFromContainer PHP Method

resolveFromContainer() private method

private resolveFromContainer ( callable | string | array $callable ) : callable
$callable callable | string | array
return callable
    private function resolveFromContainer($callable)
    {
        // Shortcut for a very common use case
        if ($callable instanceof \Closure) {
            return $callable;
        }
        $isStaticCallToNonStaticMethod = false;
        // If it's already a callable there is nothing to do
        if (is_callable($callable)) {
            $isStaticCallToNonStaticMethod = $this->isStaticCallToNonStaticMethod($callable);
            if (!$isStaticCallToNonStaticMethod) {
                return $callable;
            }
        }
        // The callable is a container entry name
        if (is_string($callable)) {
            try {
                return $this->container->get($callable);
            } catch (NotFoundException $e) {
                throw NotCallableException::fromInvalidCallable($callable, true);
            }
        }
        // The callable is an array whose first item is a container entry name
        // e.g. ['some-container-entry', 'methodToCall']
        if (is_array($callable) && is_string($callable[0])) {
            try {
                // Replace the container entry name by the actual object
                $callable[0] = $this->container->get($callable[0]);
                return $callable;
            } catch (NotFoundException $e) {
                if ($isStaticCallToNonStaticMethod) {
                    throw new NotCallableException(sprintf('Cannot call %s::%s() because %s() is not a static method and "%s" is not a container entry', $callable[0], $callable[1], $callable[1], $callable[0]));
                }
                throw new NotCallableException(sprintf('Cannot call %s on %s because it is not a class nor a valid container entry', $callable[1], $callable[0]));
            }
        }
        // Unrecognized stuff, we let it fail later
        return $callable;
    }