diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 222355171d..b50974b267 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -689,7 +689,13 @@ EOF; */ public function __construct() { - \$this->parameters = \$this->getDefaultParameters(); +EOF; + + if ($this->container->getParameterBag()->all()) { + $code .= "\n \$this->parameters = \$this->getDefaultParameters();\n"; + } + + $code .= <<services = \$this->scopedServices = diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Dumper/PhpDumperTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Dumper/PhpDumperTest.php index 221a007541..ed2228a523 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Dumper/PhpDumperTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Dumper/PhpDumperTest.php @@ -37,6 +37,20 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase new PhpDumper($container); } + public function testDumpFrozenContainerWithNoParameter() + { + $container = new ContainerBuilder(); + $container->register('foo', 'stdClass'); + + $container->compile(); + + $dumper = new PhpDumper($container); + + $dumpedString = $dumper->dump(); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services11.php', $dumpedString, '->dump() does not add getDefaultParameters() method call if container have no parameters.'); + $this->assertNotRegexp("/function getDefaultParameters\(/", $dumpedString, '->dump() does not add getDefaultParameters() method definition.'); + } + public function testDumpOptimizationString() { $definition = new Definition(); diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services11.php b/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services11.php new file mode 100644 index 0000000000..65c71e1391 --- /dev/null +++ b/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services11.php @@ -0,0 +1,45 @@ +services = + $this->scopedServices = + $this->scopeStacks = array(); + + $this->set('service_container', $this); + + $this->scopes = array(); + $this->scopeChildren = array(); + } + + /** + * Gets the 'foo' service. + * + * This service is shared. + * This method always returns the same instance of the service. + * + * @return stdClass A stdClass instance. + */ + protected function getFooService() + { + return $this->services['foo'] = new \stdClass(); + } +}