You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #47364 [DependencyInjection] Allow array attributes for service tags (aschempp)
This PR was merged into the 6.2 branch.
Discussion
----------
[DependencyInjection] Allow array attributes for service tags
| Q | A
| ------------- | ---
| Branch? | 6.2
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Tickets | Fixsymfony/symfony#38339, symfony/symfony#38540
| License | MIT
| Doc PR | symfony/symfony-docs#... <!-- required for new features -->
This adds array attribute support for container service tags as described in symfony/symfony#38339. The most notable change is the additions to the XML schema for services, because that's the current limitation for not using array.
This is reopening symfony/symfony#38540 as new PR since the other one was ("accidentially") closed 😊
/cc `@nicolas`-grekas
Commits
-------
edd8d776a0 [DependencyInjection] Allow array attributes for service tags
thrownewInvalidArgumentException(sprintf('Tag "%s", attribute "%s" in "_defaults" must be of a scalar-type or an array of scalar-type.', $tagName, $prefix.$attribute));
Copy file name to clipboardExpand all lines: Loader/Configurator/Traits/TagTrait.php
+12-5Lines changed: 12 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -26,14 +26,21 @@ final public function tag(string $name, array $attributes = []): static
26
26
thrownewInvalidArgumentException(sprintf('The tag name for service "%s" must be a non-empty string.', $this->id));
27
27
}
28
28
29
-
foreach ($attributesas$attribute => $value) {
30
-
if (!\is_scalar($value) && null !== $value) {
31
-
thrownewInvalidArgumentException(sprintf('A tag attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s".', $this->id, $name, $attribute));
thrownewInvalidArgumentException(sprintf('A tag attribute must be of a scalar-type or an array of scalar-types for service "%s", tag "%s", attribute "%s".', $this->id, $tagName, $prefix.$attribute));
thrownewInvalidArgumentException(sprintf('The tag name for service "%s" in "%s" must be a non-empty string.', (string) $service->getAttribute('id'), $file));
341
+
}
342
+
343
+
$parameters = $this->getTagAttributes($tag, sprintf('The attribute name of tag "%s" for service "%s" in %s must be a non-empty string.', $tagName, (string) $service->getAttribute('id'), $file));
thrownewInvalidArgumentException(sprintf('The tag name in "_defaults" must be a non-empty string in "%s".', $file));
298
298
}
299
299
300
-
foreach ($tagas$attribute => $value) {
301
-
if (!\is_scalar($value) && null !== $value) {
302
-
thrownewInvalidArgumentException(sprintf('Tag "%s", attribute "%s" in "_defaults" must be of a scalar-type in "%s". Check your YAML syntax.', $name, $attribute, $file));
303
-
}
304
-
}
300
+
$this->validateAttributes(sprintf('Tag "%s", attribute "%s" in "_defaults" must be of a scalar-type in "%s". Check your YAML syntax.', $name, '%s', $file), $tag);
thrownewInvalidArgumentException(sprintf('The tag name for service "%s" in "%s" must be a non-empty string.', $id, $file));
606
602
}
607
603
608
-
foreach ($tagas$attribute => $value) {
609
-
if (!\is_scalar($value) && null !== $value) {
610
-
thrownewInvalidArgumentException(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));
611
-
}
612
-
}
604
+
$this->validateAttributes(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, '%s', $file), $tag);
0 commit comments