From 34619fedfff82437cb7a1aefd44e3a60d8572135 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 22 Mar 2015 08:55:48 +0100 Subject: [PATCH] prevent inlining service configurators 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. --- .../Compiler/InlineServiceDefinitionsPass.php | 3 --- .../InlineServiceDefinitionsPassTest.php | 17 ++++++++++++ .../Tests/Dumper/XmlDumperTest.php | 1 + .../Tests/Fixtures/php/services9_compiled.php | 27 ++++++++++++++++--- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php index 77f0fe4f9432e..d9a656f78777a 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php @@ -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]); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php index aab7990623514..baefa1d0fff92 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php @@ -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())); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php index 2dcdf03fd4f5d..76cbb60da3938 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php @@ -145,6 +145,7 @@ public function provideCompiledContainerData() { return array( array('container8'), + array('container9'), array('container11'), array('container12'), array('container14'), diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php index 09852a4cc70b3..6addc7cbcc98c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -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', @@ -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; } @@ -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. * pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy