4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Compiler;
14 use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
16 use Symfony\Component\DependencyInjection\Definition;
17 use Symfony\Component\DependencyInjection\Reference;
20 * Propagate "container.hot_path" tags to referenced services.
22 * @author Nicolas Grekas <p@tchwork.com>
24 class ResolveHotPathPass extends AbstractRecursivePass
27 private $resolvedIds = array();
29 public function __construct($tagName = 'container.hot_path')
31 $this->tagName = $tagName;
37 public function process(ContainerBuilder $container)
40 parent::process($container);
41 $container->getDefinition('service_container')->clearTag($this->tagName);
43 $this->resolvedIds = array();
50 protected function processValue($value, $isRoot = false)
52 if ($value instanceof ArgumentInterface) {
55 if ($value instanceof Definition && $isRoot && (isset($this->resolvedIds[$this->currentId]) || !$value->hasTag($this->tagName) || $value->isDeprecated())) {
56 return $value->isDeprecated() ? $value->clearTag($this->tagName) : $value;
58 if ($value instanceof Reference && ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE !== $value->getInvalidBehavior() && $this->container->has($id = $this->container->normalizeId($value))) {
59 $definition = $this->container->findDefinition($id);
60 if (!$definition->hasTag($this->tagName) && !$definition->isDeprecated()) {
61 $this->resolvedIds[$id] = true;
62 $definition->addTag($this->tagName);
63 parent::processValue($definition, false);
69 return parent::processValue($value, $isRoot);