Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/dependency-injection/Compiler/AnalyzeServiceReferencesPass.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
10 */ | 10 */ |
11 | 11 |
12 namespace Symfony\Component\DependencyInjection\Compiler; | 12 namespace Symfony\Component\DependencyInjection\Compiler; |
13 | 13 |
14 use Symfony\Component\DependencyInjection\Argument\ArgumentInterface; | 14 use Symfony\Component\DependencyInjection\Argument\ArgumentInterface; |
15 use Symfony\Component\DependencyInjection\ContainerBuilder; | |
15 use Symfony\Component\DependencyInjection\ContainerInterface; | 16 use Symfony\Component\DependencyInjection\ContainerInterface; |
16 use Symfony\Component\DependencyInjection\Definition; | 17 use Symfony\Component\DependencyInjection\Definition; |
17 use Symfony\Component\DependencyInjection\Exception\RuntimeException; | 18 use Symfony\Component\DependencyInjection\Exception\RuntimeException; |
18 use Symfony\Component\DependencyInjection\ExpressionLanguage; | 19 use Symfony\Component\DependencyInjection\ExpressionLanguage; |
19 use Symfony\Component\DependencyInjection\Reference; | 20 use Symfony\Component\DependencyInjection\Reference; |
20 use Symfony\Component\DependencyInjection\ContainerBuilder; | |
21 use Symfony\Component\ExpressionLanguage\Expression; | 21 use Symfony\Component\ExpressionLanguage\Expression; |
22 | 22 |
23 /** | 23 /** |
24 * Run this pass before passes that need to know more about the relation of | 24 * Run this pass before passes that need to know more about the relation of |
25 * your services. | 25 * your services. |
32 class AnalyzeServiceReferencesPass extends AbstractRecursivePass implements RepeatablePassInterface | 32 class AnalyzeServiceReferencesPass extends AbstractRecursivePass implements RepeatablePassInterface |
33 { | 33 { |
34 private $graph; | 34 private $graph; |
35 private $currentDefinition; | 35 private $currentDefinition; |
36 private $onlyConstructorArguments; | 36 private $onlyConstructorArguments; |
37 private $hasProxyDumper; | |
37 private $lazy; | 38 private $lazy; |
38 private $expressionLanguage; | 39 private $expressionLanguage; |
40 private $byConstructor; | |
39 | 41 |
40 /** | 42 /** |
41 * @param bool $onlyConstructorArguments Sets this Service Reference pass to ignore method calls | 43 * @param bool $onlyConstructorArguments Sets this Service Reference pass to ignore method calls |
42 */ | 44 */ |
43 public function __construct($onlyConstructorArguments = false) | 45 public function __construct($onlyConstructorArguments = false, $hasProxyDumper = true) |
44 { | 46 { |
45 $this->onlyConstructorArguments = (bool) $onlyConstructorArguments; | 47 $this->onlyConstructorArguments = (bool) $onlyConstructorArguments; |
48 $this->hasProxyDumper = (bool) $hasProxyDumper; | |
46 } | 49 } |
47 | 50 |
48 /** | 51 /** |
49 * {@inheritdoc} | 52 * {@inheritdoc} |
50 */ | 53 */ |
60 { | 63 { |
61 $this->container = $container; | 64 $this->container = $container; |
62 $this->graph = $container->getCompiler()->getServiceReferenceGraph(); | 65 $this->graph = $container->getCompiler()->getServiceReferenceGraph(); |
63 $this->graph->clear(); | 66 $this->graph->clear(); |
64 $this->lazy = false; | 67 $this->lazy = false; |
68 $this->byConstructor = false; | |
65 | 69 |
66 foreach ($container->getAliases() as $id => $alias) { | 70 foreach ($container->getAliases() as $id => $alias) { |
67 $targetId = $this->getDefinitionId((string) $alias); | 71 $targetId = $this->getDefinitionId((string) $alias); |
68 $this->graph->connect($id, $alias, $targetId, $this->getDefinition($targetId), null); | 72 $this->graph->connect($id, $alias, $targetId, $this->getDefinition($targetId), null); |
69 } | 73 } |
81 $this->lazy = $lazy; | 85 $this->lazy = $lazy; |
82 | 86 |
83 return $value; | 87 return $value; |
84 } | 88 } |
85 if ($value instanceof Expression) { | 89 if ($value instanceof Expression) { |
86 $this->getExpressionLanguage()->compile((string) $value, array('this' => 'container')); | 90 $this->getExpressionLanguage()->compile((string) $value, ['this' => 'container']); |
87 | 91 |
88 return $value; | 92 return $value; |
89 } | 93 } |
90 if ($value instanceof Reference) { | 94 if ($value instanceof Reference) { |
91 $targetId = $this->getDefinitionId((string) $value); | 95 $targetId = $this->getDefinitionId((string) $value); |
95 $this->currentId, | 99 $this->currentId, |
96 $this->currentDefinition, | 100 $this->currentDefinition, |
97 $targetId, | 101 $targetId, |
98 $targetDefinition, | 102 $targetDefinition, |
99 $value, | 103 $value, |
100 $this->lazy || ($targetDefinition && $targetDefinition->isLazy()), | 104 $this->lazy || ($this->hasProxyDumper && $targetDefinition && $targetDefinition->isLazy()), |
101 ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior() | 105 ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior(), |
106 $this->byConstructor | |
102 ); | 107 ); |
103 | 108 |
104 return $value; | 109 return $value; |
105 } | 110 } |
106 if (!$value instanceof Definition) { | 111 if (!$value instanceof Definition) { |
109 if ($isRoot) { | 114 if ($isRoot) { |
110 if ($value->isSynthetic() || $value->isAbstract()) { | 115 if ($value->isSynthetic() || $value->isAbstract()) { |
111 return $value; | 116 return $value; |
112 } | 117 } |
113 $this->currentDefinition = $value; | 118 $this->currentDefinition = $value; |
119 } elseif ($this->currentDefinition === $value) { | |
120 return $value; | |
114 } | 121 } |
115 $this->lazy = false; | 122 $this->lazy = false; |
116 | 123 |
124 $byConstructor = $this->byConstructor; | |
125 $this->byConstructor = true; | |
117 $this->processValue($value->getFactory()); | 126 $this->processValue($value->getFactory()); |
118 $this->processValue($value->getArguments()); | 127 $this->processValue($value->getArguments()); |
128 $this->byConstructor = $byConstructor; | |
119 | 129 |
120 if (!$this->onlyConstructorArguments) { | 130 if (!$this->onlyConstructorArguments) { |
121 $this->processValue($value->getProperties()); | 131 $this->processValue($value->getProperties()); |
122 $this->processValue($value->getMethodCalls()); | 132 $this->processValue($value->getMethodCalls()); |
123 $this->processValue($value->getConfigurator()); | 133 $this->processValue($value->getConfigurator()); |