8000 minor #21499 [FrameworkBundle][Console] Fix descriptors to support It… · symfony/symfony@a46e691 · GitHub
[go: up one dir, main page]

Skip to content

Commit a46e691

Browse files
committed
minor #21499 [FrameworkBundle][Console] Fix descriptors to support IteratorArgument, ClosureProxy and arrays (ogizanagi)
This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle][Console] Fix descriptors to support IteratorArgument, ClosureProxy and arrays | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A Fixes both array and iterator/closure-proxy arguments support in descriptors when using `--show-arguments` Commits ------- a94924c [FrameworkBundle][Console] Fix descriptors to support IteratorArgument, ClosureProxy and arrays
2 parents 2e13d4e + a94924c commit a46e691

File tree

9 files changed

+183
-35
lines changed

9 files changed

+183
-35
lines changed

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

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
1313

1414
use Symfony\Component\DependencyInjection\Alias;
15+
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Definition;
1718
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -227,20 +228,7 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
227228
}
228229

229230
if ($showArguments) {
230-
$data['arguments'] = array();
231-
232-
foreach ($definition->getArguments() as $argument) {
233-
if ($argument instanceof Reference) {
234-
$data['arguments'][] = array(
235-
'type' => 'service',
236-
'id' => (string) $argument,
237-
);
238-
} elseif ($argument instanceof Definition) {
239-
$data['arguments'][] = $this->getContainerDefinitionData($argument, $omitTags, $showArguments);
240-
} else {
241-
$data['arguments'][] = $argument;
242-
}
243-
}
231+
$data['arguments'] = $this->describeValue($definition->getArguments(), $omitTags, $showArguments);
244232
}
245233

246234
$data['file'] = $definition->getFile();
@@ -388,4 +376,33 @@ private function getCallableData($callable, array $options = array())
388376

389377
throw new \InvalidArgumentException('Callable is not describable.');
390378
}
379+
380+
private function describeValue($value, $omitTags, $showArguments)
381+
{
382+
if (is_array($value)) {
383+
$data = array();
384+
foreach ($value as $k => $v) {
385+
$data[$k] = $this->describeValue($v, $omitTags, $showArguments);
386+
}
387+
388+
return $data;
389+
}
390+
391+
if ($value instanceof Reference) {
392+
return array(
393+
'type' => 'service',
394+
'id' => (string) $value,
395+
);
396+
}
397+
398+
if ($value instanceof Definition) {
399+
return $this->getContainerDefinitionData($value, $omitTags, $showArguments);
400+
}
401+
402+
if ($value instanceof ArgumentInterface) {
403+
return $this->describeValue($value->getValues(), $omitTags, $showArguments);
404+
}
405+
406+
return $value;
407+
}
391408
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\Console\Helper\Table;
1515
use Symfony\Component\Console\Style\SymfonyStyle;
1616
use Symfony\Component\DependencyInjection\Alias;
17+
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
18+
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1719
use Symfony\Component\DependencyInjection\ContainerBuilder;
1820
use Symfony\Component\DependencyInjection\Definition;
1921
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -325,8 +327,13 @@ protected function describeContainerDefinition(Definition $definition, array $op
325327
$argumentsInformation[] = sprintf('Service(%s)', (string) $argument);
326328
} elseif ($argument instanceof Definition) {
327329
$argumentsInformation[] = 'Inlined Service';
330+
} elseif ($argument instanceof IteratorArgument) {
331+
$argumentsInformation[] = 'Iterator';
332+
} elseif ($argument instanceof ClosureProxyArgument) {
333+
list($reference, $method) = $argument->getValues();
334+
$argumentsInformation[] = sprintf('ClosureProxy(Service(%s)::%s())', $reference, $method);
328335
} else {
329-
$argumentsInformation[] = $argument;
336+
$argumentsInformation[] = is_array($argument) ? 'Array' : $argument;
330337
}
331338
}
332339

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
1313

1414
use Symfony\Component\DependencyInjection\Alias;
15+
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
16+
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1517
use Symfony\Component\DependencyInjection\ContainerBuilder;
1618
use Symfony\Component\DependencyInjection\Definition;
1719
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -427,6 +429,17 @@ private function getArgumentNodes(array $arguments, \DOMDocument $dom)
427429
$argumentXML->setAttribute('id', (string) $argument);
428430
} elseif ($argument instanceof Definition) {
429431
$argumentXML->appendChild($dom->importNode($this->getContainerDefinitionDocument($argument, null, false, true)->childNodes->item(0), true));
432+
} elseif ($argument instanceof IteratorArgument) {
433+
$argumentXML->setAttribute('type', 'iterator');
434+
435+
foreach ($this->getArgumentNodes($argument->getValues(), $dom) as $childArgumentXML) {
436+
$argumentXML->appendChild($childArgumentXML);
437+
}
438+
} elseif ($argument instanceof ClosureProxyArgument) {
439+
list($reference, $method) = $argument->getValues();
440+
$argumentXML->setAttribute('type', 'closure-proxy');
441+
$argumentXML->setAttribute('id', (string) $reference);
442+
$argumentXML->setAttribute('method', $method);
430443
} elseif (is_array($argument)) {
431444
$argumentXML->setAttribute('type', 'collection');
432445

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;
1313

1414
use Symfony\Component\DependencyInjection\Alias;
15+
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
16+
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1517
use Symfony\Component\DependencyInjection\ContainerBuilder;
1618
use Symfony\Component\DependencyInjection\Definition;
1719
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -108,6 +110,16 @@ public static function getContainerDefinitions()
108110
->addArgument(new Reference('definition2'))
109111
->addArgument('%parameter%')
110112
->addArgument(new Definition('inline_service', array('arg1', 'arg2')))
113+
->addArgument(array(
114+
'foo',
115+
new Reference('definition2'),
116+
new Definition('inline_service'),
117+
))
118+
->addArgument(new IteratorArgument(array(
119+
new Reference('definition_1'),
120+
new Reference('definition_2'),
121+
)))
122+
->addArgument(new ClosureProxyArgument('definition1', 'get'))
111123
->setFactory(array('Full\\Qualified\\FactoryClass', 'get')),
112124
'definition_2' => $definition2
113125
->setPublic(false)

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,43 @@
3434
],
3535
"file": null,
3636
"tags": []
37-
}
37+
},
38+
[
39+
"foo",
40+
{
41+
"type": "service",
42+
"id": "definition2"
43+
},
44+
{
45+
"class": "inline_service",
46+
"public": true,
47+
"synthetic": false,
48+
"lazy": false,
49+
"shared": true,
50+
"abstract": false,
51+
"autowire": false,
52+
"arguments": [],
53+
"file": null,
54+
"tags": []
55+
}
56+
],
57+
[
58+
{
59+
"type": "service",
60+
"id": "definition_1"
61+
},
62+
{
63+
"type": "service",
64+
"id": "definition_2"
65+
}
66+
],
67+
[
68+
{
69+
"type": "service",
70+
"id": "definition1"
71+
},
72+
"get"
73+
]
3874
]
3975
}
4076
},

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
<argument>arg2</argument>
1313
</definition>
1414
</argument>
15+
<argument type="collection">
16+
<argument>foo</argument>
17+
<argument type="service" id="definition2"/>
18+
<argument>
19+
<definition class="inline_service" public="true" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" file=""/>
20+
</argument>
21+
</argument>
22+
<argument type="iterator">
23+
<argument type="service" id="definition_1"/>
24+
<argument type="service" id="definition_2"/>
25+
</argument>
26+
<argument type="closure-proxy" id="definition1" method="get"/>
1527
</definition>
1628
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>
1729
</container>

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,43 @@
2626
],
2727
"file": null,
2828
"tags": []
29-
}
29+
},
30+
[
31+
"foo",
32+
{
33+
"type": "service",
34+
"id": "definition2"
35+
},
36+
{
37+
"class": "inline_service",
38+
"public": true,
39+
"synthetic": false,
40+
"lazy": false,
41+
"shared": true,
42+
"abstract": false,
43+
"autowire": false,
44+
"arguments": [],
45+
"file": null,
46+
"tags": []
47+
}
48+
],
49+
[
50+
{
51+
"type": "service",
52+
"id": "definition_1"
53+
},
54+
{
55+
"type": "service",
56+
"id": "definition_2"
57+
}
58+
],
59+
[
60+
{
61+
"type": "service",
62+
"id": "definition1"
63+
},
64+
"get"
65+
]
3066
],
3167
"file": null,
3268
"factory_class": "Full\\Qualified\\FactoryClass",
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
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-
Factory Class Full\Qualified\FactoryClass
14-
Factory Method get
15-
Arguments Service(definition2)
16-
%parameter%
17-
Inlined Service
18-
---------------- -----------------------------
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+
Factory Class Full\Qualified\FactoryClass
14+
Factory Method get
15+
Arguments Service(definition2)
16+
%parameter%
17+
Inlined Service
18+
Array
19+
Iterator
20+
ClosureProxy(Service(definition1)::get())
21+
---------------- -------------------------------------------
1922

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,16 @@
99
<argument>arg2</argument>
1010
</definition>
1111
</argument>
12+
<argument type="collection">
13+
<argument>foo</argument>
14+
<argument type="service" id="definition2"/>
15+
<argument>
16+
<definition class="inline_service" public="true" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" file=""/>
17+
</argument>
18+
</argument>
19+
<argument type="iterator">
20+
<argument type="service" id="definition_1"/>
21+
<argument type="service" id="definition_2"/>
22+
</argument>
23+
<argument type="closure-proxy" id="definition1" method="get"/>
1224
</definition>

0 commit comments

Comments
 (0)
0