8000 [DependencyInjection] Yaml: check if is an array before using it · symfony/symfony@7c27b8e · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c27b8e

Browse files
committed
[DependencyInjection] Yaml: check if is an array before using it
1 parent 4491eb6 commit 7c27b8e

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,15 @@ private function parseDefinition($id, $service, $file, array $defaults)
331331
}
332332
}
333333

334-
$tags = isset($service['tags']) ? $service['tags'] : array();
334+
if (isset($service['tags'])) {
335+
$tags = $service['tags'];
336+
337+
if (!is_array($tags)) {
338+
throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
339+
}
340+
} else {
341+
$tags = array();
342+
}
335343

336344
if (!isset($defaults['tags'])) {
337345
// no-op
@@ -343,34 +351,28 @@ private function parseDefinition($id, $service, $file, array $defaults)
343351
$tags = array_merge($tags, $defaults['tags']);
344352
}
345353

346-
if (null !== $tags) {
347-
if (!is_array($tags)) {
348-
throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
354+
foreach ($tags as $tag) {
355+
if (!is_array($tag)) {
356+
$tag = array('name' => $tag);
349357
}
350358

351-
foreach ($tags as $tag) {
352-
if (!is_array($tag)) {
353-
$tag = array('name' => $tag);
354-
}
355-
356-
if (!isset($tag['name'])) {
357-
throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
358-
}
359-
$name = $tag['name'];
360-
unset($tag['name']);
359+
if (!isset($tag['name'])) {
360+
throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
361+
}
362+
$name = $tag['name'];
363+
unset($tag['name']);
361364

362-
if (!is_string($name) || '' === $name) {
363-
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
364-
}
365+
if (!is_string($name) || '' === $name) {
366+
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
367+
}
365368

366-
foreach ($tag as $attribute => $value) {
367-
if (!is_scalar($value) && null !== $value) {
368-
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));
369-
}
369+
foreach ($tag as $attribute => $value) {
370+
if (!is_scalar($value) && null !== $value) {
371+
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));
370372
}
371-
372-
$definition->addTag($name, $tag);
373373
}
374+
375+
$definition->addTag($name, $tag);
374376
}
375377

376378
if (isset($service['decorates'])) {

0 commit comments

Comments
 (0)
0