X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fsymfony%2Fdependency-injection%2FCompiler%2FInlineServiceDefinitionsPass.php;fp=vendor%2Fsymfony%2Fdependency-injection%2FCompiler%2FInlineServiceDefinitionsPass.php;h=c64348ed1de3bbb62cd509aa9a590c5f5b9219ed;hp=3bec493e9184814401d84d5a8371c79fa64b0bc4;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/symfony/dependency-injection/Compiler/InlineServiceDefinitionsPass.php b/vendor/symfony/dependency-injection/Compiler/InlineServiceDefinitionsPass.php index 3bec493e9..c64348ed1 100644 --- a/vendor/symfony/dependency-injection/Compiler/InlineServiceDefinitionsPass.php +++ b/vendor/symfony/dependency-injection/Compiler/InlineServiceDefinitionsPass.php @@ -11,111 +11,110 @@ namespace Symfony\Component\DependencyInjection\Compiler; +use Symfony\Component\DependencyInjection\Argument\ArgumentInterface; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * Inline service definitions where this is possible. * * @author Johannes M. Schmitt */ -class InlineServiceDefinitionsPass implements RepeatablePassInterface +class InlineServiceDefinitionsPass extends AbstractRecursivePass implements RepeatablePassInterface { - private $repeatedPass; - private $graph; - private $compiler; - private $formatter; - private $currentId; + private $cloningIds = array(); + private $inlinedServiceIds = array(); /** * {@inheritdoc} */ public function setRepeatedPass(RepeatedPass $repeatedPass) { - $this->repeatedPass = $repeatedPass; + // no-op for BC } /** - * Processes the ContainerBuilder for inline service definitions. + * Returns an array of all services inlined by this pass. * - * @param ContainerBuilder $container + * The key is the inlined service id and its value is the list of services it was inlined into. + * + * @deprecated since version 3.4, to be removed in 4.0. + * + * @return array */ - public function process(ContainerBuilder $container) + public function getInlinedServiceIds() { - $this->compiler = $container->getCompiler(); - $this->formatter = $this->compiler->getLoggingFormatter(); - $this->graph = $this->compiler->getServiceReferenceGraph(); + @trigger_error('Calling InlineServiceDefinitionsPass::getInlinedServiceIds() is deprecated since Symfony 3.4 and will be removed in 4.0.', E_USER_DEPRECATED); - $container->setDefinitions($this->inlineArguments($container, $container->getDefinitions(), true)); + return $this->inlinedServiceIds; } /** - * Processes inline arguments. - * - * @param ContainerBuilder $container The ContainerBuilder - * @param array $arguments An array of arguments - * @param bool $isRoot If we are processing the root definitions or not - * - * @return array + * {@inheritdoc} */ - private function inlineArguments(ContainerBuilder $container, array $arguments, $isRoot = false) + protected function processValue($value, $isRoot = false) { - foreach ($arguments as $k => $argument) { - if ($isRoot) { - $this->currentId = $k; - } - if (is_array($argument)) { - $arguments[$k] = $this->inlineArguments($container, $argument); - } elseif ($argument instanceof Reference) { - if (!$container->hasDefinition($id = (string) $argument)) { - continue; - } - - if ($this->isInlineableDefinition($id, $definition = $container->getDefinition($id))) { - $this->compiler->addLogMessage($this->formatter->formatInlineService($this, $id, $this->currentId)); - - if ($definition->isShared()) { - $arguments[$k] = $definition; - } else { - $arguments[$k] = clone $definition; - } - } - } elseif ($argument instanceof Definition) { - $argument->setArguments($this->inlineArguments($container, $argument->getArguments())); - $argument->setMethodCalls($this->inlineArguments($container, $argument->getMethodCalls())); - $argument->setProperties($this->inlineArguments($container, $argument->getProperties())); - - $configurator = $this->inlineArguments($container, array($argument->getConfigurator())); - $argument->setConfigurator($configurator[0]); - - $factory = $this->inlineArguments($container, array($argument->getFactory())); - $argument->setFactory($factory[0]); + if ($value instanceof ArgumentInterface) { + // Reference found in ArgumentInterface::getValues() are not inlineable + return $value; + } + + if ($value instanceof Definition && $this->cloningIds) { + if ($value->isShared()) { + return $value; } + $value = clone $value; + } + + if (!$value instanceof Reference || !$this->container->hasDefinition($id = $this->container->normalizeId($value))) { + return parent::processValue($value, $isRoot); } - return $arguments; + $definition = $this->container->getDefinition($id); + + if (!$this->isInlineableDefinition($id, $definition, $this->container->getCompiler()->getServiceReferenceGraph())) { + return $value; + } + + $this->container->log($this, sprintf('Inlined service "%s" to "%s".', $id, $this->currentId)); + $this->inlinedServiceIds[$id][] = $this->currentId; + + if ($definition->isShared()) { + return $definition; + } + + if (isset($this->cloningIds[$id])) { + $ids = array_keys($this->cloningIds); + $ids[] = $id; + + throw new ServiceCircularReferenceException($id, array_slice($ids, array_search($id, $ids))); + } + + $this->cloningIds[$id] = true; + try { + return $this->processValue($definition); + } finally { + unset($this->cloningIds[$id]); + } } /** * Checks if the definition is inlineable. * - * @param string $id - * @param Definition $definition - * * @return bool If the definition is inlineable */ - private function isInlineableDefinition($id, Definition $definition) + private function isInlineableDefinition($id, Definition $definition, ServiceReferenceGraph $graph) { if (!$definition->isShared()) { return true; } - if ($definition->isDeprecated() || $definition->isPublic() || $definition->isLazy()) { + if ($definition->isDeprecated() || $definition->isPublic() || $definition->isPrivate() || $definition->isLazy()) { return false; } - if (!$this->graph->hasNode($id)) { + if (!$graph->hasNode($id)) { return true; } @@ -124,7 +123,10 @@ class InlineServiceDefinitionsPass implements RepeatablePassInterface } $ids = array(); - foreach ($this->graph->getNode($id)->getInEdges() as $edge) { + foreach ($graph->getNode($id)->getInEdges() as $edge) { + if ($edge->isWeak()) { + return false; + } $ids[] = $edge->getSourceNode()->getId(); }