From 320cf40b71440d6c76fd3dbede91f09b88a1b8fe Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 24 Jul 2017 16:06:58 +0200 Subject: [PATCH] [DI] Fix resetting private services --- .../LazyProxy/PhpDumper/ProxyDumper.php | 3 ++- .../DependencyInjection/Dumper/PhpDumper.php | 22 +++++++++++++++++++ .../Tests/Fixtures/php/services1-1.php | 9 ++++++++ .../Tests/Fixtures/php/services1.php | 9 ++++++++ .../Tests/Fixtures/php/services10.php | 9 ++++++++ .../Tests/Fixtures/php/services12.php | 9 ++++++++ .../Tests/Fixtures/php/services13.php | 9 ++++++++ .../Tests/Fixtures/php/services19.php | 9 ++++++++ .../Tests/Fixtures/php/services24.php | 9 ++++++++ .../Tests/Fixtures/php/services26.php | 9 ++++++++ .../Tests/Fixtures/php/services33.php | 9 ++++++++ .../Tests/Fixtures/php/services8.php | 9 ++++++++ .../Tests/Fixtures/php/services9_compiled.php | 9 ++++++++ .../Fixtures/php/services_array_params.php | 9 ++++++++ .../Tests/Fixtures/php/services_locator.php | 9 ++++++++ .../Fixtures/php/services_private_frozen.php | 9 ++++++++ .../Fixtures/php/services_subscriber.php | 9 ++++++++ 17 files changed, 159 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php index 563e2d1baa4cc..29c6c3617e5e3 100644 --- a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php +++ b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php @@ -14,6 +14,7 @@ use ProxyManager\Generator\ClassGenerator; use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy; use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface; @@ -69,7 +70,7 @@ public function getProxyFactoryCode(Definition $definition, $id, $methodName = n $instantiation = 'return'; if ($definition->isShared()) { - $instantiation .= " \$this->services['$id'] ="; + $instantiation .= sprintf(' $this->%s[\'%s\'] =', $definition->isPublic() || !method_exists(ContainerBuilder::class, 'addClassResource') ? 'services' : 'privates', $id); } if (null === $methodName) { diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 077f7fef223c3..5ee485be40dc0 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -153,6 +153,7 @@ public function dump(array $options = array()) $code = $this->startClass($options['class'], $options['base_class'], $options['namespace']). $this->addConstructor(). + $this->addReset(). $this->addCompile(). $this->addIsCompiled(). $this->addServices(). @@ -831,6 +832,27 @@ public function __construct() return $code; } + /** + * Adds the reset method for a compiled container. + * + * @return string + */ + private function addReset() + { + return <<docStar} + * {@inheritdoc} + */ + public function reset() + { + \$this->privates = array(); + parent::reset(); + } + +EOF; + } + /** * Adds the compile method for a compiled container. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php index 01f159f842037..5f74931f7a290 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php @@ -34,6 +34,15 @@ public function __construct() $this->aliases = array(); } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->privates = array(); + parent::reset(); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php index 967146d410e62..ca73b472a5710 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php @@ -32,6 +32,15 @@ public function __construct() $this->aliases = array(); } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->privates = array(); + parent::reset(); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php index 78ce81547277e..28c09cb74f504 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php @@ -37,6 +37,15 @@ public function __construct() $this->aliases = array(); } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->privates = array(); + parent::reset(); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php index db9faadd187c6..e3042f6d8b593 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php @@ -41,6 +41,15 @@ public function __construct() $this->aliases = array(); } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->privates = array(); + parent::reset(); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php index 35a68aa9b3f2f..e79b934632ef8 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php @@ -35,6 +35,15 @@ public function __construct() $this->aliases = array(); } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->privates = array(); + parent::reset(); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php index 6e384da3b9d7a..1168381f0dba6 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php @@ -36,6 +36,15 @@ public function __construct() $this->aliases = array(); } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->privates = array(); + parent::reset(); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php index 382613ccf4691..ce66c1794f12a 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php @@ -35,6 +35,15 @@ public function __construct() $this->aliases = array(); } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->privates = array(); + parent::reset(); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php index 0fc608186a4d6..0eccfb26c42a9 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php @@ -37,6 +37,15 @@ public function __construct() $this->aliases = array(); } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->privates = array(); + parent::reset(); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php index 548ce20c8bc5d..de77e5bdb4634 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php @@ -35,6 +35,15 @@ public function __construct() $this->aliases = array(); } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->privates = array(); + parent::reset(); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php index 17bbbfae714d4..004c7b8008be6 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php @@ -34,6 +34,15 @@ public function __construct() $this->aliases = array(); } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->privates = array(); + parent::reset(); + } + /** * {@inheritdoc} */ 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 3d47bac17eb80..f8f17c8577168 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -60,6 +60,15 @@ public function __construct() ); } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->privates = array(); + parent::reset(); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_array_params.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_array_params.php index d5f4f2ae9d886..b6931b99822b3 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_array_params.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_array_params.php @@ -41,6 +41,15 @@ public function __construct() $this->aliases = array(); } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->privates = array(); + parent::reset(); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_locator.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_locator.php index a413e1cfdc639..68fa5bcd136a4 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_locator.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_locator.php @@ -42,6 +42,15 @@ public function __construct() $this->aliases = array(); } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->privates = array(); + parent::reset(); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php index 7bd14e1608e27..329c2a4af1bda 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php @@ -36,6 +36,15 @@ public function __construct() $this->aliases = array(); } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->privates = array(); + parent::reset(); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php index aaaeaa45f6c09..fb63dee8a1adb 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php @@ -36,6 +36,15 @@ public function __construct() $this->aliases = array(); } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->privates = array(); + parent::reset(); + } + /** * {@inheritdoc} */