From 4ea115b44968a30ea6b2d02049c02205d29447cc Mon Sep 17 00:00:00 2001 From: klemens Date: Sat, 11 Feb 2017 12:12:36 +0100 Subject: [PATCH 1/3] spelling fixes --- Compiler/ReplaceAliasByActualDefinitionPass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Compiler/ReplaceAliasByActualDefinitionPass.php b/Compiler/ReplaceAliasByActualDefinitionPass.php index 5c58656a5..b7210ee6e 100644 --- a/Compiler/ReplaceAliasByActualDefinitionPass.php +++ b/Compiler/ReplaceAliasByActualDefinitionPass.php @@ -51,7 +51,7 @@ public function process(ContainerBuilder $container) if (isset($replacements[$targetId])) { $container->setAlias($definitionId, $replacements[$targetId]); } - // No neeed to process the same target twice + // No need to process the same target twice if (isset($seenAliasTargets[$targetId])) { continue; } From 60ffc6063fe726cbfeaf60f040b4296f8e7311c6 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 14 Feb 2017 10:20:20 +0100 Subject: [PATCH 2/3] [DI] Align AutowirePass with 2.8 --- Compiler/AutowirePass.php | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/Compiler/AutowirePass.php b/Compiler/AutowirePass.php index fcb986383..985f3a50e 100644 --- a/Compiler/AutowirePass.php +++ b/Compiler/AutowirePass.php @@ -217,26 +217,24 @@ private function set($type, $id) // is this already a type/class that is known to match multiple services? if (isset($this->ambiguousServiceTypes[$type])) { - $this->addServiceToAmbiguousType($id, $type); + $this->ambiguousServiceTypes[$type][] = $id; return; } // check to make sure the type doesn't match multiple services - if (isset($this->types[$type])) { - if ($this->types[$type] === $id) { - return; - } - - // keep an array of all services matching this type - $this->addServiceToAmbiguousType($id, $type); - - unset($this->types[$type]); + if (!isset($this->types[$type]) || $this->types[$type] === $id) { + $this->types[$type] = $id; return; } - $this->types[$type] = $id; + // keep an array of all services matching this type + if (!isset($this->ambiguousServiceTypes[$type])) { + $this->ambiguousServiceTypes[$type] = array($this->types[$type]); + unset($this->types[$type]); + } + $this->ambiguousServiceTypes[$type][] = $id; } /** @@ -311,17 +309,6 @@ private function getReflectionClass($id, Definition $definition) return $this->reflectionClasses[$id] = $reflector; } - private function addServiceToAmbiguousType($id, $type) - { - // keep an array of all services matching this type - if (!isset($this->ambiguousServiceTypes[$type])) { - $this->ambiguousServiceTypes[$type] = array( - $this->types[$type], - ); - } - $this->ambiguousServiceTypes[$type][] = $id; - } - /** * @param \ReflectionClass $reflectionClass * From df7f2af9aad6ef2106c55edc8970396ac6c12fa2 Mon Sep 17 00:00:00 2001 From: Titouan Galopin Date: Tue, 14 Feb 2017 12:35:48 +0100 Subject: [PATCH 3/3] Improve tracking of environment variables in the case of private services --- Compiler/RemoveUnusedDefinitionsPass.php | 1 + .../RemoveUnusedDefinitionsPassTest.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Compiler/RemoveUnusedDefinitionsPass.php b/Compiler/RemoveUnusedDefinitionsPass.php index 9e18a9ebd..8252f73f6 100644 --- a/Compiler/RemoveUnusedDefinitionsPass.php +++ b/Compiler/RemoveUnusedDefinitionsPass.php @@ -72,6 +72,7 @@ public function process(ContainerBuilder $container) $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'replaces alias '.reset($referencingAliases))); } elseif (0 === count($referencingAliases) && false === $isReferenced) { $container->removeDefinition($id); + $container->resolveEnvPlaceholders(serialize($definition)); $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'unused')); $hasChanged = true; } diff --git a/Tests/Compiler/RemoveUnusedDefinitionsPassTest.php b/Tests/Compiler/RemoveUnusedDefinitionsPassTest.php index 82149ebdb..cd51a0b29 100644 --- a/Tests/Compiler/RemoveUnusedDefinitionsPassTest.php +++ b/Tests/Compiler/RemoveUnusedDefinitionsPassTest.php @@ -14,6 +14,7 @@ use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass; use Symfony\Component\DependencyInjection\Compiler\RepeatedPass; use Symfony\Component\DependencyInjection\Compiler\RemoveUnusedDefinitionsPass; +use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -105,6 +106,28 @@ public function testProcessWontRemovePrivateFactory() $this->assertTrue($container->hasDefinition('foobar')); } + public function testProcessConsiderEnvVariablesAsUsedEvenInPrivateServices() + { + $container = new ContainerBuilder(); + $container->setParameter('env(FOOBAR)', 'test'); + $container + ->register('foo') + ->setArguments(array('%env(FOOBAR)%')) + ->setPublic(false) + ; + + $resolvePass = new ResolveParameterPlaceHoldersPass(); + $resolvePass->process($container); + + $this->process($container); + + $this->assertFalse($container->hasDefinition('foo')); + + $envCounters = $container->getEnvCounters(); + $this->assertArrayHasKey('FOOBAR', $envCounters); + $this->assertSame(1, $envCounters['FOOBAR']); + } + protected function process(ContainerBuilder $container) { $repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new RemoveUnusedDefinitionsPass()));