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 99330cb

Browse filesBrowse files
committed
bug #14013 [DependencyInjection] prevent inlining service configurators (xabbuh)
This PR was merged into the 2.6 branch. Discussion ---------- [DependencyInjection] prevent inlining service configurators | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Currently, only the `PhpDumper` is able to dump inlined service configurators. Since Symfony applications dump the compiled container in XML, inlined configurators will break this process. We did something similar before with service factories in #13914. Commits ------- 34619fe prevent inlining service configurators
2 parents 3b9127e + 34619fe commit 99330cb
Copy full SHA for 99330cb

File tree

Expand file treeCollapse file tree

4 files changed

+41
-7
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+41
-7
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ public function process(ContainerBuilder $container)
6262
$definition->setProperties(
6363
$this->inlineArguments($container, $definition->getProperties())
6464
);
65-
66-
$configurator = $this->inlineArguments($container, array($definition->getConfigurator()));
67-
$definition->setConfigurator($configurator[0]);
6865
}
6966
}
7067

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,23 @@ public function testProcessDoesNotInlineFactories()
254254
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $factory[0]);
255255
}
256256

257+
public function testProcessDoesNotInlineConfigurators()
258+
{
259+
$container = new ContainerBuilder();
260+
$container
261+
->register('foo.configurator')
262+
->setPublic(false)
263+
;
264+
$container
265+
->register('foo')
266+
->setConfigurator(array(new Reference('foo.configurator'), 'getFoo'))
267+
;
268+
$this->process($container);
269+
270+
$configurator = $container->getDefinition('foo')->getConfigurator();
271+
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $configurator[0]);
272+
}
273+
257274
protected function process(ContainerBuilder $container)
258275
{
259276
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new InlineServiceDefinitionsPass()));

‎src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public function provideCompiledContainerData()
145145
{
146146
return array(
147147
array('container8'),
148+
array('container9'),
148149
array('container11'),
149150
array('container12'),
150151
array('container14'),

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php
+23-4Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function __construct()
3737
$this->methodMap = array(
3838
'bar' => 'getBarService',
3939
'baz' => 'getBazService',
40+
'configurator_service' => 'getConfiguratorServiceService',
4041
'configured_service' => 'getConfiguredServiceService',
4142
'decorator_service' => 'getDecoratorServiceService',
4243
'decorator_service_with_name' => 'getDecoratorServiceWithNameService',
@@ -113,12 +114,9 @@ protected function getBazService()
113114
*/
114115
protected function getConfiguredServiceService()
115116
{
116-
$a = new \ConfClass();
117-
$a->setFoo($this->get('baz'));
118-
119117
$this->services['configured_service'] = $instance = new \stdClass();
120118

121-
$a->configureStdClass($instance);
119+
$this->get('configurator_service')->configureStdClass($instance);
122120

123121
return $instance;
124122
}
@@ -326,6 +324,27 @@ protected function synchronizeRequestService()
326324
}
327325
}
328326

327+
/**
328+
* Gets the 'configurator_service' service.
329+
*
330+
* This service is shared.
331+
* This method always returns the same instance of the service.
332+
*
333+
* This service is private.
334+
* If you want to be able to request this service from the container directly,
335+
* make it public, otherwise you might end up with broken code.
336+
*
337+
* @return \ConfClass A ConfClass instance.
338+
*/
339+
protected function getConfiguratorServiceService()
340+
{
341+
$this->services['configurator_service'] = $instance = new \ConfClass();
342+
343+
$instance->setFoo($this->get('baz'));
344+
345+
return $instance;
346+
}
347+
329348
/**
330349
* Gets the 'new_factory' service.
331350
*

0 commit comments

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