X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fsymfony%2Fdependency-injection%2FCompiler%2FAnalyzeServiceReferencesPass.php;fp=vendor%2Fsymfony%2Fdependency-injection%2FCompiler%2FAnalyzeServiceReferencesPass.php;h=296051302d9e3f8b185889d6730a6df3db0a840a;hp=68b2a0217263cff3c8675eaa89e71ab1a3fcb26d;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/symfony/dependency-injection/Compiler/AnalyzeServiceReferencesPass.php b/vendor/symfony/dependency-injection/Compiler/AnalyzeServiceReferencesPass.php index 68b2a0217..296051302 100644 --- a/vendor/symfony/dependency-injection/Compiler/AnalyzeServiceReferencesPass.php +++ b/vendor/symfony/dependency-injection/Compiler/AnalyzeServiceReferencesPass.php @@ -11,7 +11,10 @@ namespace Symfony\Component\DependencyInjection\Compiler; +use Symfony\Component\DependencyInjection\Argument\ArgumentInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\ExpressionLanguage; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -26,14 +29,12 @@ use Symfony\Component\ExpressionLanguage\Expression; * * @author Johannes M. Schmitt */ -class AnalyzeServiceReferencesPass implements RepeatablePassInterface +class AnalyzeServiceReferencesPass extends AbstractRecursivePass implements RepeatablePassInterface { private $graph; - private $container; - private $currentId; private $currentDefinition; - private $repeatedPass; private $onlyConstructorArguments; + private $lazy; private $expressionLanguage; /** @@ -49,77 +50,81 @@ class AnalyzeServiceReferencesPass implements RepeatablePassInterface */ public function setRepeatedPass(RepeatedPass $repeatedPass) { - $this->repeatedPass = $repeatedPass; + // no-op for BC } /** * Processes a ContainerBuilder object to populate the service reference graph. - * - * @param ContainerBuilder $container */ public function process(ContainerBuilder $container) { $this->container = $container; $this->graph = $container->getCompiler()->getServiceReferenceGraph(); $this->graph->clear(); + $this->lazy = false; - foreach ($container->getDefinitions() as $id => $definition) { - if ($definition->isSynthetic() || $definition->isAbstract()) { - continue; - } + foreach ($container->getAliases() as $id => $alias) { + $targetId = $this->getDefinitionId((string) $alias); + $this->graph->connect($id, $alias, $targetId, $this->getDefinition($targetId), null); + } - $this->currentId = $id; - $this->currentDefinition = $definition; + parent::process($container); + } - $this->processArguments($definition->getArguments()); - if (is_array($definition->getFactory())) { - $this->processArguments($definition->getFactory()); - } + protected function processValue($value, $isRoot = false) + { + $lazy = $this->lazy; - if (!$this->onlyConstructorArguments) { - $this->processArguments($definition->getMethodCalls()); - $this->processArguments($definition->getProperties()); - if ($definition->getConfigurator()) { - $this->processArguments(array($definition->getConfigurator())); - } - } - } + if ($value instanceof ArgumentInterface) { + $this->lazy = true; + parent::processValue($value->getValues()); + $this->lazy = $lazy; - foreach ($container->getAliases() as $id => $alias) { - $this->graph->connect($id, $alias, (string) $alias, $this->getDefinition((string) $alias), null); + return $value; } - } + if ($value instanceof Expression) { + $this->getExpressionLanguage()->compile((string) $value, array('this' => 'container')); - /** - * Processes service definitions for arguments to find relationships for the service graph. - * - * @param array $arguments An array of Reference or Definition objects relating to service definitions - */ - private function processArguments(array $arguments) - { - foreach ($arguments as $argument) { - if (is_array($argument)) { - $this->processArguments($argument); - } elseif ($argument instanceof Expression) { - $this->getExpressionLanguage()->compile((string) $argument, array('this' => 'container')); - } elseif ($argument instanceof Reference) { - $this->graph->connect( - $this->currentId, - $this->currentDefinition, - $this->getDefinitionId((string) $argument), - $this->getDefinition((string) $argument), - $argument - ); - } elseif ($argument instanceof Definition) { - $this->processArguments($argument->getArguments()); - $this->processArguments($argument->getMethodCalls()); - $this->processArguments($argument->getProperties()); - - if (is_array($argument->getFactory())) { - $this->processArguments($argument->getFactory()); - } + return $value; + } + if ($value instanceof Reference) { + $targetId = $this->getDefinitionId((string) $value); + $targetDefinition = $this->getDefinition($targetId); + + $this->graph->connect( + $this->currentId, + $this->currentDefinition, + $targetId, + $targetDefinition, + $value, + $this->lazy || ($targetDefinition && $targetDefinition->isLazy()), + ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior() + ); + + return $value; + } + if (!$value instanceof Definition) { + return parent::processValue($value, $isRoot); + } + if ($isRoot) { + if ($value->isSynthetic() || $value->isAbstract()) { + return $value; } + $this->currentDefinition = $value; } + $this->lazy = false; + + $this->processValue($value->getFactory()); + $this->processValue($value->getArguments()); + + if (!$this->onlyConstructorArguments) { + $this->processValue($value->getProperties()); + $this->processValue($value->getMethodCalls()); + $this->processValue($value->getConfigurator()); + } + $this->lazy = $lazy; + + return $value; } /** @@ -131,8 +136,6 @@ class AnalyzeServiceReferencesPass implements RepeatablePassInterface */ private function getDefinition($id) { - $id = $this->getDefinitionId($id); - return null === $id ? null : $this->container->getDefinition($id); } @@ -146,21 +149,26 @@ class AnalyzeServiceReferencesPass implements RepeatablePassInterface return; } - return $id; + return $this->container->normalizeId($id); } private function getExpressionLanguage() { if (null === $this->expressionLanguage) { + if (!class_exists(ExpressionLanguage::class)) { + throw new RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); + } + $providers = $this->container->getExpressionLanguageProviders(); $this->expressionLanguage = new ExpressionLanguage(null, $providers, function ($arg) { if ('""' === substr_replace($arg, '', 1, -1)) { $id = stripcslashes(substr($arg, 1, -1)); + $id = $this->getDefinitionId($id); $this->graph->connect( $this->currentId, $this->currentDefinition, - $this->getDefinitionId($id), + $id, $this->getDefinition($id) ); }