Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3ae36f4

Browse filesBrowse files
committed
feature #22024 [DI] Introduce "container.service_locator" tag, replaces ServiceLocatorArgument (nicolas-grekas)
This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] Introduce "container.service_locator" tag, replaces ServiceLocatorArgument | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no (master only) | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - I first started working on adding this new "container.service_locator" tag, so here it is. It allows defining and dumping service-locator services properly, where it wasn't possible previously (you had to create a DI extension to do so.) Then I realized that this allowed us to entirely drop `ServiceLocatorArgument` and replace it with the more flexible `ServiceClosureArgument`. This makes things simpler overall, see diff stat. Commits ------- 5d230b5 [DI] Introduce "container.service_locator" tag, replaces ServiceLocatorArgument
2 parents 207d068 + 5d230b5 commit 3ae36f4
Copy full SHA for 3ae36f4

File tree

68 files changed

+141
-535
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner

68 files changed

+141
-535
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
1818
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1919
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
20-
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
2120
use Symfony\Component\DependencyInjection\ContainerBuilder;
2221
use Symfony\Component\DependencyInjection\Definition;
2322
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -332,8 +331,6 @@ protected function describeContainerDefinition(Definition $definition, array $op
332331
$argumentsInformation[] = sprintf('Service(%s)', (string) $argument);
333332
} elseif ($argument instanceof IteratorArgument) {
334333
$argumentsInformation[] = sprintf('Iterator (%d element(s))', count($argument->getValues()));
335-
} elseif ($argument instanceof ServiceLocatorArgument) {
336-
$argumentsInformation[] = sprintf('ServiceLocator (%d service(s))', count($argument->getValues()));
337334
} elseif ($argument instanceof ClosureProxyArgument) {
338335
list($reference, $method) = $argument->getValues();
339336
$argumentsInformation[] = sprintf('ClosureProxy(Service(%s)::%s())', $reference, $method);

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php
-7Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
1616
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1717
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
18-
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
1918
use Symfony\Component\DependencyInjection\ContainerBuilder;
2019
use Symfony\Component\DependencyInjection\Definition;
2120
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -436,12 +435,6 @@ private function getArgumentNodes(array $arguments, \DOMDocument $dom)
436435
} elseif ($argument instanceof IteratorArgument) {
437436
$argumentXML->setAttribute('type', 'iterator');
438437

439-
foreach ($this->getArgumentNodes($argument->getValues(), $dom) as $childArgumentXML) {
440-
$argumentXML->appendChild($childArgumentXML);
441-
}
442-
} elseif ($argument instanceof ServiceLocatorArgument) {
443-
$argumentXML->setAttribute('type', 'service-locator');
444-
445438
foreach ($this->getArgumentNodes($argument->getValues(), $dom) as $childArgumentXML) {
446439
$argumentXML->appendChild($childArgumentXML);
447440
}

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConstraintValidatorsPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConstraintValidatorsPass.php
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14-
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
14+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17+
use Symfony\Component\DependencyInjection\Definition;
1718
use Symfony\Component\DependencyInjection\Reference;
19+
use Symfony\Component\DependencyInjection\ServiceLocator;
1820

1921
class AddConstraintValidatorsPass implements CompilerPassInterface
2022
{
@@ -33,12 +35,12 @@ public function process(ContainerBuilder $container)
3335
}
3436

3537
if (isset($attributes[0]['alias'])) {
36-
$validators[$attributes[0]['alias']] = new Reference($id);
38+
$validators[$attributes[0]['alias']] = new ServiceClosureArgument(new Reference($id));
3739
}
3840

39-
$validators[$definition->getClass()] = new Reference($id);
41+
$validators[$definition->getClass()] = new ServiceClosureArgument(new Reference($id));
4042
}
4143

42-
$container->getDefinition('validator.validator_factory')->replaceArgument(0, new ServiceLocatorArgument($validators));
44+
$container->getDefinition('validator.validator_factory')->replaceArgument(0, (new Definition(ServiceLocator::class, array($validators)))->addTag('container.service_locator'));
4345
}
4446
}

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<!-- DependencyInjectionExtension -->
3232
<service id="form.extension" class="Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension" public="false">
33-
<argument type="service-locator" /><!-- All services with tag "form.type" are stored in a service locator by FormPass -->
33+
<argument /><!-- All services with tag "form.type" are stored in a service locator by FormPass -->
3434
<argument type="collection" /><!-- All services with tag "form.type_extension" are stored here by FormPass -->
3535
<argument type="iterator" /><!-- All services with tag "form.type_guesser" are stored here by FormPass -->
3636
</service>

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,13 @@
4949

5050
<service id="session_listener" class="Symfony\Component\HttpKernel\EventListener\SessionListener">
5151
<tag name="kernel.event_subscriber" />
52-
<argument type="service-locator">
53-
<argument key="session" type="service" id="session" on-invalid="null" />
52+
<argument type="service">
53+
<service class="Symfony\Component\DependencyInjection\ServiceLocator">
54+
<tag name="container.service_locator" />
55+
<argument type="collection">
56+
<argument key="session" type="service" id="session" on-invalid="ignore" />
57+
</argument>
58+
</service>
5459
</argument>
5560
</service>
5661

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222

2323
<service id="test.session.listener" class="Symfony\Component\HttpKernel\EventListener\TestSessionListener">
2424
<tag name="kernel.event_subscriber" />
25-
<argument type="service-locator">
26-
<argument key="session" type="service" id="session" on-invalid="null" />
25+
<argument type="service">
26+
<service class="Symfony\Component\DependencyInjection\ServiceLocator">
27+
<tag name="container.service_locator" />
28+
<argument type="collection">
29+
<argument key="session" type="service" id="session" on-invalid="ignore" />
30+
</argument>
31+
</service>
2732
</argument>
2833
</service>
2934
</services>

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
</service>
5858

5959
<service id="validator.validator_factory" class="Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory" public="false">
60-
<argument type="service-locator" /> <!-- Constraint validators locator -->
60+
<argument /> <!-- Constraint validators locator -->
6161
</service>
6262

6363
<service id="validator.expression" class="Symfony\Component\Validator\Constraints\ExpressionValidator">

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private function assertDescription($expectedDescription, $describedObject, array
192192
$this->getDescriptor()->describe($output, $describedObject, $options);
193193

194194
if ('json' === $this->getFormat()) {
195-
$this->assertEquals(json_decode($expectedDescription), json_decode($output->fetch()));
195+
$this->assertEquals(json_encode(json_decode($expectedDescription), JSON_PRETTY_PRINT), json_encode(json_decode($output->fetch()), JSON_PRETTY_PRINT));
196196
} else {
197197
$this->assertEquals(trim($expectedDescription), trim(str_replace(PHP_EOL, "\n", $output->fetch())));
198198
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
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;
1817
use Symfony\Component\DependencyInjection\ContainerBuilder;
1918
use Symfony\Component\DependencyInjection\Definition;
2019
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -121,10 +120,6 @@ public static function getContainerDefinitions()
121120
new Reference('definition_2'),
122121
)))
123122
->addArgument(new ClosureProxyArgument('definition1', 'get'))
124-
->addArgument(new ServiceLocatorArgument(array(
125-
'def1' => new Reference('definition_1'),
126-
'def2' => new Reference('definition_2'),
127-
)))
128123
->setFactory(array('Full\\Qualified\\FactoryClass', 'get')),
129124
'definition_2' => $definition2
130125
->setPublic(false)

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddConstraintValidatorsPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddConstraintValidatorsPassTest.php
+9-7Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
16-
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
16+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
use Symfony\Component\DependencyInjection\Definition;
1819
use Symfony\Component\DependencyInjection\Reference;
20+
use Symfony\Component\DependencyInjection\ServiceLocator;
1921

2022
class AddConstraintValidatorsPassTest extends TestCase
2123
{
2224
public function testThatConstraintValidatorServicesAreProcessed()
2325
{
2426
$container = new ContainerBuilder();
2527
$validatorFactory = $container->register('validator.validator_factory')
26-
->setArguments(array(new ServiceLocatorArgument(array())));
28+
->addArgument(array());
2729

2830
$container->register('my_constraint_validator_service1', Validator1::class)
2931
->addTag('validator.constraint_validator', array('alias' => 'my_constraint_validator_alias1'));
@@ -36,11 +38,11 @@ public function testThatConstraintValidatorServicesAreProcessed()
3638
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
3739
$addConstraintValidatorsPass->process($container);
3840

39-
$this->assertEquals(new ServiceLocatorArgument(array(
40-
Validator1::class => new Reference('my_constraint_validator_service1'),
41-
'my_constraint_validator_alias1' => new Reference('my_constraint_validator_service1'),
42-
Validator2::class => new Reference('my_constraint_validator_service2'),
43-
)), $validatorFactory->getArgument(0));
41+
$this->assertEquals((new Definition(ServiceLocator::class, array(array(
42+
Validator1::class => new ServiceClosureArgument(new Reference('my_constraint_validator_service1')),
43+
'my_constraint_validator_alias1' => new ServiceClosureArgument(new Reference('my_constraint_validator_service1')),
44+
Validator2::class => new ServiceClosureArgument(new Reference('my_constraint_validator_service2')),
45+
))))->addTag('container.service_locator'), $validatorFactory->getArgument(0));
4446
}
4547

4648
public function testThatCompilerPassIsIgnoredIfThereIsNoConstraintValidatorFactoryDefinition()

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/FormPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/FormPassTest.php
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass;
1616
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
17-
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
17+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1818
use Symfony\Component\DependencyInjection\ContainerBuilder;
1919
use Symfony\Component\DependencyInjection\Definition;
2020
use Symfony\Component\DependencyInjection\Reference;
21+
use Symfony\Component\DependencyInjection\ServiceLocator;
2122
use Symfony\Component\Form\AbstractType;
2223

2324
/**
@@ -49,10 +50,10 @@ public function testAddTaggedTypes()
4950
$extDefinition = $container->getDefinition('form.extension');
5051

5152
$this->assertEquals(
52-
new ServiceLocatorArgument(array(
53-
__CLASS__.'_Type1' => new Reference('my.type1'),
54-
__CLASS__.'_Type2' => new Reference('my.type2'),
55-
)),
53+
(new Definition(ServiceLocator::class, array(array(
54+
__CLASS__.'_Type1' => new ServiceClosureArgument(new Reference('my.type1')),
55+
__CLASS__.'_Type2' => new ServiceClosureArgument(new Reference('my.type2')),
56+
))))->addTag('container.service_locator'),
5657
$extDefinition->getArgument(0)
5758
);
5859
}
@@ -196,7 +197,7 @@ private function createExtensionDefinition()
196197
{
197198
$definition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension');
198199
$definition->setArguments(array(
199-
new ServiceLocatorArgument(array()),
200+
array(),
200201
array(),
201202
new IteratorArgument(array()),
202203
));

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\FullStack;
1616
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1717
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
18+
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
1819
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
1920
use Symfony\Component\Cache\Adapter\AdapterInterface;
2021
use Symfony\Component\Cache\Adapter\ApcuAdapter;
@@ -921,7 +922,7 @@ protected function createContainerFromFile($file, $data = array(), $resetCompile
921922
$container->getCompilerPassConfig()->setOptimizationPasses(array());
922923
$container->getCompilerPassConfig()->setRemovingPasses(array());
923924
}
924-
$container->getCompilerPassConfig()->setBeforeRemovingPasses(array(new AddAnnotationsCachedReaderPass()));
925+
$container->getCompilerPassConfig()->setBeforeRemovingPasses(array(new AddAnnotationsCachedReaderPass(), new AddConstraintValidatorsPass()));
925926
$container->compile();
926927

927928
return self::$containerCache[$cacheKey] = $container;

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json
+1-11Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,7 @@
6464
"id": "definition1"
6565
},
6666
"get"
67-
],
68-
{
69-
"def1": {
70-
"type": "service",
71-
"id": "definition_1"
72-
},
73-
"def2": {
74-
"type": "service",
75-
"id": "definition_2"
76-
}
77-
}
67+
]
7868
],
7969
"file": null,
8070
"factory_class": "Full\\Qualified\\FactoryClass",

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
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>
3127
</definition>
3228
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>
3329
</container>

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.json
+1-11Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,7 @@
6262
"id": "definition1"
6363
},
6464
"get"
65-
],
66-
{
67-
"def1": {
68-
"type": "service",
69-
"id": "definition_1"
70-
},
71-
"def2": {
72-
"type": "service",
73-
"id": "definition_2"
74-
}
75-
}
65+
]
7666
],
7767
"file": null,
7868
"factory_class": "Full\\Qualified\\FactoryClass",

‎src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.txt

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.txt
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@
1818
Array (3 element(s))
1919
Iterator (2 element(s))
2020
ClosureProxy(Service(definition1)::get())
21-
ServiceLocator (2 service(s))
2221
---------------- -------------------------------------------
2322

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.xml
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,4 @@
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>
2824
</definition>

‎src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
use Symfony\Component\Console\Application;
1818
use Symfony\Component\DependencyInjection\Alias;
1919
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
20-
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
20+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
2121
use Symfony\Component\DependencyInjection\ChildDefinition;
22+
use Symfony\Component\DependencyInjection\Definition;
2223
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2324
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2425
use Symfony\Component\DependencyInjection\ContainerBuilder;
2526
use Symfony\Component\DependencyInjection\Reference;
27+
use Symfony\Component\DependencyInjection\ServiceLocator;
2628
use Symfony\Component\Config\FileLocator;
2729
use Symfony\Component\Security\Core\Authorization\ExpressionLanguage;
2830

@@ -260,10 +262,10 @@ private function createFirewalls($config, ContainerBuilder $container)
260262
->replaceArgument(2, new Reference($configId))
261263
;
262264

263-
$contextRefs[$contextId] = new Reference($contextId);
265+
$contextRefs[$contextId] = new ServiceClosureArgument(new Reference($contextId));
264266
$map[$contextId] = $matcher;
265267
}
266-
$mapDef->replaceArgument(0, new ServiceLocatorArgument($contextRefs));
268+
$mapDef->replaceArgument(0, (new Definition(ServiceLocator::class, array($contextRefs)))->addTag('container.service_locator'));
267269
$mapDef->replaceArgument(1, new IteratorArgument($map));
268270

269271
// add authentication providers to authentication manager

‎src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/RuntimeLoaderPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/RuntimeLoaderPass.php
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler;
1313

14-
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
14+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1717
use Symfony\Component\DependencyInjection\Reference;
18+
use Symfony\Component\DependencyInjection\Definition;
19+
use Symfony\Component\DependencyInjection\ServiceLocator;
1820

1921
/**
2022
* Registers Twig runtime services.
@@ -36,9 +38,9 @@ public function process(ContainerBuilder $container)
3638
continue;
3739
}
3840

39-
$mapping[$def->getClass()] = new Reference($id);
41+
$mapping[$def->getClass()] = new ServiceClosureArgument(new Reference($id));
4042
}
4143

42-
$definition->replaceArgument(0, new ServiceLocatorArgument($mapping));
44+
$definition->replaceArgument(0, (new Definition(ServiceLocator::class, array($mapping)))->addTag('container.service_locator'));
4345
}
4446
}

‎src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,11 @@ public function testRuntimeLoader()
244244
$container->compile();
245245

246246
$loader = $container->getDefinition('twig.runtime_loader');
247-
$args = $loader->getArgument(0)->getValues();
247+
$args = $loader->getArgument(0)->getArgument(0);
248248
$this->assertArrayHasKey('Symfony\Bridge\Twig\Form\TwigRenderer', $args);
249249
$this->assertArrayHasKey('FooClass', $args);
250-
$this->assertContains('twig.form.renderer', $args);
251-
$this->assertContains('foo', $args);
250+
$this->assertEquals('twig.form.renderer', $args['Symfony\Bridge\Twig\Form\TwigRenderer']->getValues()[0]);
251+
$this->assertEquals('foo', $args['FooClass']->getValues()[0]);
252252
}
253253

254254
private function createContainer()

‎src/Symfony/Component/DependencyInjection/Argument/ServiceClosureArgument.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Argument/ServiceClosureArgument.php
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
* Represents a service wrapped in a memoizing closure.
1919
*
2020
* @author Nicolas Grekas <p@tchwork.com>
21-
*
22-
* @experimental in version 3.3
2321
*/
2422
class ServiceClosureArgument implements ArgumentInterface
2523
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.