Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/dependency-injection/Compiler/ResolveInstanceofConditionalsPass.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 |
---|---|
12 namespace Symfony\Component\DependencyInjection\Compiler; | 12 namespace Symfony\Component\DependencyInjection\Compiler; |
13 | 13 |
14 use Symfony\Component\DependencyInjection\ChildDefinition; | 14 use Symfony\Component\DependencyInjection\ChildDefinition; |
15 use Symfony\Component\DependencyInjection\ContainerBuilder; | 15 use Symfony\Component\DependencyInjection\ContainerBuilder; |
16 use Symfony\Component\DependencyInjection\Definition; | 16 use Symfony\Component\DependencyInjection\Definition; |
17 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; | |
17 use Symfony\Component\DependencyInjection\Exception\RuntimeException; | 18 use Symfony\Component\DependencyInjection\Exception\RuntimeException; |
18 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; | |
19 | 19 |
20 /** | 20 /** |
21 * Applies instanceof conditionals to definitions. | 21 * Applies instanceof conditionals to definitions. |
22 * | 22 * |
23 * @author Nicolas Grekas <p@tchwork.com> | 23 * @author Nicolas Grekas <p@tchwork.com> |
48 } | 48 } |
49 | 49 |
50 private function processDefinition(ContainerBuilder $container, $id, Definition $definition) | 50 private function processDefinition(ContainerBuilder $container, $id, Definition $definition) |
51 { | 51 { |
52 $instanceofConditionals = $definition->getInstanceofConditionals(); | 52 $instanceofConditionals = $definition->getInstanceofConditionals(); |
53 $autoconfiguredInstanceof = $definition->isAutoconfigured() ? $container->getAutoconfiguredInstanceof() : array(); | 53 $autoconfiguredInstanceof = $definition->isAutoconfigured() ? $container->getAutoconfiguredInstanceof() : []; |
54 if (!$instanceofConditionals && !$autoconfiguredInstanceof) { | 54 if (!$instanceofConditionals && !$autoconfiguredInstanceof) { |
55 return $definition; | 55 return $definition; |
56 } | 56 } |
57 | 57 |
58 if (!$class = $container->getParameterBag()->resolveValue($definition->getClass())) { | 58 if (!$class = $container->getParameterBag()->resolveValue($definition->getClass())) { |
59 return $definition; | 59 return $definition; |
60 } | 60 } |
61 | 61 |
62 $conditionals = $this->mergeConditionals($autoconfiguredInstanceof, $instanceofConditionals, $container); | 62 $conditionals = $this->mergeConditionals($autoconfiguredInstanceof, $instanceofConditionals, $container); |
63 | 63 |
64 $definition->setInstanceofConditionals(array()); | 64 $definition->setInstanceofConditionals([]); |
65 $parent = $shared = null; | 65 $parent = $shared = null; |
66 $instanceofTags = array(); | 66 $instanceofTags = []; |
67 | 67 |
68 foreach ($conditionals as $interface => $instanceofDefs) { | 68 foreach ($conditionals as $interface => $instanceofDefs) { |
69 if ($interface !== $class && (!$container->getReflectionClass($class, false))) { | 69 if ($interface !== $class && (!$container->getReflectionClass($class, false))) { |
70 continue; | 70 continue; |
71 } | 71 } |
79 $instanceofDef = clone $instanceofDef; | 79 $instanceofDef = clone $instanceofDef; |
80 $instanceofDef->setAbstract(true)->setParent($parent ?: 'abstract.instanceof.'.$id); | 80 $instanceofDef->setAbstract(true)->setParent($parent ?: 'abstract.instanceof.'.$id); |
81 $parent = 'instanceof.'.$interface.'.'.$key.'.'.$id; | 81 $parent = 'instanceof.'.$interface.'.'.$key.'.'.$id; |
82 $container->setDefinition($parent, $instanceofDef); | 82 $container->setDefinition($parent, $instanceofDef); |
83 $instanceofTags[] = $instanceofDef->getTags(); | 83 $instanceofTags[] = $instanceofDef->getTags(); |
84 $instanceofDef->setTags(array()); | 84 $instanceofDef->setTags([]); |
85 | 85 |
86 if (isset($instanceofDef->getChanges()['shared'])) { | 86 if (isset($instanceofDef->getChanges()['shared'])) { |
87 $shared = $instanceofDef->isShared(); | 87 $shared = $instanceofDef->isShared(); |
88 } | 88 } |
89 } | 89 } |
92 if ($parent) { | 92 if ($parent) { |
93 $bindings = $definition->getBindings(); | 93 $bindings = $definition->getBindings(); |
94 $abstract = $container->setDefinition('abstract.instanceof.'.$id, $definition); | 94 $abstract = $container->setDefinition('abstract.instanceof.'.$id, $definition); |
95 | 95 |
96 // cast Definition to ChildDefinition | 96 // cast Definition to ChildDefinition |
97 $definition->setBindings(array()); | 97 $definition->setBindings([]); |
98 $definition = serialize($definition); | 98 $definition = serialize($definition); |
99 $definition = substr_replace($definition, '53', 2, 2); | 99 $definition = substr_replace($definition, '53', 2, 2); |
100 $definition = substr_replace($definition, 'Child', 44, 0); | 100 $definition = substr_replace($definition, 'Child', 44, 0); |
101 $definition = unserialize($definition); | 101 $definition = unserialize($definition); |
102 $definition->setParent($parent); | 102 $definition->setParent($parent); |
103 | 103 |
104 if (null !== $shared && !isset($definition->getChanges()['shared'])) { | 104 if (null !== $shared && !isset($definition->getChanges()['shared'])) { |
105 $definition->setShared($shared); | 105 $definition->setShared($shared); |
106 } | 106 } |
107 | 107 |
108 $i = count($instanceofTags); | 108 $i = \count($instanceofTags); |
109 while (0 <= --$i) { | 109 while (0 <= --$i) { |
110 foreach ($instanceofTags[$i] as $k => $v) { | 110 foreach ($instanceofTags[$i] as $k => $v) { |
111 foreach ($v as $v) { | 111 foreach ($v as $v) { |
112 if ($definition->hasTag($k) && in_array($v, $definition->getTag($k))) { | 112 if ($definition->hasTag($k) && \in_array($v, $definition->getTag($k))) { |
113 continue; | 113 continue; |
114 } | 114 } |
115 $definition->addTag($k, $v); | 115 $definition->addTag($k, $v); |
116 } | 116 } |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 $definition->setBindings($bindings); | |
121 | |
120 // reset fields with "merge" behavior | 122 // reset fields with "merge" behavior |
121 $abstract | 123 $abstract |
122 ->setBindings($bindings) | 124 ->setBindings([]) |
123 ->setArguments(array()) | 125 ->setArguments([]) |
124 ->setMethodCalls(array()) | 126 ->setMethodCalls([]) |
125 ->setDecoratedService(null) | 127 ->setDecoratedService(null) |
126 ->setTags(array()) | 128 ->setTags([]) |
127 ->setAbstract(true); | 129 ->setAbstract(true); |
128 } | 130 } |
129 | 131 |
130 return $definition; | 132 return $definition; |
131 } | 133 } |
132 | 134 |
133 private function mergeConditionals(array $autoconfiguredInstanceof, array $instanceofConditionals, ContainerBuilder $container) | 135 private function mergeConditionals(array $autoconfiguredInstanceof, array $instanceofConditionals, ContainerBuilder $container) |
134 { | 136 { |
135 // make each value an array of ChildDefinition | 137 // make each value an array of ChildDefinition |
136 $conditionals = array_map(function ($childDef) { return array($childDef); }, $autoconfiguredInstanceof); | 138 $conditionals = array_map(function ($childDef) { return [$childDef]; }, $autoconfiguredInstanceof); |
137 | 139 |
138 foreach ($instanceofConditionals as $interface => $instanceofDef) { | 140 foreach ($instanceofConditionals as $interface => $instanceofDef) { |
139 // make sure the interface/class exists (but don't validate automaticInstanceofConditionals) | 141 // make sure the interface/class exists (but don't validate automaticInstanceofConditionals) |
140 if (!$container->getReflectionClass($interface)) { | 142 if (!$container->getReflectionClass($interface)) { |
141 throw new RuntimeException(sprintf('"%s" is set as an "instanceof" conditional, but it does not exist.', $interface)); | 143 throw new RuntimeException(sprintf('"%s" is set as an "instanceof" conditional, but it does not exist.', $interface)); |
142 } | 144 } |
143 | 145 |
144 if (!isset($autoconfiguredInstanceof[$interface])) { | 146 if (!isset($autoconfiguredInstanceof[$interface])) { |
145 $conditionals[$interface] = array(); | 147 $conditionals[$interface] = []; |
146 } | 148 } |
147 | 149 |
148 $conditionals[$interface][] = $instanceofDef; | 150 $conditionals[$interface][] = $instanceofDef; |
149 } | 151 } |
150 | 152 |