private function YamlFileLoader::validate

private YamlFileLoader::validate($content, $file)

Validates a YAML file.

Parameters

mixed $content:

string $file:

Return value

array

Throws

InvalidArgumentException When service file is not valid.

File

core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php, line 348

Class

YamlFileLoader
YamlFileLoader loads YAML files service definitions.

Namespace

Drupal\Core\DependencyInjection

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. It should contain an array. Check your YAML syntax.', $file));
  }

  if ($invalid_keys = array_diff_key($content, array('parameters' => 1, 'services' => 1))) {
    throw new InvalidArgumentException(sprintf('The service file "%s" is not valid: it contains invalid keys %s. Services have to be added under "services" and Parameters under "parameters".', $file, $invalid_keys));
  }

  return $content;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!DependencyInjection!YamlFileLoader.php/function/YamlFileLoader::validate/8.1.x