private function YamlFileLoader::validate

Same name in this branch
  1. 8.x drupal/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php \Drupal\Core\DependencyInjection\YamlFileLoader::validate()
  2. 8.x drupal/core/vendor/symfony/routing/Symfony/Component/Routing/Loader/YamlFileLoader.php \Symfony\Component\Routing\Loader\YamlFileLoader::validate()
  3. 8.x drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php \Symfony\Component\DependencyInjection\Loader\YamlFileLoader::validate()

Validates a YAML file.

Parameters

mixed $content:

string $file:

Return value

array

Throws

InvalidArgumentException When service file is not valid

1 call to YamlFileLoader::validate()
YamlFileLoader::loadFile in drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
Loads a YAML file.

File

drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php, line 273

Class

YamlFileLoader
YamlFileLoader loads YAML files service definitions.

Namespace

Symfony\Component\DependencyInjection\Loader

Code

private function validate($content, $file) {
  if (null === $content) {
    return $content;
  }
  if (!is_array($content)) {
    throw new InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
  }
  foreach (array_keys($content) as $namespace) {
    if (in_array($namespace, array(
      'imports',
      'parameters',
      'services',
    ))) {
      continue;
    }
    if (!$this->container
      ->hasExtension($namespace)) {
      $extensionNamespaces = array_filter(array_map(function ($ext) {
        return $ext
          ->getAlias();
      }, $this->container
        ->getExtensions()));
      throw new InvalidArgumentException(sprintf('There is no extension able to load the configuration for "%s" (in %s). Looked for namespace "%s", found %s', $namespace, $file, $namespace, $extensionNamespaces ? sprintf('"%s"', implode('", "', $extensionNamespaces)) : 'none'));
    }
  }
  return $content;
}