comparison vendor/symfony/dependency-injection/Dumper/XmlDumper.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 7a779792577d
children 129ea1e6d783
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
9 * file that was distributed with this source code. 9 * file that was distributed with this source code.
10 */ 10 */
11 11
12 namespace Symfony\Component\DependencyInjection\Dumper; 12 namespace Symfony\Component\DependencyInjection\Dumper;
13 13
14 use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
15 use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
16 use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
14 use Symfony\Component\DependencyInjection\ContainerInterface; 17 use Symfony\Component\DependencyInjection\ContainerInterface;
15 use Symfony\Component\DependencyInjection\Parameter; 18 use Symfony\Component\DependencyInjection\Parameter;
16 use Symfony\Component\DependencyInjection\Reference; 19 use Symfony\Component\DependencyInjection\Reference;
17 use Symfony\Component\DependencyInjection\Definition; 20 use Symfony\Component\DependencyInjection\Definition;
18 use Symfony\Component\DependencyInjection\Alias; 21 use Symfony\Component\DependencyInjection\Alias;
33 private $document; 36 private $document;
34 37
35 /** 38 /**
36 * Dumps the service container as an XML string. 39 * Dumps the service container as an XML string.
37 * 40 *
38 * @param array $options An array of options
39 *
40 * @return string An xml string representing of the service container 41 * @return string An xml string representing of the service container
41 */ 42 */
42 public function dump(array $options = array()) 43 public function dump(array $options = array())
43 { 44 {
44 $this->document = new \DOMDocument('1.0', 'utf-8'); 45 $this->document = new \DOMDocument('1.0', 'utf-8');
56 $this->document = null; 57 $this->document = null;
57 58
58 return $this->container->resolveEnvPlaceholders($xml); 59 return $this->container->resolveEnvPlaceholders($xml);
59 } 60 }
60 61
61 /**
62 * Adds parameters.
63 *
64 * @param \DOMElement $parent
65 */
66 private function addParameters(\DOMElement $parent) 62 private function addParameters(\DOMElement $parent)
67 { 63 {
68 $data = $this->container->getParameterBag()->all(); 64 $data = $this->container->getParameterBag()->all();
69 if (!$data) { 65 if (!$data) {
70 return; 66 return;
71 } 67 }
72 68
73 if ($this->container->isFrozen()) { 69 if ($this->container->isCompiled()) {
74 $data = $this->escape($data); 70 $data = $this->escape($data);
75 } 71 }
76 72
77 $parameters = $this->document->createElement('parameters'); 73 $parameters = $this->document->createElement('parameters');
78 $parent->appendChild($parameters); 74 $parent->appendChild($parameters);
79 $this->convertParameters($data, 'parameter', $parameters); 75 $this->convertParameters($data, 'parameter', $parameters);
80 } 76 }
81 77
82 /**
83 * Adds method calls.
84 *
85 * @param array $methodcalls
86 * @param \DOMElement $parent
87 */
88 private function addMethodCalls(array $methodcalls, \DOMElement $parent) 78 private function addMethodCalls(array $methodcalls, \DOMElement $parent)
89 { 79 {
90 foreach ($methodcalls as $methodcall) { 80 foreach ($methodcalls as $methodcall) {
91 $call = $this->document->createElement('call'); 81 $call = $this->document->createElement('call');
92 $call->setAttribute('method', $methodcall[0]); 82 $call->setAttribute('method', $methodcall[0]);
118 $service->setAttribute('class', $class); 108 $service->setAttribute('class', $class);
119 } 109 }
120 if (!$definition->isShared()) { 110 if (!$definition->isShared()) {
121 $service->setAttribute('shared', 'false'); 111 $service->setAttribute('shared', 'false');
122 } 112 }
123 if (!$definition->isPublic()) { 113 if (!$definition->isPrivate()) {
124 $service->setAttribute('public', 'false'); 114 $service->setAttribute('public', $definition->isPublic() ? 'true' : 'false');
125 } 115 }
126 if ($definition->isSynthetic()) { 116 if ($definition->isSynthetic()) {
127 $service->setAttribute('synthetic', 'true'); 117 $service->setAttribute('synthetic', 'true');
128 } 118 }
129 if ($definition->isLazy()) { 119 if ($definition->isLazy()) {
172 162
173 if (is_array($callable) && $callable[0] instanceof Definition) { 163 if (is_array($callable) && $callable[0] instanceof Definition) {
174 $this->addService($callable[0], null, $factory); 164 $this->addService($callable[0], null, $factory);
175 $factory->setAttribute('method', $callable[1]); 165 $factory->setAttribute('method', $callable[1]);
176 } elseif (is_array($callable)) { 166 } elseif (is_array($callable)) {
177 $factory->setAttribute($callable[0] instanceof Reference ? 'service' : 'class', $callable[0]); 167 if (null !== $callable[0]) {
168 $factory->setAttribute($callable[0] instanceof Reference ? 'service' : 'class', $callable[0]);
169 }
178 $factory->setAttribute('method', $callable[1]); 170 $factory->setAttribute('method', $callable[1]);
179 } else { 171 } else {
180 $factory->setAttribute('function', $callable); 172 $factory->setAttribute('function', $callable);
181 } 173 }
182 $service->appendChild($factory); 174 $service->appendChild($factory);
191 183
192 if ($definition->isAutowired()) { 184 if ($definition->isAutowired()) {
193 $service->setAttribute('autowire', 'true'); 185 $service->setAttribute('autowire', 'true');
194 } 186 }
195 187
196 foreach ($definition->getAutowiringTypes() as $autowiringTypeValue) { 188 foreach ($definition->getAutowiringTypes(false) as $autowiringTypeValue) {
197 $autowiringType = $this->document->createElement('autowiring-type'); 189 $autowiringType = $this->document->createElement('autowiring-type');
198 $autowiringType->appendChild($this->document->createTextNode($autowiringTypeValue)); 190 $autowiringType->appendChild($this->document->createTextNode($autowiringTypeValue));
199 191
200 $service->appendChild($autowiringType); 192 $service->appendChild($autowiringType);
193 }
194
195 if ($definition->isAutoconfigured()) {
196 $service->setAttribute('autoconfigure', 'true');
201 } 197 }
202 198
203 if ($definition->isAbstract()) { 199 if ($definition->isAbstract()) {
204 $service->setAttribute('abstract', 'true'); 200 $service->setAttribute('abstract', 'true');
205 } 201 }
232 private function addServiceAlias($alias, Alias $id, \DOMElement $parent) 228 private function addServiceAlias($alias, Alias $id, \DOMElement $parent)
233 { 229 {
234 $service = $this->document->createElement('service'); 230 $service = $this->document->createElement('service');
235 $service->setAttribute('id', $alias); 231 $service->setAttribute('id', $alias);
236 $service->setAttribute('alias', $id); 232 $service->setAttribute('alias', $id);
237 if (!$id->isPublic()) { 233 if (!$id->isPrivate()) {
238 $service->setAttribute('public', 'false'); 234 $service->setAttribute('public', $id->isPublic() ? 'true' : 'false');
239 } 235 }
240 $parent->appendChild($service); 236 $parent->appendChild($service);
241 } 237 }
242 238
243 /**
244 * Adds services.
245 *
246 * @param \DOMElement $parent
247 */
248 private function addServices(\DOMElement $parent) 239 private function addServices(\DOMElement $parent)
249 { 240 {
250 $definitions = $this->container->getDefinitions(); 241 $definitions = $this->container->getDefinitions();
251 if (!$definitions) { 242 if (!$definitions) {
252 return; 243 return;
282 $element = $this->document->createElement($type); 273 $element = $this->document->createElement($type);
283 if ($withKeys) { 274 if ($withKeys) {
284 $element->setAttribute($keyAttribute, $key); 275 $element->setAttribute($keyAttribute, $key);
285 } 276 }
286 277
278 if ($value instanceof ServiceClosureArgument) {
279 $value = $value->getValues()[0];
280 }
287 if (is_array($value)) { 281 if (is_array($value)) {
288 $element->setAttribute('type', 'collection'); 282 $element->setAttribute('type', 'collection');
289 $this->convertParameters($value, $type, $element, 'key'); 283 $this->convertParameters($value, $type, $element, 'key');
284 } elseif ($value instanceof TaggedIteratorArgument) {
285 $element->setAttribute('type', 'tagged');
286 $element->setAttribute('tag', $value->getTag());
287 } elseif ($value instanceof IteratorArgument) {
288 $element->setAttribute('type', 'iterator');
289 $this->convertParameters($value->getValues(), $type, $element, 'key');
290 } elseif ($value instanceof Reference) { 290 } elseif ($value instanceof Reference) {
291 $element->setAttribute('type', 'service'); 291 $element->setAttribute('type', 'service');
292 $element->setAttribute('id', (string) $value); 292 $element->setAttribute('id', (string) $value);
293 $behaviour = $value->getInvalidBehavior(); 293 $behaviour = $value->getInvalidBehavior();
294 if ($behaviour == ContainerInterface::NULL_ON_INVALID_REFERENCE) { 294 if (ContainerInterface::NULL_ON_INVALID_REFERENCE == $behaviour) {
295 $element->setAttribute('on-invalid', 'null'); 295 $element->setAttribute('on-invalid', 'null');
296 } elseif ($behaviour == ContainerInterface::IGNORE_ON_INVALID_REFERENCE) { 296 } elseif (ContainerInterface::IGNORE_ON_INVALID_REFERENCE == $behaviour) {
297 $element->setAttribute('on-invalid', 'ignore'); 297 $element->setAttribute('on-invalid', 'ignore');
298 } elseif (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE == $behaviour) {
299 $element->setAttribute('on-invalid', 'ignore_uninitialized');
298 } 300 }
299 } elseif ($value instanceof Definition) { 301 } elseif ($value instanceof Definition) {
300 $element->setAttribute('type', 'service'); 302 $element->setAttribute('type', 'service');
301 $this->addService($value, null, $element); 303 $this->addService($value, null, $element);
302 } elseif ($value instanceof Expression) { 304 } elseif ($value instanceof Expression) {
315 } 317 }
316 318
317 /** 319 /**
318 * Escapes arguments. 320 * Escapes arguments.
319 * 321 *
320 * @param array $arguments
321 *
322 * @return array 322 * @return array
323 */ 323 */
324 private function escape(array $arguments) 324 private function escape(array $arguments)
325 { 325 {
326 $args = array(); 326 $args = array();