Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0976c86

Browse files
committed
minor #21600 [DI][FrameworkBundle] ServiceLocator: Tests dumpers & update descriptors (ogizanagi)
This PR was merged into the 3.3-dev branch. Discussion ---------- [DI][FrameworkBundle] ServiceLocator: Tests dumpers & update descriptors | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | no | Fixed tickets | N/A | License | MIT | Doc PR | N/A This simply ensures the new feature is properly considered by the different dumpers, and updates the console descriptors to support the new `ServiceLocatorArgument`. I also added the number of elements in an array/iterator/service_locator argument when using the `TextDescriptor` in this PR. (fabbot is complaining about the new yaml tags support) Commits ------- aa9074d [DI][FrameworkBundle] ServiceLocator: Tests dumpers & update descriptors
2 parents 00d20ea + aa9074d commit 0976c86

30 files changed

+126
-24
lines changed

src/Symfony/Bundle/FrameworkBundle/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

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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)

src/Symfony/Bundle/FrameworkBundle/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",

src/Symfony/Bundle/FrameworkBundle/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>

src/Symfony/Bundle/FrameworkBundle/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",

src/Symfony/Bundle/FrameworkBundle/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

src/Symfony/Bundle/FrameworkBundle/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>

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,8 +898,8 @@ private function startClass($class, $baseClass, $namespace)
898898
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
899899
use Symfony\Component\DependencyInjection\Exception\LogicException;
900900
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
901-
use Symfony\Component\DependencyInjection\ServiceLocator;
902901
$bagClass
902+
use Symfony\Component\DependencyInjection\ServiceLocator;
903903
904904
/*{$this->docStar}
905905
* $class.

src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
77
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
8+
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
89
use Symfony\Component\DependencyInjection\ContainerInterface;
910
use Symfony\Component\DependencyInjection\ContainerBuilder;
1011
use Symfony\Component\DependencyInjection\Reference;
@@ -144,5 +145,13 @@
144145
->register('closure_proxy', 'BarClass')
145146
->setArguments(array(new ClosureProxyArgument('closure_proxy', 'getBaz')))
146147
;
148+
$container
149+
->register('service_locator', 'Bar')
150+
->setArguments(array(new ServiceLocatorArgument(array(
151+
'bar' => new Reference('bar'),
152+
'invalid' => new Reference('invalid', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
153+
'container' => new Reference('service_container'),
154+
))))
155+
;
147156

148157
return $container;

src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ digraph sc {
2929
node_lazy_context [label="lazy_context\nLazyContext\n", shape=record, fillcolor="#eeeeee", style="filled"];
3030
node_lazy_context_ignore_invalid_ref [label="lazy_context_ignore_invalid_ref\nLazyContext\n", shape=record, fillcolor="#eeeeee", style="filled"];
3131
node_closure_proxy [label="closure_proxy\nBarClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
32+
node_service_locator [label="service_locator\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
3233
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
3334
node_foo2 [label="foo2\n\n", shape=record, fillcolor="#ff9999", style="filled"];
3435
node_foo3 [label="foo3\n\n", shape=record, fillcolor="#ff9999", style="filled"];
@@ -52,4 +53,7 @@ digraph sc {
5253
node_lazy_context_ignore_invalid_ref -> node_foo_baz [label="" style="filled" color="#9999ff"];
5354
node_lazy_context_ignore_invalid_ref -> node_invalid [label="" style="filled" color="#9999ff"];
5455
node_closure_proxy -> node_closure_proxy [label="" style="filled" color="#9999ff"];
56+
node_service_locator -> node_bar [label="" style="filled" color="#9999ff"];
57+
node_service_locator -> node_invalid [label="" style="filled" color="#9999ff"];
58+
node_service_locator -> node_service_container [label="" style="filled" color="#9999ff"];
5559
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
88
use Symfony\Component\DependencyInjection\Exception\LogicException;
99
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
10-
use Symfony\Component\DependencyInjection\ServiceLocator;
1110
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
11+
use Symfony\Component\DependencyInjection\ServiceLocator;
1212

1313
/**
1414
* Container.

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
77
use Symfony\Component\DependencyInjection\Exception\LogicException;
88
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9-
use Symfony\Component\DependencyInjection\ServiceLocator;
109
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ServiceLocator;
1111

1212
/**
1313
* ProjectServiceContainer.

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
77
use Symfony\Component\DependencyInjection\Exception\LogicException;
88
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9-
use Symfony\Component\DependencyInjection\ServiceLocator;
109
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ServiceLocator;
1111

1212
/**
1313
* ProjectServiceContainer.

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
77
use Symfony\Component\DependencyInjection\Exception\LogicException;
88
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9-
use Symfony\Component\DependencyInjection\ServiceLocator;
109
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ServiceLocator;
1111

1212
/**
1313
* ProjectServiceContainer.

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
77
use Symfony\Component\DependencyInjection\Exception\LogicException;
88
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9-
use Symfony\Component\DependencyInjection\ServiceLocator;
109
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ServiceLocator;
1111

1212
/**
1313
* ProjectServiceContainer.

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
77
use Symfony\Component\DependencyInjection\Exception\LogicException;
88
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9-
use Symfony\Component\DependencyInjection\ServiceLocator;
109
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ServiceLocator;
1111

1212
/**
1313
* ProjectServiceContainer.

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
77
use Symfony\Component\DependencyInjection\Exception\LogicException;
88
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9-
use Symfony\Component\DependencyInjection\ServiceLocator;
109
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ServiceLocator;
1111

1212
/**
1313
* ProjectServiceContainer.

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
77
use Symfony\Component\DependencyInjection\Exception\LogicException;
88
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9-
use Symfony\Component\DependencyInjection\ServiceLocator;
109
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ServiceLocator;
1111

1212
/**
1313
* ProjectServiceContainer.

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services29.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
77
use Symfony\Component\DependencyInjection\Exception\LogicException;
88
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9-
use Symfony\Component\DependencyInjection\ServiceLocator;
109
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ServiceLocator;
1111

1212
/**
1313
* Symfony_DI_PhpDumper_Test_Overriden_Getters.

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services31.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
77
use Symfony\Component\DependencyInjection\Exception\LogicException;
88
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9-
use Symfony\Component\DependencyInjection\ServiceLocator;
109
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ServiceLocator;
1111

1212
/**
1313
* ProjectServiceContainer.

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services32.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
77
use Symfony\Component\DependencyInjection\Exception\LogicException;
88
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9-
use Symfony\Component\DependencyInjection\ServiceLocator;
109
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ServiceLocator;
1111

1212
/**
1313
* ProjectServiceContainer.

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
77
use Symfony\Component\DependencyInjection\Exception\LogicException;
88
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9-
use Symfony\Component\DependencyInjection\ServiceLocator;
109
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ServiceLocator;
1111

1212
/**
1313
* ProjectServiceContainer.

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
77
use Symfony\Component\DependencyInjection\Exception\LogicException;
88
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9-
use Symfony\Component\DependencyInjection\ServiceLocator;
109
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ServiceLocator;
1111

1212
/**
1313
* ProjectServiceContainer.

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
77
use Symfony\Component\DependencyInjection\Exception\LogicException;
88
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9-
use Symfony\Component\DependencyInjection\ServiceLocator;
109
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
10+
use Symfony\Component\DependencyInjection\ServiceLocator;
1111

1212
/**
1313
* ProjectServiceContainer.
@@ -54,6 +54,7 @@ public function __construct()
5454
'new_factory' => 'getNewFactoryService',
5555
'new_factory_service' => 'getNewFactoryServiceService',
5656
'service_from_static_method' => 'getServiceFromStaticMethodService',
57+
'service_locator' => 'getServiceLocatorService',
5758
);
5859
$this->privates = array(
5960
'configurator_service' => true,
@@ -401,6 +402,23 @@ protected function getServiceFromStaticMethodService()
401402
return $this->services['service_from_static_method'] = \Bar\FooClass::getInstance();
402403
}
403404

405+
/**
406+
* Gets the 'service_locator' service.
407+
*
408+
* This service is shared.
409+
* This method always returns the same instance of the service.
410+
*
411+
* @return \Bar A Bar instance
412+
*/
413+
protected function getServiceLocatorService()
414+
{
415+
return $this->services['service_locator'] = new \Bar(new ServiceLocator(array(
416+
'bar' => function () { return ${($_ = isset($this->services['bar']) ? $this->services['bar'] : $this->get('bar')) && false ?: '_'}; },
417+
'invalid' => function () { return $this->get('invalid', ContainerInterface::NULL_ON_INVALID_REFERENCE); },
418+
'container' => function () { return $this; },
419+
)));
420+
}
421+
404422
/**
405423
* Gets the 'configurator_service' service.
406424
*

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
77
use Symfony\Component\DependencyInjection\Exception\LogicException;
88
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9-
use Symfony\Component\DependencyInjection\ServiceLocator;
109
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ServiceLocator;
1111

1212
/**
1313
* ProjectServiceContainer.
@@ -50,6 +50,7 @@ public function __construct()
5050
'method_call1' => 'getMethodCall1Service',
5151
'new_factory_service' => 'getNewFactoryServiceService',
5252
'service_from_static_method' => 'getServiceFromStaticMethodService',
53+
'service_locator' => 'getServiceLocatorService',
5354
);
5455
$this->aliases = array(
5556
'alias_for_alias' => 'foo',
@@ -392,6 +393,22 @@ protected function getServiceFromStaticMethodService()
392393
return $this->services['service_from_static_method'] = \Bar\FooClass::getInstance();
393394
}
394395

396+
/**
397+
* Gets the 'service_locator' service.
398+
*
399+
* This service is shared.
400+
* This method always returns the same instance of the service.
401+
*
402+
* @return \Bar A Bar instance
403+
*/
404+
protected function getServiceLocatorService()
405+
{
406+
return $this->services['service_locator'] = new \Bar(new ServiceLocator(array(
407+
'bar' => function () { return ${($_ = isset($this->services['bar']) ? $this->services['bar'] : $this->get('bar')) && false ?: '_'}; },
408+
'container' => function () { return $this; },
409+
)));
410+
}
411+
395412
/**
396413
* {@inheritdoc}
397414
*/

0 commit comments

Comments
 (0)