protected 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: The parsed YAML file.

string $filename: The name of the file, only used for error messages.

Return value

array The $content unchanged returned to allow for chaining this method.

Throws

\InvalidArgumentException When service file is not valid

1 call to YamlFileLoader::validate()
YamlFileLoader::loadFile in drupal/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
Loads a YAML file.

File

drupal/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php, line 198
Contains \Drupal\Core\DependencyInjection\YamlFileLoader.

Class

YamlFileLoader
YamlFileLoader loads YAML files service definitions.

Namespace

Drupal\Core\DependencyInjection

Code

protected function validate($content, $filename) {
  if (NULL === $content) {
    return $content;
  }
  if (!is_array($content)) {
    throw new \InvalidArgumentException(sprintf('The service file "%s" is not valid: it is not an array.', $filename));
  }
  if ($keys = array_diff_key($content, array(
    'parameters' => TRUE,
    'services' => TRUE,
  ))) {
    $invalid_keys = htmlspecialchars(implode(', ', $keys), ENT_QUOTES, 'UTF-8');
    throw new \InvalidArgumentException(sprintf('The service file "%s" is not valid: it contains invalid keys %s.', $filename, $invalid_keys));
  }
  return $content;
}