Skip to content

Commit 05e190e

Browse files
committed
[DI][FrameworkBundle] ServiceLocator: Tests dumpers & update descriptors
1 parent ee4fd51 commit 05e190e

File tree

8 files changed

+50
-6
lines changed

8 files changed

+50
-6
lines changed

Console/Descriptor/TextDescriptor.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\DependencyInjection\Alias;
1717
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
1818
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
19+
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
1920
use Symfony\Component\DependencyInjection\ContainerBuilder;
2021
use Symfony\Component\DependencyInjection\Definition;
2122
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -328,12 +329,14 @@ protected function describeContainerDefinition(Definition $definition, array $op
328329
} elseif ($argument instanceof Definition) {
329330
$argumentsInformation[] = 'Inlined Service';
330331
} elseif ($argument instanceof IteratorArgument) {
331-
$argumentsInformation[] = 'Iterator';
332+
$argumentsInformation[] = sprintf('Iterator (%d element(s))', count($argument->getValues()));
333+
} elseif ($argument instanceof ServiceLocatorArgument) {
334+
$argumentsInformation[] = sprintf('ServiceLocator (%d service(s))', count($argument->getValues()));
332335
} elseif ($argument instanceof ClosureProxyArgument) {
333336
list($reference, $method) = $argument->getValues();
334337
$argumentsInformation[] = sprintf('ClosureProxy(Service(%s)::%s())', $reference, $method);
335338
} else {
336-
$argumentsInformation[] = is_array($argument) ? 'Array' : $argument;
339+
$argumentsInformation[] = is_array($argument) ? sprintf('Array (%d element(s))', count($argument)) : $argument;
337340
}
338341
}
339342

Console/Descriptor/XmlDescriptor.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\DependencyInjection\Alias;
1515
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
1616
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
17+
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
1819
use Symfony\Component\DependencyInjection\Definition;
1920
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -432,6 +433,12 @@ private function getArgumentNodes(array $arguments, \DOMDocument $dom)
432433
} elseif ($argument instanceof IteratorArgument) {
433434
$argumentXML->setAttribute('type', 'iterator');
434435

436+
foreach ($this->getArgumentNodes($argument->getValues(), $dom) as $childArgumentXML) {
437+
$argumentXML->appendChild($childArgumentXML);
438+
}
439+
} elseif ($argument instanceof ServiceLocatorArgument) {
440+
$argumentXML->setAttribute('type', 'service_locator');
441+
435442
foreach ($this->getArgumentNodes($argument->getValues(), $dom) as $childArgumentXML) {
436443
$argumentXML->appendChild($childArgumentXML);
437444
}

Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\DependencyInjection\Alias;
1515
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
1616
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
17+
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
1819
use Symfony\Component\DependencyInjection\Definition;
1920
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -120,6 +121,10 @@ public static function getContainerDefinitions()
120121
new Reference('definition_2'),
121122
)))
122123
->addArgument(new ClosureProxyArgument('definition1', 'get'))
124+
->addArgument(new ServiceLocatorArgument(array(
125+
'def1' => new Reference('definition_1'),
126+
'def2' => new Reference('definition_2'),
127+
)))
123128
->setFactory(array('Full\\Qualified\\FactoryClass', 'get')),
124129
'definition_2' => $definition2
125130
->setPublic(false)

Tests/Fixtures/Descriptor/builder_1_arguments.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,17 @@
6464
"id": "definition1"
6565
},
6666
"get"
67-
]
67+
],
68+
{
69+
"def1": {
70+
"type": "service",
71+
"id": "definition_1"
72+
},
73+
"def2": {
74+
"type": "service",
75+
"id": "definition_2"
76+
}
77+
}
6878
],
6979
"file": null,
7080
"factory_class": "Full\\Qualified\\FactoryClass",

Tests/Fixtures/Descriptor/builder_1_arguments.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
<argument type="service" id="definition_2"/>
2525
</argument>
2626
<argument type="closure-proxy" id="definition1" method="get"/>
27+
<argument type="service_locator">
28+
<argument key="def1" type="service" id="definition_1"/>
29+
<argument key="def2" type="service" id="definition_2"/>
30+
</argument>
2731
</definition>
2832
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>
2933
</container>

Tests/Fixtures/Descriptor/definition_arguments_1.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,17 @@
6262
"id": "definition1"
6363
},
6464
"get"
65-
]
65+
],
66+
{
67+
"def1": {
68+
"type": "service",
69+
"id": "definition_1"
70+
},
71+
"def2": {
72+
"type": "service",
73+
"id": "definition_2"
74+
}
75+
}
6676
],
6777
"file": null,
6878
"factory_class": "Full\\Qualified\\FactoryClass",

Tests/Fixtures/Descriptor/definition_arguments_1.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
Arguments Service(definition2)
1616
%parameter%
1717
Inlined Service
18-
Array
19-
Iterator
18+
Array (3 element(s))
19+
Iterator (2 element(s))
2020
ClosureProxy(Service(definition1)::get())
21+
ServiceLocator (2 service(s))
2122
---------------- -------------------------------------------
2223

Tests/Fixtures/Descriptor/definition_arguments_1.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@
2121
<argument type="service" id="definition_2"/>
2222
</argument>
2323
<argument type="closure-proxy" id="definition1" method="get"/>
24+
<argument type="service_locator">
25+
<argument key="def1" type="service" id="definition_1"/>
26+
<argument key="def2" type="service" id="definition_2"/>
27+
</argument>
2428
</definition>

0 commit comments

Comments
 (0)