Skip to content

Commit

Permalink
bug #14013 [DependencyInjection] prevent inlining service configurato…
Browse files Browse the repository at this point in the history
…rs (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
  • Loading branch information
fabpot committed Mar 23, 2015
2 parents 3b9127e + 34619fe commit 99330cb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
Expand Up @@ -62,9 +62,6 @@ public function process(ContainerBuilder $container)
$definition->setProperties(
$this->inlineArguments($container, $definition->getProperties())
);

$configurator = $this->inlineArguments($container, array($definition->getConfigurator()));
$definition->setConfigurator($configurator[0]);
}
}

Expand Down
Expand Up @@ -254,6 +254,23 @@ public function testProcessDoesNotInlineFactories()
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $factory[0]);
}

public function testProcessDoesNotInlineConfigurators()
{
$container = new ContainerBuilder();
$container
->register('foo.configurator')
->setPublic(false)
;
$container
->register('foo')
->setConfigurator(array(new Reference('foo.configurator'), 'getFoo'))
;
$this->process($container);

$configurator = $container->getDefinition('foo')->getConfigurator();
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $configurator[0]);
}

protected function process(ContainerBuilder $container)
{
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new InlineServiceDefinitionsPass()));
Expand Down
Expand Up @@ -145,6 +145,7 @@ public function provideCompiledContainerData()
{
return array(
array('container8'),
array('container9'),
array('container11'),
array('container12'),
array('container14'),
Expand Down
Expand Up @@ -37,6 +37,7 @@ public function __construct()
$this->methodMap = array(
'bar' => 'getBarService',
'baz' => 'getBazService',
'configurator_service' => 'getConfiguratorServiceService',
'configured_service' => 'getConfiguredServiceService',
'decorator_service' => 'getDecoratorServiceService',
'decorator_service_with_name' => 'getDecoratorServiceWithNameService',
Expand Down Expand Up @@ -113,12 +114,9 @@ protected function getBazService()
*/
protected function getConfiguredServiceService()
{
$a = new \ConfClass();
$a->setFoo($this->get('baz'));

$this->services['configured_service'] = $instance = new \stdClass();

$a->configureStdClass($instance);
$this->get('configurator_service')->configureStdClass($instance);

return $instance;
}
Expand Down Expand Up @@ -326,6 +324,27 @@ protected function synchronizeRequestService()
}
}

/**
* Gets the 'configurator_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* This service is private.
* If you want to be able to request this service from the container directly,
* make it public, otherwise you might end up with broken code.
*
* @return \ConfClass A ConfClass instance.
*/
protected function getConfiguratorServiceService()
{
$this->services['configurator_service'] = $instance = new \ConfClass();

$instance->setFoo($this->get('baz'));

return $instance;
}

/**
* Gets the 'new_factory' service.
*
Expand Down

0 comments on commit 99330cb

Please sign in to comment.