Skip to content

Commit 57b17f4

Browse files
committed
[FrameworkBundle] Fix debug:container --show-arguments missing cases
1 parent cc398db commit 57b17f4

13 files changed

+216
-10
lines changed

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected function describeContainerService($service, array $options = array(),
8686
if ($service instanceof Alias) {
8787
$this->describeContainerAlias($service, $options, $builder);
8888
} elseif ($service instanceof Definition) {
89-
$this->writeData($this->getContainerDefinitionData($service), $options);
89+
$this->writeData($this->getContainerDefinitionData($service, isset($options['omit_tags']) && $options['omit_tags'], isset($options['show_arguments']) && $options['show_arguments']), $options);
9090
} else {
9191
$this->writeData(get_class($service), $options);
9292
}
@@ -99,6 +99,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
9999
{
100100
$serviceIds = isset($options['tag']) && $options['tag'] ? array_keys($builder->findTaggedServiceIds($options['tag'])) : $builder->getServiceIds();
101101
$showPrivate = isset($options['show_private']) && $options['show_private'];
102+
$omitTags = isset($options['omit_tags']) && $options['omit_tags'];
102103
$showArguments = isset($options['show_arguments']) && $options['show_arguments'];
103104
$data = array('definitions' => array(), 'aliases' => array(), 'services' => array());
104105

@@ -109,7 +110,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
109110
$data['aliases'][$serviceId] = $this->getContainerAliasData($service);
110111
} elseif ($service instanceof Definition) {
111112
if (($showPrivate || $service->isPublic())) {
112-
$data['definitions'][$serviceId] = $this->getContainerDefinitionData($service, false, $showArguments);
113+
$data['definitions'][$serviceId] = $this->getContainerDefinitionData($service, $omitTags, $showArguments);
113114
}
114115
} else {
115116
$data['services'][$serviceId] = get_class($service);
@@ -124,7 +125,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
124125
*/
125126
protected function describeContainerDefinition(Definition $definition, array $options = array())
126127
{
127-
$this->writeData($this->getContainerDefinitionData($definition, isset($options['omit_tags']) && $options['omit_tags']), $options);
128+
$this->writeData($this->getContainerDefinitionData($definition, isset($options['omit_tags']) && $options['omit_tags'], isset($options['show_arguments']) && $options['show_arguments']), $options);
128129
}
129130

130131
/**
@@ -137,7 +138,7 @@ protected function describeContainerAlias(Alias $alias, array $options = array()
137138
}
138139

139140
$this->writeData(
140-
array($this->getContainerAliasData($alias), $this->getContainerDefinitionData($builder->getDefinition((string) $alias))),
141+
array($this->getContainerAliasData($alias), $this->getContainerDefinitionData($builder->getDefinition((string) $alias), isset($options['omit_tags']) && $options['omit_tags'], isset($options['show_arguments']) && $options['show_arguments'])),
141142
array_merge($options, array('id' => (string) $alias))
142143
);
143144
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected function describeContainerService($service, array $options = array(),
103103
throw new \InvalidArgumentException('An "id" option must be provided.');
104104
}
105105

106-
$childOptions = array('id' => $options['id'], 'as_array' => true);
106+
$childOptions = array_merge($options, array('id' => $options['id'], 'as_array' => true));
107107

108108
if ($service instanceof Alias) {
109109
$this->describeContainerAlias($service, $childOptions, $builder);

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

+18-2
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ protected function describeContainerDefinition(Definition $definition, array $op
255255
$tableRows[] = array('Service ID', isset($options['id']) ? $options['id'] : '-');
256256
$tableRows[] = array('Class', $definition->getClass() ?: '-');
257257

258-
$tags = $definition->getTags();
259-
if (count($tags)) {
258+
$omitTags = isset($options['omit_tags']) && $options['omit_tags'];
259+
if (!$omitTags && ($tags = $definition->getTags())) {
260260
$tagInformation = array();
261261
foreach ($tags as $tagName => $tagData) {
262262
foreach ($tagData as $tagParameters) {
@@ -327,6 +327,22 @@ protected function describeContainerDefinition(Definition $definition, array $op
327327
}
328328
}
329329

330+
$showArguments = isset($options['show_arguments']) && $options['show_arguments'];
331+
$argumentsInformation = array();
332+
if ($showArguments && ($arguments = $definition->getArguments())) {
333+
foreach ($arguments as $argument) {
334+
if ($argument instanceof Reference) {
335+
$argumentsInformation[] = sprintf('Service(%s)', (string) $argument);
336+
} elseif ($argument instanceof Definition) {
337+
$argumentsInformation[] = 'Inlined Service';
338+
} else {
339+
$argumentsInformation[] = $argument;
340+
}
341+
}
342+
343+
$tableRows[] = array('Arguments', implode("\n", $argumentsInformation));
344+
}
345+
330346
$options['output']->table($tableHeaders, $tableRows);
331347
}
332348

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function describeContainerService($service, array $options = array(),
6868
throw new \InvalidArgumentException('An "id" option must be provided.');
6969
}
7070

71-
$this->writeDocument($this->getContainerServiceDocument($service, $options['id'], $builder));
71+
$this->writeDocument($this->getContainerServiceDocument($service, $options['id'], $builder, isset($options['show_arguments']) && $options['show_arguments']));
7272
}
7373

7474
/**
@@ -84,7 +84,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
8484
*/
8585
protected function describeContainerDefinition(Definition $definition, array $options = array())
8686
{
87-
$this->writeDocument($this->getContainerDefinitionDocument($definition, isset($options['id']) ? $options['id'] : null, isset($options['omit_tags']) && $options['omit_tags']));
87+
$this->writeDocument($this->getContainerDefinitionDocument($definition, isset($options['id']) ? $options['id'] : null, isset($options['omit_tags']) && $options['omit_tags'], isset($options['show_arguments']) && $options['show_arguments']));
8888
}
8989

9090
/**
@@ -284,7 +284,7 @@ private function getContainerServiceDocument($service, $id, ContainerBuilder $bu
284284
if ($service instanceof Alias) {
285285
$dom->appendChild($dom->importNode($this->getContainerAliasDocument($service, $id)->childNodes->item(0), true));
286286
if ($builder) {
287-
$dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($builder->getDefinition((string) $service), (string) $service)->childNodes->item(0), true));
287+
$dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($builder->getDefinition((string) $service), (string) $service, false, $showArguments)->childNodes->item(0), true));
288288
}
289289
} elseif ($service instanceof Definition) {
290290
$dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($service, $id, false, $showArguments)->childNodes->item(0), true));

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

+18
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ public function getDescribeContainerDefinitionTestData()
7979
return $this->getDescriptionTestData(ObjectsProvider::getContainerDefinitions());
8080
}
8181

82+
/** @dataProvider getDescribeContainerDefinitionWithArgumentsShownTestData */
83+
public function testDescribeContainerDefinitionWithArgumentsShown(Definition $definition, $expectedDescription)
84+
{
85+
$this->assertDescription($expectedDescription, $definition, array('show_arguments' => true));
86+
}
87+
88+
public function getDescribeContainerDefinitionWithArgumentsShownTestData()
89+
{
90+
$definitions = ObjectsProvider::getContainerDefinitions();
91+
$definitionsWithArgs = array();
92+
93+
foreach ($definitions as $key => $definition) {
94+
$definitionsWithArgs[str_replace('definition_', 'definition_arguments_', $key)] = $definition;
95+
}
96+
97+
return $this->getDescriptionTestData($definitionsWithArgs);
98+
}
99+
82100
/** @dataProvider getDescribeContainerAliasTestData */
83101
public function testDescribeContainerAlias(Alias $alias, $expectedDescription)
84102
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"class": "Full\\Qualified\\Class1",
3+
"public": true,
4+
"synthetic": false,
5+
"lazy": true,
6+
"shared": true,
7+
"abstract": true,
8+
"autowire": false,
9+
"autowiring_types": [],
10+
"arguments": [
11+
{
12+
"type": "service",
13+
"id": "definition2"
14+
},
15+
"%parameter%",
16+
{
17+
"class": "inline_service",
18+
"public": true,
19+
"synthetic": false,
20+
"lazy": false,
21+
"shared": true,
22+
"abstract": false,
23+
"autowire": false,
24+
"autowiring_types": [],
25+
"arguments": [
26+
"arg1",
27+
"arg2"
28+
],
29+
"file": null,
30+
"tags": []
31+
}
32+
],
33+
"file": null,
34+
"factory_class": "Full\\Qualified\\FactoryClass",
35+
"factory_method": "get",
36+
"tags": []
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- Class: `Full\Qualified\Class1`
2+
- Public: yes
3+
- Synthetic: no
4+
- Lazy: yes
5+
- Shared: yes
6+
- Abstract: yes
7+
- Autowired: no
8+
- Arguments: yes
9+
- Factory Class: `Full\Qualified\FactoryClass`
10+
- Factory Method: `get`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
------------------ -----------------------------
2+
 Option   Value 
3+
------------------ -----------------------------
4+
Service ID -
5+
Class Full\Qualified\Class1
6+
Tags -
7+
Public yes
8+
Synthetic no
9+
Lazy yes
10+
Shared yes
11+
Abstract yes
12+
Autowired no
13+
Autowiring Types -
14+
Factory Class Full\Qualified\FactoryClass
15+
Factory Method get
16+
Arguments Service(definition2)
17+
%parameter%
18+
Inlined Service
19+
------------------ -----------------------------
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definition class="Full\Qualified\Class1" public="true" synthetic="false" lazy="true" shared="true" abstract="true" autowired="false" file="">
3+
<factory class="Full\Qualified\FactoryClass" method="get"/>
4+
<argument type="service" id="definition2"/>
5+
<argument>%parameter%</argument>
6+
<argument>
7+
<definition class="inline_service" public="true" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" file="">
8+
<argument>arg1</argument>
9+
<argument>arg2</argument>
10+
</definition>
11+
</argument>
12+
</definition>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"class": "Full\\Qualified\\Class2",
3+
"public": false,
4+
"synthetic": true,
5+
"lazy": false,
6+
"shared": true,
7+
"abstract": false,
8+
"autowire": false,
9+
"autowiring_types": [],
10+
"arguments": [],
11+
"file": "\/path\/to\/file",
12+
"factory_service": "factory.service",
13+
"factory_method": "get",
14+
"calls": [
15+
"setMailer"
16+
],
17+
"tags": [
18+
{
19+
"name": "tag1",
20+
"parameters": {
21+
"attr1": "val1",
22+
"attr2": "val2"
23+
}
24+
},
25+
{
26+
"name": "tag1",
27+
"parameters": {
28+
"attr3": "val3"
29+
}
30+
},
31+
{
32+
"name": "tag2",
33+
"parameters": []
34+
}
35+
]
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
- Class: `Full\Qualified\Class2`
2+
- Public: no
3+
- Synthetic: yes
4+
- Lazy: no
5+
- Shared: yes
6+
- Abstract: no
7+
- Autowired: no
8+
- Arguments: no
9+
- File: `/path/to/file`
10+
- Factory Service: `factory.service`
11+
- Factory Method: `get`
12+
- Call: `setMailer`
13+
- Tag: `tag1`
14+
- Attr1: val1
15+
- Attr2: val2
16+
- Tag: `tag1`
17+
- Attr3: val3
18+
- Tag: `tag2`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
------------------ ---------------------------------
2+
 Option   Value 
3+
------------------ ---------------------------------
4+
Service ID -
5+
Class Full\Qualified\Class2
6+
Tags tag1 (attr1: val1, attr2: val2)
7+
tag1 (attr3: val3)
8+
tag2
9+
Calls setMailer
10+
Public no
11+
Synthetic yes
12+
Lazy no
13+
Shared yes
14+
Abstract no
15+
Autowired no
16+
Autowiring Types -
17+
Required File /path/to/file
18+
Factory Service factory.service
19+
Factory Method get
20+
------------------ ---------------------------------
21+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definition class="Full\Qualified\Class2" public="false" synthetic="true" lazy="false" shared="true" abstract="false" autowired="false" file="/path/to/file">
3+
<factory service="factory.service" method="get"/>
4+
<calls>
5+
<call method="setMailer"/>
6+
</calls>
7+
<tags>
8+
<tag name="tag1">
9+
<parameter name="attr1">val1</parameter>
10+
<parameter name="attr2">val2</parameter>
11+
</tag>
12+
<tag name="tag1">
13+
<parameter name="attr3">val3</parameter>
14+
</tag>
15+
<tag name="tag2"/>
16+
</tags>
17+
</definition>

0 commit comments

Comments
 (0)