Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. YamlFileLoader.php

function YamlFileLoader::parseCallable

Throws

InvalidArgumentException When errors occur

1 call to YamlFileLoader::parseCallable()
YamlFileLoader::parseDefinition in vendor/symfony/dependency-injection/Loader/YamlFileLoader.php

File

vendor/symfony/dependency-injection/Loader/YamlFileLoader.php, line 722

Class

YamlFileLoader
YamlFileLoader loads YAML files service definitions.

Namespace

Symfony\Component\DependencyInjection\Loader

Code

private function parseCallable(mixed $callable, string $parameter, string $id, string $file) : string|array|Reference {
    if (\is_string($callable)) {
        if (str_starts_with($callable, '@=')) {
            if ('factory' !== $parameter) {
                throw new InvalidArgumentException(\sprintf('Using expressions in "%s" for the "%s" service is not supported in "%s".', $parameter, $id, $file));
            }
            if (!class_exists(Expression::class)) {
                throw new \LogicException('The "@=" expression syntax cannot be used without the ExpressionLanguage component. Try running "composer require symfony/expression-language".');
            }
            return $callable;
        }
        if ('' !== $callable && '@' === $callable[0]) {
            if (!str_contains($callable, ':')) {
                return [
                    $this->resolveServices($callable, $file),
                    '__invoke',
                ];
            }
            throw new InvalidArgumentException(\sprintf('The value of the "%s" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s" in "%s").', $parameter, $id, $callable, substr($callable, 1), $file));
        }
        return $callable;
    }
    if (\is_array($callable)) {
        if (isset($callable[0]) && isset($callable[1])) {
            return [
                $this->resolveServices($callable[0], $file),
                $callable[1],
            ];
        }
        if ('factory' === $parameter && isset($callable[1]) && null === $callable[0]) {
            return $callable;
        }
        throw new InvalidArgumentException(\sprintf('Parameter "%s" must contain an array with two elements for service "%s" in "%s". Check your YAML syntax.', $parameter, $id, $file));
    }
    throw new InvalidArgumentException(\sprintf('Parameter "%s" must be a string or an array for service "%s" in "%s". Check your YAML syntax.', $parameter, $id, $file));
}
RSS feed
Powered by Drupal