Chris@14
|
1 <?php
|
Chris@14
|
2
|
Chris@14
|
3 /*
|
Chris@14
|
4 * This file is part of the Symfony package.
|
Chris@14
|
5 *
|
Chris@14
|
6 * (c) Fabien Potencier <fabien@symfony.com>
|
Chris@14
|
7 *
|
Chris@14
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@14
|
9 * file that was distributed with this source code.
|
Chris@14
|
10 */
|
Chris@14
|
11
|
Chris@14
|
12 namespace Symfony\Component\DependencyInjection\Compiler;
|
Chris@14
|
13
|
Chris@14
|
14 use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
|
Chris@14
|
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
|
Chris@14
|
16 use Symfony\Component\DependencyInjection\Definition;
|
Chris@14
|
17 use Symfony\Component\DependencyInjection\Reference;
|
Chris@14
|
18
|
Chris@14
|
19 /**
|
Chris@14
|
20 * Propagate "container.hot_path" tags to referenced services.
|
Chris@14
|
21 *
|
Chris@14
|
22 * @author Nicolas Grekas <p@tchwork.com>
|
Chris@14
|
23 */
|
Chris@14
|
24 class ResolveHotPathPass extends AbstractRecursivePass
|
Chris@14
|
25 {
|
Chris@14
|
26 private $tagName;
|
Chris@17
|
27 private $resolvedIds = [];
|
Chris@14
|
28
|
Chris@14
|
29 public function __construct($tagName = 'container.hot_path')
|
Chris@14
|
30 {
|
Chris@14
|
31 $this->tagName = $tagName;
|
Chris@14
|
32 }
|
Chris@14
|
33
|
Chris@14
|
34 /**
|
Chris@14
|
35 * {@inheritdoc}
|
Chris@14
|
36 */
|
Chris@14
|
37 public function process(ContainerBuilder $container)
|
Chris@14
|
38 {
|
Chris@14
|
39 try {
|
Chris@14
|
40 parent::process($container);
|
Chris@14
|
41 $container->getDefinition('service_container')->clearTag($this->tagName);
|
Chris@14
|
42 } finally {
|
Chris@17
|
43 $this->resolvedIds = [];
|
Chris@14
|
44 }
|
Chris@14
|
45 }
|
Chris@14
|
46
|
Chris@14
|
47 /**
|
Chris@14
|
48 * {@inheritdoc}
|
Chris@14
|
49 */
|
Chris@14
|
50 protected function processValue($value, $isRoot = false)
|
Chris@14
|
51 {
|
Chris@14
|
52 if ($value instanceof ArgumentInterface) {
|
Chris@14
|
53 return $value;
|
Chris@14
|
54 }
|
Chris@14
|
55 if ($value instanceof Definition && $isRoot && (isset($this->resolvedIds[$this->currentId]) || !$value->hasTag($this->tagName) || $value->isDeprecated())) {
|
Chris@14
|
56 return $value->isDeprecated() ? $value->clearTag($this->tagName) : $value;
|
Chris@14
|
57 }
|
Chris@14
|
58 if ($value instanceof Reference && ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE !== $value->getInvalidBehavior() && $this->container->has($id = $this->container->normalizeId($value))) {
|
Chris@14
|
59 $definition = $this->container->findDefinition($id);
|
Chris@14
|
60 if (!$definition->hasTag($this->tagName) && !$definition->isDeprecated()) {
|
Chris@14
|
61 $this->resolvedIds[$id] = true;
|
Chris@14
|
62 $definition->addTag($this->tagName);
|
Chris@14
|
63 parent::processValue($definition, false);
|
Chris@14
|
64 }
|
Chris@14
|
65
|
Chris@14
|
66 return $value;
|
Chris@14
|
67 }
|
Chris@14
|
68
|
Chris@14
|
69 return parent::processValue($value, $isRoot);
|
Chris@14
|
70 }
|
Chris@14
|
71 }
|