Skip to content

[FrameworkBundle] Handle tags array attributes in descriptors #51669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
foreach ($tagData as $parameters) {
$output .= "\n".'- Tag: `'.$tagName.'`';
foreach ($parameters as $name => $value) {
$output .= "\n".' - '.ucfirst($name).': '.$value;
$output .= "\n".' - '.ucfirst($name).': '.(\is_array($value) ? $this->formatParameter($value) : $value);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't do a simple explode because we allow array of array of array etc. So I think it's alright to reuse the formatParameter method (see tests for example output).

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ protected function describeContainerServices(ContainerBuilder $container, array
if (!isset($maxTags[$key])) {
$maxTags[$key] = \strlen($key);
}
if (\is_array($value)) {
$value = $this->formatParameter($value);
}

if (\strlen($value) > $maxTags[$key]) {
$maxTags[$key] = \strlen($value);
}
Expand All @@ -233,7 +237,11 @@ protected function describeContainerServices(ContainerBuilder $container, array
foreach ($this->sortByPriority($definition->getTag($showTag)) as $key => $tag) {
$tagValues = [];
foreach ($tagsNames as $tagName) {
$tagValues[] = $tag[$tagName] ?? '';
if (\is_array($tagValue = $tag[$tagName] ?? '')) {
$tagValue = $this->formatParameter($tagValue);
}

$tagValues[] = $tagValue;
}
if (0 === $key) {
$tableRows[] = array_merge([$serviceId], $tagValues, [$definition->getClass()]);
Expand Down Expand Up @@ -275,7 +283,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
$tagInformation = [];
foreach ($tags as $tagName => $tagData) {
foreach ($tagData as $tagParameters) {
$parameters = array_map(fn ($key, $value) => sprintf('<info>%s</info>: %s', $key, $value), array_keys($tagParameters), array_values($tagParameters));
$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));
$parameters = implode(', ', $parameters);

if ('' === $parameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public static function getContainerDefinitions()
->addTag('tag1', ['attr1' => 'val1', 'attr2' => 'val2'])
->addTag('tag1', ['attr3' => 'val3'])
->addTag('tag2')
->addTag('tag3', ['array_attr' => ['foo', 'bar', [[[['ccc']]]]]])
->addMethodCall('setMailer', [new Reference('mailer')])
->setFactory([new Reference('factory.service'), 'get']),
'.definition_3' => $definition3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@
{
"name": "tag2",
"parameters": []
},
{
"name": "tag3",
"parameters": {
"array_attr": [
"foo",
"bar",
[
[
[
[
"ccc"
]
]
]
]
]
}
}
],
"usages": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@
- Tag: `tag1`
- Attr3: val3
- Tag: `tag2`
- Tag: `tag3`
- Array_attr: ["foo","bar",[[[["ccc"]]]]]
- Usages: .alias_2
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
Information for Service ".service_2"
====================================

----------------- ---------------------------------
 Option   Value 
----------------- ---------------------------------
Service ID .service_2
Class Full\Qualified\Class2
Tags tag1 (attr1: val1, attr2: val2)
tag1 (attr3: val3)
tag2
Calls setMailer
Public no
Synthetic yes
Lazy no
Shared yes
Abstract no
Autowired no
Autoconfigured no
Required File /path/to/file
Factory Service factory.service
Factory Method get
Usages .alias_2
----------------- ---------------------------------
----------------- ------------------------------------------------
 Option   Value 
----------------- ------------------------------------------------
Service ID .service_2
Class Full\Qualified\Class2
Tags tag1 (attr1: val1, attr2: val2)
tag1 (attr3: val3)
tag2
tag3 (array_attr: ["foo","bar",[[[["ccc"]]]]])
Calls setMailer
Public no
Synthetic yes
Lazy no
Shared yes
Abstract no
Autowired no
Autoconfigured no
Required File /path/to/file
Factory Service factory.service
Factory Method get
Usages .alias_2
----------------- ------------------------------------------------

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<parameter name="attr3">val3</parameter>
</tag>
<tag name="tag2"/>
<tag name="tag3">
<parameter name="array_attr">["foo","bar",[[[["ccc"]]]]]</parameter>
</tag>
</tags>
<usages>
<usage>.alias_2</usage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@
{
"name": "tag2",
"parameters": []
},
{
"name": "tag3",
"parameters": {
"array_attr": [
"foo",
"bar",
[
[
[
[
"ccc"
]
]
]
]
]
}
}
],
"usages": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Definitions
- Tag: `tag1`
- Attr3: val3
- Tag: `tag2`
- Tag: `tag3`
- Array_attr: ["foo","bar",[[[["ccc"]]]]]
- Usages: none

### .definition_3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<parameter name="attr3">val3</parameter>
</tag>
<tag name="tag2"/>
<tag name="tag3">
<parameter name="array_attr">["foo","bar",[[[["ccc"]]]]]</parameter>
</tag>
</tags>
</definition>
<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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@
{
"name": "tag2",
"parameters": []
},
{
"name": "tag3",
"parameters": {
"array_attr": [
"foo",
"bar",
[
[
[
[
"ccc"
]
]
]
]
]
}
}
],
"usages": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ Definitions
- Tag: `tag1`
- Attr3: val3
- Tag: `tag2`
- Tag: `tag3`
- Array_attr: ["foo","bar",[[[["ccc"]]]]]
- Usages: none
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<parameter name="attr3">val3</parameter>
</tag>
<tag name="tag2"/>
<tag name="tag3">
<parameter name="array_attr">["foo","bar",[[[["ccc"]]]]]</parameter>
</tag>
</tags>
</definition>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,25 @@
],
"usages": []
}
],
"tag3": [
{
"class": "Full\\Qualified\\Class2",
"public": false,
"synthetic": true,
"lazy": false,
"shared": true,
"abstract": false,
"autowire": false,
"autoconfigure": false,
"deprecated": false,
"file": "\/path\/to\/file",
"factory_service": "factory.service",
"factory_method": "get",
"calls": [
"setMailer"
],
"usages": []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,24 @@ tag2
- Factory Method: `get`
- Call: `setMailer`
- Usages: none


tag3
----

### .definition_2

- Class: `Full\Qualified\Class2`
- Public: no
- Synthetic: yes
- Lazy: no
- Shared: yes
- Abstract: no
- Autowired: no
- Autoconfigured: no
- Deprecated: no
- File: `/path/to/file`
- Factory Service: `factory.service`
- Factory Method: `get`
- Call: `setMailer`
- Usages: none
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@

* .definition_2

"tag3" tag
----------

* .definition_2

Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@
</calls>
</definition>
</tag>
<tag name="tag3">
<definition id=".definition_2" class="Full\Qualified\Class2" public="false" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" deprecated="false" file="/path/to/file">
<factory service="factory.service" method="get"/>
<calls>
<call method="setMailer"/>
</calls>
</definition>
</tag>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@
{
"name": "tag2",
"parameters": []
},
{
"name": "tag3",
"parameters": {
"array_attr": [
"foo",
"bar",
[
[
[
[
"ccc"
]
]
]
]
]
}
}
],
"usages": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
- Tag: `tag1`
- Attr3: val3
- Tag: `tag2`
- Tag: `tag3`
- Array_attr: ["foo","bar",[[[["ccc"]]]]]
- Usages: none
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
----------------- ---------------------------------
 Option   Value 
----------------- ---------------------------------
Service ID -
Class Full\Qualified\Class2
Tags tag1 (attr1: val1, attr2: val2)
tag1 (attr3: val3)
tag2
Calls setMailer
Public no
Synthetic yes
Lazy no
Shared yes
Abstract no
Autowired no
Autoconfigured no
Required File /path/to/file
Factory Service factory.service
Factory Method get
Usages none
----------------- ---------------------------------
----------------- ------------------------------------------------
 Option   Value 
----------------- ------------------------------------------------
Service ID -
Class Full\Qualified\Class2
Tags tag1 (attr1: val1, attr2: val2)
tag1 (attr3: val3)
tag2
tag3 (array_attr: ["foo","bar",[[[["ccc"]]]]])
Calls setMailer
Public no
Synthetic yes
Lazy no
Shared yes
Abstract no
Autowired no
Autoconfigured no
Required File /path/to/file
Factory Service factory.service
Factory Method get
Usages none
----------------- ------------------------------------------------

Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
<parameter name="attr3">val3</parameter>
</tag>
<tag name="tag2"/>
<tag name="tag3">
<parameter name="array_attr">["foo","bar",[[[["ccc"]]]]]</parameter>
</tag>
</tags>
</definition>
Loading
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