diff --git a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php index ed3111a..c578023 100644 --- a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php +++ b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php @@ -83,6 +83,10 @@ public function load($file) // parameters if (isset($content['parameters'])) { + if (!is_array($content['parameters'])) { + throw new InvalidArgumentException(sprintf('The "parameters" key should contain an array in %s. Check your YAML syntax.', $file)); + } + foreach ($content['parameters'] as $key => $value) { $this->container->setParameter($key, $this->resolveServices($value)); } @@ -108,6 +112,10 @@ private function parseDefinitions($content, $file) return; } + if (!is_array($content['services'])) { + throw new InvalidArgumentException(sprintf('The "services" key should contain an array in %s. Check your YAML syntax.', $file)); + } + foreach ($content['services'] as $id => $service) { $this->parseDefinition($id, $service, $file); } @@ -128,8 +136,14 @@ private function parseDefinition($id, $service, $file) $this->container->setAlias($id, substr($service, 1)); return; - } elseif (isset($service['alias'])) { - $public = !array_key_exists('public', $service) || (Boolean) $service['public']; + } + + if (!is_array($service)) { + throw new InvalidArgumentException(sprintf('A service definition must be an array or a string starting with "@" but %s found for service "%s" in %s. Check your YAML syntax.', gettype($service), $id, $file)); + } + + if (isset($service['alias'])) { + $public = !array_key_exists('public', $service) || (bool) $service['public']; $this->container->setAlias($id, new Alias($service['alias'], $public)); return; @@ -215,6 +229,10 @@ private function parseDefinition($id, $service, $file) } if (isset($service['calls'])) { + if (!is_array($service['calls'])) { + throw new InvalidArgumentException(sprintf('Parameter "calls" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file)); + } + foreach ($service['calls'] as $call) { $args = isset($call[1]) ? $this->resolveServices($call[1]) : array(); $definition->addMethodCall($call[0], $args); @@ -223,10 +241,14 @@ private function parseDefinition($id, $service, $file) if (isset($service['tags'])) { if (!is_array($service['tags'])) { - throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s.', $id, $file)); + throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file)); } foreach ($service['tags'] as $tag) { + if (!is_array($tag)) { + throw new InvalidArgumentException(sprintf('A "tags" entry must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file)); + } + if (!isset($tag['name'])) { throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file)); } @@ -236,7 +258,7 @@ private function parseDefinition($id, $service, $file) foreach ($tag as $attribute => $value) { if (!is_scalar($value) && null !== $value) { - throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s.', $id, $name, $attribute, $file)); + throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s. Check your YAML syntax.', $id, $name, $attribute, $file)); } } @@ -244,6 +266,11 @@ private function parseDefinition($id, $service, $file) } } + if (isset($service['decorates'])) { + $renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null; + $definition->setDecoratedService($service['decorates'], $renameId); + } + $this->container->setDefinition($id, $definition); } @@ -253,6 +280,8 @@ private function parseDefinition($id, $service, $file) * @param string $file * * @return array The file content + * + * @throws InvalidArgumentException when the given file is not a local file or when it does not exist */ protected function loadFile($file) { @@ -284,7 +313,7 @@ private function validate($content, $file) } if (!is_array($content)) { - throw new InvalidArgumentException(sprintf('The service file "%s" is not valid: it is not an array.', $file)); + 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))) { @@ -297,9 +326,9 @@ private function validate($content, $file) /** * Resolves services. * - * @param string $value + * @param string|array $value * - * @return Reference + * @return array|string|Reference */ private function resolveServices($value) {