diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 0241c7fcf9..7ed2b3027e 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -833,18 +833,16 @@ EOF; */ private function addConstructor() { - $parameters = $this->exportParameters($this->container->getParameterBag()->all()); + $arguments = $this->container->getParameterBag()->all() ? 'new ParameterBag($this->getDefaultParameters())' : null; $code = <<exportParameters($this->container->getParameterBag()->all()); - $code = <<container->getParameterBag()->all()) { + $code .= "\n \$this->parameters = \$this->getDefaultParameters();\n"; + } + + $code .= <<services = \$this->scopedServices = \$this->scopeStacks = array(); @@ -990,6 +994,8 @@ EOF; return ''; } + $parameters = $this->exportParameters($this->container->getParameterBag()->all()); + $code = ''; if ($this->container->isFrozen()) { $code .= <<parameters[\$name]) || array_key_exists(\$name, \$this->parameters))) { throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', \$name)); } - return self::\$parameters[\$name]; + return \$this->parameters[\$name]; } /** @@ -1015,7 +1021,7 @@ EOF; { \$name = strtolower(\$name); - return isset(self::\$parameters[\$name]) || array_key_exists(\$name, self::\$parameters); + return isset(\$this->parameters[\$name]) || array_key_exists(\$name, \$this->parameters); } /** @@ -1032,15 +1038,28 @@ EOF; public function getParameterBag() { if (null === \$this->parameterBag) { - \$this->parameterBag = new FrozenParameterBag(self::\$parameters); + \$this->parameterBag = new FrozenParameterBag(\$this->parameters); } return \$this->parameterBag; } - EOF; } + $code .= << '', - 'some_string' => '-', - ); + private $parameters; /** * Constructor. */ public function __construct() { + $this->parameters = $this->getDefaultParameters(); + $this->services = $this->scopedServices = $this->scopeStacks = array(); @@ -69,11 +68,11 @@ class ProjectServiceContainer extends Container { $name = strtolower($name); - if (!(isset(self::$parameters[$name]) || array_key_exists($name, self::$parameters))) { + if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters))) { throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name)); } - return self::$parameters[$name]; + return $this->parameters[$name]; } /** @@ -83,7 +82,7 @@ class ProjectServiceContainer extends Container { $name = strtolower($name); - return isset(self::$parameters[$name]) || array_key_exists($name, self::$parameters); + return isset($this->parameters[$name]) || array_key_exists($name, $this->parameters); } /** @@ -100,9 +99,21 @@ class ProjectServiceContainer extends Container public function getParameterBag() { if (null === $this->parameterBag) { - $this->parameterBag = new FrozenParameterBag(self::$parameters); + $this->parameterBag = new FrozenParameterBag($this->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 2d8a61fb2d..ada46e9412 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php @@ -16,9 +16,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; */ class ProjectServiceContainer extends Container { - private static $parameters = array( - - ); + private $parameters; /** * Constructor. diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php index 7c50647d4e..f922d2000c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php @@ -16,7 +16,22 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; */ class ProjectServiceContainer extends Container { - private static $parameters = array( + /** + * 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( 'foo' => '%baz%', 'baz' => 'bar', 'bar' => 'foo is %%foo bar', @@ -32,12 +47,5 @@ class ProjectServiceContainer extends Container 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 3cc3aac8b8..650bdf7b63 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php @@ -16,18 +16,12 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; */ 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(self::$parameters)); + parent::__construct(new ParameterBag($this->getDefaultParameters())); $this->methodMap = array( 'bar' => 'getBarService', 'baz' => 'getBazService', @@ -390,4 +384,18 @@ class ProjectServiceContainer extends Container 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 5e8103bdd0..b81687f574 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -16,17 +16,15 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; */ class ProjectServiceContainer extends Container { - private static $parameters = array( - 'baz_class' => 'BazClass', - 'foo_class' => 'Bar\\FooClass', - 'foo' => 'bar', - ); + private $parameters; /** * Constructor. */ public function __construct() { + $this->parameters = $this->getDefaultParameters(); + $this->services = $this->scopedServices = $this->scopeStacks = array(); @@ -336,11 +334,11 @@ class ProjectServiceContainer extends Container { $name = strtolower($name); - if (!(isset(self::$parameters[$name]) || array_key_exists($name, self::$parameters))) { + if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters))) { throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name)); } - return self::$parameters[$name]; + return $this->parameters[$name]; } /** @@ -350,7 +348,7 @@ class ProjectServiceContainer extends Container { $name = strtolower($name); - return isset(self::$parameters[$name]) || array_key_exists($name, self::$parameters); + return isset($this->parameters[$name]) || array_key_exists($name, $this->parameters); } /** @@ -367,9 +365,22 @@ class ProjectServiceContainer extends Container public function getParameterBag() { if (null === $this->parameterBag) { - $this->parameterBag = new FrozenParameterBag(self::$parameters); + $this->parameterBag = new FrozenParameterBag($this->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', + ); + } }