Mercurial > hg > isophonics-drupal-site
diff vendor/symfony/dependency-injection/Compiler/AnalyzeServiceReferencesPass.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 7a779792577d |
children | 129ea1e6d783 |
line wrap: on
line diff
--- a/vendor/symfony/dependency-injection/Compiler/AnalyzeServiceReferencesPass.php Mon Apr 23 09:33:26 2018 +0100 +++ b/vendor/symfony/dependency-injection/Compiler/AnalyzeServiceReferencesPass.php Mon Apr 23 09:46:53 2018 +0100 @@ -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 @@ * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ -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 @@ */ 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; - } - - $this->currentId = $id; - $this->currentDefinition = $definition; - - $this->processArguments($definition->getArguments()); - if (is_array($definition->getFactory())) { - $this->processArguments($definition->getFactory()); - } - - if (!$this->onlyConstructorArguments) { - $this->processArguments($definition->getMethodCalls()); - $this->processArguments($definition->getProperties()); - if ($definition->getConfigurator()) { - $this->processArguments(array($definition->getConfigurator())); - } - } + foreach ($container->getAliases() as $id => $alias) { + $targetId = $this->getDefinitionId((string) $alias); + $this->graph->connect($id, $alias, $targetId, $this->getDefinition($targetId), null); } - foreach ($container->getAliases() as $id => $alias) { - $this->graph->connect($id, $alias, (string) $alias, $this->getDefinition((string) $alias), null); - } + parent::process($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) + protected function processValue($value, $isRoot = false) { - 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()); + $lazy = $this->lazy; - if (is_array($argument->getFactory())) { - $this->processArguments($argument->getFactory()); - } + if ($value instanceof ArgumentInterface) { + $this->lazy = true; + parent::processValue($value->getValues()); + $this->lazy = $lazy; + + return $value; + } + if ($value instanceof Expression) { + $this->getExpressionLanguage()->compile((string) $value, array('this' => 'container')); + + 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 @@ */ private function getDefinition($id) { - $id = $this->getDefinitionId($id); - return null === $id ? null : $this->container->getDefinition($id); } @@ -146,21 +149,26 @@ 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) ); }