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

Breadcrumb

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

function YamlFileLoader::parseDefaults

Same name in this branch
  1. 11.1.x core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php \Drupal\Core\DependencyInjection\YamlFileLoader::parseDefaults()

Throws

InvalidArgumentException

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

File

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

Class

YamlFileLoader
YamlFileLoader loads YAML files service definitions.

Namespace

Symfony\Component\DependencyInjection\Loader

Code

private function parseDefaults(array &$content, string $file) : array {
    if (!\array_key_exists('_defaults', $content['services'])) {
        return [];
    }
    $defaults = $content['services']['_defaults'];
    unset($content['services']['_defaults']);
    if (!\is_array($defaults)) {
        throw new InvalidArgumentException(\sprintf('Service "_defaults" key must be an array, "%s" given in "%s".', get_debug_type($defaults), $file));
    }
    foreach ($defaults as $key => $default) {
        if (!isset(self::DEFAULTS_KEYWORDS[$key])) {
            throw new InvalidArgumentException(\sprintf('The configuration key "%s" cannot be used to define a default value in "%s". Allowed keys are "%s".', $key, $file, implode('", "', self::DEFAULTS_KEYWORDS)));
        }
    }
    if (isset($defaults['tags'])) {
        if (!\is_array($tags = $defaults['tags'])) {
            throw new InvalidArgumentException(\sprintf('Parameter "tags" in "_defaults" must be an array in "%s". Check your YAML syntax.', $file));
        }
        foreach ($tags as $tag) {
            if (!\is_array($tag)) {
                $tag = [
                    'name' => $tag,
                ];
            }
            if (1 === \count($tag) && \is_array(current($tag))) {
                $name = key($tag);
                $tag = current($tag);
            }
            else {
                if (!isset($tag['name'])) {
                    throw new InvalidArgumentException(\sprintf('A "tags" entry in "_defaults" is missing a "name" key in "%s".', $file));
                }
                $name = $tag['name'];
                unset($tag['name']);
            }
            if (!\is_string($name) || '' === $name) {
                throw new InvalidArgumentException(\sprintf('The tag name in "_defaults" must be a non-empty string in "%s".', $file));
            }
            $this->validateAttributes(\sprintf('Tag "%s", attribute "%s" in "_defaults" must be of a scalar-type in "%s". Check your YAML syntax.', $name, '%s', $file), $tag);
        }
    }
    if (isset($defaults['bind'])) {
        if (!\is_array($defaults['bind'])) {
            throw new InvalidArgumentException(\sprintf('Parameter "bind" in "_defaults" must be an array in "%s". Check your YAML syntax.', $file));
        }
        foreach ($this->resolveServices($defaults['bind'], $file) as $argument => $value) {
            $defaults['bind'][$argument] = new BoundArgument($value, true, BoundArgument::DEFAULTS_BINDING, $file);
        }
    }
    return $defaults;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal