protected function YamlFileLoader::validate

Same name in this branch

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()

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;
}