Skip to content

Commit 0552d19

Browse files
bug #51669 [FrameworkBundle] Handle tags array attributes in descriptors (fancyweb)
This PR was merged into the 6.3 branch. Discussion ---------- [FrameworkBundle] Handle tags array attributes in descriptors | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #51636 | License | MIT | Doc PR | - Targeting 6.3 since array attributes are only possible in tags since 6.2. Commits ------- 71cf59c [FrameworkBundle] Handle tags array attributes in descriptors
2 parents a99b697 + 71cf59c commit 0552d19

25 files changed

+248
-66
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
254254
foreach ($tagData as $parameters) {
255255
$output .= "\n".'- Tag: `'.$tagName.'`';
256256
foreach ($parameters as $name => $value) {
257-
$output .= "\n".' - '.ucfirst($name).': '.$value;
257+
$output .= "\n".' - '.ucfirst($name).': '.(\is_array($value) ? $this->formatParameter($value) : $value);
258258
}
259259
}
260260
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ protected function describeContainerServices(ContainerBuilder $container, array
209209
if (!isset($maxTags[$key])) {
210210
$maxTags[$key] = \strlen($key);
211211
}
212+
if (\is_array($value)) {
213+
$value = $this->formatParameter($value);
214+
}
215+
212216
if (\strlen($value) > $maxTags[$key]) {
213217
$maxTags[$key] = \strlen($value);
214218
}
@@ -233,7 +237,11 @@ protected function describeContainerServices(ContainerBuilder $container, array
233237
foreach ($this->sortByPriority($definition->getTag($showTag)) as $key => $tag) {
234238
$tagValues = [];
235239
foreach ($tagsNames as $tagName) {
236-
$tagValues[] = $tag[$tagName] ?? '';
240+
if (\is_array($tagValue = $tag[$tagName] ?? '')) {
241+
$tagValue = $this->formatParameter($tagValue);
242+
}
243+
244+
$tagValues[] = $tagValue;
237245
}
238246
if (0 === $key) {
239247
$tableRows[] = array_merge([$serviceId], $tagValues, [$definition->getClass()]);
@@ -275,7 +283,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
275283
$tagInformation = [];
276284
foreach ($tags as $tagName => $tagData) {
277285
foreach ($tagData as $tagParameters) {
278-
$parameters = array_map(fn ($key, $value) => sprintf('<info>%s</info>: %s', $key, $value), array_keys($tagParameters), array_values($tagParameters));
286+
$parameters = array_map(fn ($key, $value) => sprintf('<info>%s</info>: %s', $key, \is_array($value) ? $this->formatParameter($value) : $value), array_keys($tagParameters), array_values($tagParameters));
279287
$parameters = implode(', ', $parameters);
280288

281289
if ('' === $parameters) {

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public static function getContainerDefinitions()
169169
->addTag('tag1', ['attr1' => 'val1', 'attr2' => 'val2'])
170170
->addTag('tag1', ['attr3' => 'val3'])
171171
->addTag('tag2')
172+
->addTag('tag3', ['array_attr' => ['foo', 'bar', [[[['ccc']]]]]])
172173
->addMethodCall('setMailer', [new Reference('mailer')])
173174
->setFactory([new Reference('factory.service'), 'get']),
174175
'.definition_3' => $definition3

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@
3636
{
3737
"name": "tag2",
3838
"parameters": []
39+
},
40+
{
41+
"name": "tag3",
42+
"parameters": {
43+
"array_attr": [
44+
"foo",
45+
"bar",
46+
[
47+
[
48+
[
49+
[
50+
"ccc"
51+
]
52+
]
53+
]
54+
]
55+
]
56+
}
3957
}
4058
],
4159
"usages": [

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@
2424
- Tag: `tag1`
2525
- Attr3: val3
2626
- Tag: `tag2`
27+
- Tag: `tag3`
28+
- Array_attr: ["foo","bar",[[[["ccc"]]]]]
2729
- Usages: .alias_2

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.txt

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33
Information for Service ".service_2"
44
====================================
55

6-
----------------- ---------------------------------
7-
 Option   Value 
8-
----------------- ---------------------------------
9-
Service ID .service_2
10-
Class Full\Qualified\Class2
11-
Tags tag1 (attr1: val1, attr2: val2)
12-
tag1 (attr3: val3)
13-
tag2
14-
Calls setMailer
15-
Public no
16-
Synthetic yes
17-
Lazy no
18-
Shared yes
19-
Abstract no
20-
Autowired no
21-
Autoconfigured no
22-
Required File /path/to/file
23-
Factory Service factory.service
24-
Factory Method get
25-
Usages .alias_2
26-
----------------- ---------------------------------
6+
----------------- ------------------------------------------------
7+
 Option   Value 
8+
----------------- ------------------------------------------------
9+
Service ID .service_2
10+
Class Full\Qualified\Class2
11+
Tags tag1 (attr1: val1, attr2: val2)
12+
tag1 (attr3: val3)
13+
tag2
14+
tag3 (array_attr: ["foo","bar",[[[["ccc"]]]]])
15+
Calls setMailer
16+
Public no
17+
Synthetic yes
18+
Lazy no
19+
Shared yes
20+
Abstract no
21+
Autowired no
22+
Autoconfigured no
23+
Required File /path/to/file
24+
Factory Service factory.service
25+
Factory Method get
26+
Usages .alias_2
27+
----------------- ------------------------------------------------
28+

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<parameter name="attr3">val3</parameter>
1515
</tag>
1616
<tag name="tag2"/>
17+
<tag name="tag3">
18+
<parameter name="array_attr">["foo","bar",[[[["ccc"]]]]]</parameter>
19+
</tag>
1720
</tags>
1821
<usages>
1922
<usage>.alias_2</usage>

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@
3333
{
3434
"name": "tag2",
3535
"parameters": []
36+
},
37+
{
38+
"name": "tag3",
39+
"parameters": {
40+
"array_attr": [
41+
"foo",
42+
"bar",
43+
[
44+
[
45+
[
46+
[
47+
"ccc"
48+
]
49+
]
50+
]
51+
]
52+
]
53+
}
3654
}
3755
],
3856
"usages": []

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Definitions
2525
- Tag: `tag1`
2626
- Attr3: val3
2727
- Tag: `tag2`
28+
- Tag: `tag3`
29+
- Array_attr: ["foo","bar",[[[["ccc"]]]]]
2830
- Usages: none
2931

3032
### .definition_3

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<parameter name="attr3">val3</parameter>
1616
</tag>
1717
<tag name="tag2"/>
18+
<tag name="tag3">
19+
<parameter name="array_attr">["foo","bar",[[[["ccc"]]]]]</parameter>
20+
</tag>
1821
</tags>
1922
</definition>
2023
<definition id=".definition_3" class="Full\Qualified\Class3" public="false" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" deprecated="false" file="/path/to/file">

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy