diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 3e5de6cb8252..1311fb055138 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -800,16 +800,18 @@ class $class extends $baseClass */ private function addConstructor() { - $arguments = $this->container->getParameterBag()->all() ? 'new ParameterBag($this->getDefaultParameters())' : null; + $parameters = $this->exportParameters($this->container->getParameterBag()->all()); $code = <<exportParameters($this->container->getParameterBag()->all()); + $code = <<container->getParameterBag()->all()) { - $code .= "\n \$this->parameters = \$this->getDefaultParameters();\n"; - } - - $code .= <<services = \$this->scopedServices = \$this->scopeStacks = array(); @@ -961,8 +957,6 @@ private function addDefaultParametersMethod() return ''; } - $parameters = $this->exportParameters($this->container->getParameterBag()->all()); - $code = ''; if ($this->container->isFrozen()) { $code .= <<parameters[\$name]) || array_key_exists(\$name, \$this->parameters))) { + if (!(isset(self::\$parameters[\$name]) || array_key_exists(\$name, self::\$parameters))) { throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', \$name)); } - return \$this->parameters[\$name]; + return self::\$parameters[\$name]; } /** @@ -988,7 +982,7 @@ public function hasParameter(\$name) { \$name = strtolower(\$name); - return isset(\$this->parameters[\$name]) || array_key_exists(\$name, \$this->parameters); + return isset(self::\$parameters[\$name]) || array_key_exists(\$name, self::\$parameters); } /** @@ -1005,27 +999,14 @@ public function setParameter(\$name, \$value) public function getParameterBag() { if (null === \$this->parameterBag) { - \$this->parameterBag = new FrozenParameterBag(\$this->parameters); + \$this->parameterBag = new FrozenParameterBag(self::\$parameters); } return \$this->parameterBag; } -EOF; - } - - $code .= << '', + 'some_string' => '-', + ); /** * Constructor. */ public function __construct() { - $this->parameters = $this->getDefaultParameters(); - $this->services = $this->scopedServices = $this->scopeStacks = array(); @@ -68,11 +69,11 @@ public function getParameter($name) { $name = strtolower($name); - if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters))) { + if (!(isset(self::$parameters[$name]) || array_key_exists($name, self::$parameters))) { throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name)); } - return $this->parameters[$name]; + return self::$parameters[$name]; } /** @@ -82,7 +83,7 @@ public function hasParameter($name) { $name = strtolower($name); - return isset($this->parameters[$name]) || array_key_exists($name, $this->parameters); + return isset(self::$parameters[$name]) || array_key_exists($name, self::$parameters); } /** @@ -99,21 +100,9 @@ public function setParameter($name, $value) public function getParameterBag() { if (null === $this->parameterBag) { - $this->parameterBag = new FrozenParameterBag($this->parameters); + $this->parameterBag = new FrozenParameterBag(self::$parameters); } return $this->parameterBag; } - /** - * Gets the default parameters. - * - * @return array An array of the default parameters - */ - protected function getDefaultParameters() - { - return array( - 'empty_value' => '', - 'some_string' => '-', - ); - } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php index ada46e94129e..2d8a61fb2d02 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php @@ -16,7 +16,9 @@ */ class ProjectServiceContainer extends Container { - private $parameters; + private static $parameters = array( + + ); /** * Constructor. diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php index f922d2000c7e..7c50647d4e04 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php @@ -16,22 +16,7 @@ */ class ProjectServiceContainer extends Container { - /** - * Constructor. - */ - public function __construct() - { - parent::__construct(new ParameterBag($this->getDefaultParameters())); - } - - /** - * Gets the default parameters. - * - * @return array An array of the default parameters - */ - protected function getDefaultParameters() - { - return array( + private static $parameters = array( 'foo' => '%baz%', 'baz' => 'bar', 'bar' => 'foo is %%foo bar', @@ -47,5 +32,12 @@ protected function getDefaultParameters() 7 => 'null', ), ); + + /** + * Constructor. + */ + public function __construct() + { + parent::__construct(new ParameterBag(self::$parameters)); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php index 4ca34ef9ae61..68199d3092d5 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php @@ -16,12 +16,18 @@ */ class ProjectServiceContainer extends Container { + private static $parameters = array( + 'baz_class' => 'BazClass', + 'foo_class' => 'Bar\\FooClass', + 'foo' => 'bar', + ); + /** * Constructor. */ public function __construct() { - parent::__construct(new ParameterBag($this->getDefaultParameters())); + parent::__construct(new ParameterBag(self::$parameters)); $this->methodMap = array( 'bar' => 'getBarService', 'baz' => 'getBazService', @@ -370,18 +376,4 @@ protected function getNewFactoryService() return $instance; } - - /** - * Gets the default parameters. - * - * @return array An array of the default parameters - */ - protected function getDefaultParameters() - { - return array( - 'baz_class' => 'BazClass', - 'foo_class' => 'Bar\\FooClass', - 'foo' => 'bar', - ); - } } 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 bf47e8216ce8..873893fa960f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -16,15 +16,17 @@ */ class ProjectServiceContainer extends Container { - private $parameters; + private static $parameters = array( + 'baz_class' => 'BazClass', + 'foo_class' => 'Bar\\FooClass', + 'foo' => 'bar', + ); /** * Constructor. */ public function __construct() { - $this->parameters = $this->getDefaultParameters(); - $this->services = $this->scopedServices = $this->scopeStacks = array(); @@ -320,11 +322,11 @@ public function getParameter($name) { $name = strtolower($name); - if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters))) { + if (!(isset(self::$parameters[$name]) || array_key_exists($name, self::$parameters))) { throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name)); } - return $this->parameters[$name]; + return self::$parameters[$name]; } /** @@ -334,7 +336,7 @@ public function hasParameter($name) { $name = strtolower($name); - return isset($this->parameters[$name]) || array_key_exists($name, $this->parameters); + return isset(self::$parameters[$name]) || array_key_exists($name, self::$parameters); } /** @@ -351,22 +353,9 @@ public function setParameter($name, $value) public function getParameterBag() { if (null === $this->parameterBag) { - $this->parameterBag = new FrozenParameterBag($this->parameters); + $this->parameterBag = new FrozenParameterBag(self::$parameters); } return $this->parameterBag; } - /** - * Gets the default parameters. - * - * @return array An array of the default parameters - */ - protected function getDefaultParameters() - { - return array( - 'baz_class' => 'BazClass', - 'foo_class' => 'Bar\\FooClass', - 'foo' => 'bar', - ); - } }