|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\DependencyInjection\Compiler; |
13 | 13 |
|
14 | | -use Symfony\Component\DependencyInjection\ChildDefinition; |
15 | | -use Symfony\Component\DependencyInjection\Definition; |
16 | | -use Symfony\Component\DependencyInjection\Exception\ExceptionInterface; |
17 | | -use Symfony\Component\DependencyInjection\Exception\RuntimeException; |
| 14 | +@trigger_error('The '.__NAMESPACE__.'\ResolveDefinitionTemplatesPass class is deprecated since version 3.4 and will be removed in 4.0. Use the ResolveChildDefinitionsPass class instead.', E_USER_DEPRECATED); |
18 | 15 |
|
19 | | -/** |
20 | | - * This replaces all ChildDefinition instances with their equivalent fully |
21 | | - * merged Definition instance. |
22 | | - * |
23 | | - * @author Johannes M. Schmitt <schmittjoh@gmail.com> |
24 | | - * @author Nicolas Grekas <p@tchwork.com> |
25 | | - */ |
26 | | -class ResolveDefinitionTemplatesPass extends AbstractRecursivePass |
27 | | -{ |
28 | | - protected function processValue($value, $isRoot = false) |
29 | | - { |
30 | | - if (!$value instanceof Definition) { |
31 | | - return parent::processValue($value, $isRoot); |
32 | | - } |
33 | | - if ($isRoot) { |
34 | | - // yes, we are specifically fetching the definition from the |
35 | | - // container to ensure we are not operating on stale data |
36 | | - $value = $this->container->getDefinition($this->currentId); |
37 | | - } |
38 | | - if ($value instanceof ChildDefinition) { |
39 | | - $value = $this->resolveDefinition($value); |
40 | | - if ($isRoot) { |
41 | | - $this->container->setDefinition($this->currentId, $value); |
42 | | - } |
43 | | - } |
44 | | - |
45 | | - return parent::processValue($value, $isRoot); |
46 | | - } |
| 16 | +class_exists(ResolveChildDefinitionsPass::class); |
47 | 17 |
|
| 18 | +if (false) { |
48 | 19 | /** |
49 | | - * Resolves the definition. |
| 20 | + * This definition decorates another definition. |
50 | 21 | * |
51 | | - * @return Definition |
| 22 | + * @author Johannes M. Schmitt <schmittjoh@gmail.com> |
52 | 23 | * |
53 | | - * @throws RuntimeException When the definition is invalid |
| 24 | + * @deprecated The ResolveDefinitionTemplatesPass class is deprecated since version 3.4 and will be removed in 4.0. Use the ResolveChildDefinitionsPass class instead. |
54 | 25 | */ |
55 | | - private function resolveDefinition(ChildDefinition $definition) |
| 26 | + class ResolveDefinitionTemplatesPass extends AbstractRecursivePass |
56 | 27 | { |
57 | | - try { |
58 | | - return $this->doResolveDefinition($definition); |
59 | | - } catch (ExceptionInterface $e) { |
60 | | - $r = new \ReflectionProperty($e, 'message'); |
61 | | - $r->setAccessible(true); |
62 | | - $r->setValue($e, sprintf('Service "%s": %s', $this->currentId, $e->getMessage())); |
63 | | - |
64 | | - throw $e; |
65 | | - } |
66 | | - } |
67 | | - |
68 | | - private function doResolveDefinition(ChildDefinition $definition) |
69 | | - { |
70 | | - if (!$this->container->has($parent = $definition->getParent())) { |
71 | | - throw new RuntimeException(sprintf('Parent definition "%s" does not exist.', $parent)); |
72 | | - } |
73 | | - |
74 | | - $parentDef = $this->container->findDefinition($parent); |
75 | | - if ($parentDef instanceof ChildDefinition) { |
76 | | - $id = $this->currentId; |
77 | | - $this->currentId = $parent; |
78 | | - $parentDef = $this->resolveDefinition($parentDef); |
79 | | - $this->container->setDefinition($parent, $parentDef); |
80 | | - $this->currentId = $id; |
81 | | - } |
82 | | - |
83 | | - $this->container->log($this, sprintf('Resolving inheritance for "%s" (parent: %s).', $this->currentId, $parent)); |
84 | | - $def = new Definition(); |
85 | | - |
86 | | - // merge in parent definition |
87 | | - // purposely ignored attributes: abstract, shared, tags, autoconfigured |
88 | | - $def->setClass($parentDef->getClass()); |
89 | | - $def->setArguments($parentDef->getArguments()); |
90 | | - $def->setMethodCalls($parentDef->getMethodCalls()); |
91 | | - $def->setProperties($parentDef->getProperties()); |
92 | | - if ($parentDef->getAutowiringTypes(false)) { |
93 | | - $def->setAutowiringTypes($parentDef->getAutowiringTypes(false)); |
94 | | - } |
95 | | - if ($parentDef->isDeprecated()) { |
96 | | - $def->setDeprecated(true, $parentDef->getDeprecationMessage('%service_id%')); |
97 | | - } |
98 | | - $def->setFactory($parentDef->getFactory()); |
99 | | - $def->setConfigurator($parentDef->getConfigurator()); |
100 | | - $def->setFile($parentDef->getFile()); |
101 | | - $def->setPublic($parentDef->isPublic()); |
102 | | - $def->setLazy($parentDef->isLazy()); |
103 | | - $def->setAutowired($parentDef->isAutowired()); |
104 | | - $def->setChanges($parentDef->getChanges()); |
105 | | - |
106 | | - $def->setBindings($parentDef->getBindings()); |
107 | | - |
108 | | - // overwrite with values specified in the decorator |
109 | | - $changes = $definition->getChanges(); |
110 | | - if (isset($changes['class'])) { |
111 | | - $def->setClass($definition->getClass()); |
112 | | - } |
113 | | - if (isset($changes['factory'])) { |
114 | | - $def->setFactory($definition->getFactory()); |
115 | | - } |
116 | | - if (isset($changes['configurator'])) { |
117 | | - $def->setConfigurator($definition->getConfigurator()); |
118 | | - } |
119 | | - if (isset($changes['file'])) { |
120 | | - $def->setFile($definition->getFile()); |
121 | | - } |
122 | | - if (isset($changes['public'])) { |
123 | | - $def->setPublic($definition->isPublic()); |
124 | | - } |
125 | | - if (isset($changes['lazy'])) { |
126 | | - $def->setLazy($definition->isLazy()); |
127 | | - } |
128 | | - if (isset($changes['deprecated'])) { |
129 | | - $def->setDeprecated($definition->isDeprecated(), $definition->getDeprecationMessage('%service_id%')); |
130 | | - } |
131 | | - if (isset($changes['autowired'])) { |
132 | | - $def->setAutowired($definition->isAutowired()); |
133 | | - } |
134 | | - if (isset($changes['shared'])) { |
135 | | - $def->setShared($definition->isShared()); |
136 | | - } |
137 | | - if (isset($changes['decorated_service'])) { |
138 | | - $decoratedService = $definition->getDecoratedService(); |
139 | | - if (null === $decoratedService) { |
140 | | - $def->setDecoratedService($decoratedService); |
141 | | - } else { |
142 | | - $def->setDecoratedService($decoratedService[0], $decoratedService[1], $decoratedService[2]); |
143 | | - } |
144 | | - } |
145 | | - |
146 | | - // merge arguments |
147 | | - foreach ($definition->getArguments() as $k => $v) { |
148 | | - if (is_numeric($k)) { |
149 | | - $def->addArgument($v); |
150 | | - } elseif (0 === strpos($k, 'index_')) { |
151 | | - $def->replaceArgument((int) substr($k, strlen('index_')), $v); |
152 | | - } else { |
153 | | - $def->setArgument($k, $v); |
154 | | - } |
155 | | - } |
156 | | - |
157 | | - // merge properties |
158 | | - foreach ($definition->getProperties() as $k => $v) { |
159 | | - $def->setProperty($k, $v); |
160 | | - } |
161 | | - |
162 | | - // append method calls |
163 | | - if ($calls = $definition->getMethodCalls()) { |
164 | | - $def->setMethodCalls(array_merge($def->getMethodCalls(), $calls)); |
165 | | - } |
166 | | - |
167 | | - // merge autowiring types |
168 | | - foreach ($definition->getAutowiringTypes(false) as $autowiringType) { |
169 | | - $def->addAutowiringType($autowiringType); |
170 | | - } |
171 | | - |
172 | | - // these attributes are always taken from the child |
173 | | - $def->setAbstract($definition->isAbstract()); |
174 | | - $def->setTags($definition->getTags()); |
175 | | - // autoconfigure is never taken from parent (on purpose) |
176 | | - // and it's not legal on an instanceof |
177 | | - $def->setAutoconfigured($definition->isAutoconfigured()); |
178 | | - |
179 | | - return $def; |
180 | 28 | } |
181 | 29 | } |
0 commit comments