Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/dependency-injection/Dumper/XmlDumper.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 | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
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\Alias; | |
14 use Symfony\Component\DependencyInjection\Argument\IteratorArgument; | 15 use Symfony\Component\DependencyInjection\Argument\IteratorArgument; |
15 use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; | 16 use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; |
16 use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; | 17 use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; |
17 use Symfony\Component\DependencyInjection\ContainerInterface; | 18 use Symfony\Component\DependencyInjection\ContainerInterface; |
19 use Symfony\Component\DependencyInjection\Definition; | |
20 use Symfony\Component\DependencyInjection\Exception\RuntimeException; | |
18 use Symfony\Component\DependencyInjection\Parameter; | 21 use Symfony\Component\DependencyInjection\Parameter; |
19 use Symfony\Component\DependencyInjection\Reference; | 22 use Symfony\Component\DependencyInjection\Reference; |
20 use Symfony\Component\DependencyInjection\Definition; | |
21 use Symfony\Component\DependencyInjection\Alias; | |
22 use Symfony\Component\DependencyInjection\Exception\RuntimeException; | |
23 use Symfony\Component\ExpressionLanguage\Expression; | 23 use Symfony\Component\ExpressionLanguage\Expression; |
24 | 24 |
25 /** | 25 /** |
26 * XmlDumper dumps a service container as an XML string. | 26 * XmlDumper dumps a service container as an XML string. |
27 * | 27 * |
38 /** | 38 /** |
39 * Dumps the service container as an XML string. | 39 * Dumps the service container as an XML string. |
40 * | 40 * |
41 * @return string An xml string representing of the service container | 41 * @return string An xml string representing of the service container |
42 */ | 42 */ |
43 public function dump(array $options = array()) | 43 public function dump(array $options = []) |
44 { | 44 { |
45 $this->document = new \DOMDocument('1.0', 'utf-8'); | 45 $this->document = new \DOMDocument('1.0', 'utf-8'); |
46 $this->document->formatOutput = true; | 46 $this->document->formatOutput = true; |
47 | 47 |
48 $container = $this->document->createElementNS('http://symfony.com/schema/dic/services', 'container'); | 48 $container = $this->document->createElementNS('http://symfony.com/schema/dic/services', 'container'); |
78 private function addMethodCalls(array $methodcalls, \DOMElement $parent) | 78 private function addMethodCalls(array $methodcalls, \DOMElement $parent) |
79 { | 79 { |
80 foreach ($methodcalls as $methodcall) { | 80 foreach ($methodcalls as $methodcall) { |
81 $call = $this->document->createElement('call'); | 81 $call = $this->document->createElement('call'); |
82 $call->setAttribute('method', $methodcall[0]); | 82 $call->setAttribute('method', $methodcall[0]); |
83 if (count($methodcall[1])) { | 83 if (\count($methodcall[1])) { |
84 $this->convertParameters($methodcall[1], 'argument', $call); | 84 $this->convertParameters($methodcall[1], 'argument', $call); |
85 } | 85 } |
86 $parent->appendChild($call); | 86 $parent->appendChild($call); |
87 } | 87 } |
88 } | 88 } |
158 $this->addMethodCalls($definition->getMethodCalls(), $service); | 158 $this->addMethodCalls($definition->getMethodCalls(), $service); |
159 | 159 |
160 if ($callable = $definition->getFactory()) { | 160 if ($callable = $definition->getFactory()) { |
161 $factory = $this->document->createElement('factory'); | 161 $factory = $this->document->createElement('factory'); |
162 | 162 |
163 if (is_array($callable) && $callable[0] instanceof Definition) { | 163 if (\is_array($callable) && $callable[0] instanceof Definition) { |
164 $this->addService($callable[0], null, $factory); | 164 $this->addService($callable[0], null, $factory); |
165 $factory->setAttribute('method', $callable[1]); | 165 $factory->setAttribute('method', $callable[1]); |
166 } elseif (is_array($callable)) { | 166 } elseif (\is_array($callable)) { |
167 if (null !== $callable[0]) { | 167 if (null !== $callable[0]) { |
168 $factory->setAttribute($callable[0] instanceof Reference ? 'service' : 'class', $callable[0]); | 168 $factory->setAttribute($callable[0] instanceof Reference ? 'service' : 'class', $callable[0]); |
169 } | 169 } |
170 $factory->setAttribute('method', $callable[1]); | 170 $factory->setAttribute('method', $callable[1]); |
171 } else { | 171 } else { |
201 } | 201 } |
202 | 202 |
203 if ($callable = $definition->getConfigurator()) { | 203 if ($callable = $definition->getConfigurator()) { |
204 $configurator = $this->document->createElement('configurator'); | 204 $configurator = $this->document->createElement('configurator'); |
205 | 205 |
206 if (is_array($callable) && $callable[0] instanceof Definition) { | 206 if (\is_array($callable) && $callable[0] instanceof Definition) { |
207 $this->addService($callable[0], null, $configurator); | 207 $this->addService($callable[0], null, $configurator); |
208 $configurator->setAttribute('method', $callable[1]); | 208 $configurator->setAttribute('method', $callable[1]); |
209 } elseif (is_array($callable)) { | 209 } elseif (\is_array($callable)) { |
210 $configurator->setAttribute($callable[0] instanceof Reference ? 'service' : 'class', $callable[0]); | 210 $configurator->setAttribute($callable[0] instanceof Reference ? 'service' : 'class', $callable[0]); |
211 $configurator->setAttribute('method', $callable[1]); | 211 $configurator->setAttribute('method', $callable[1]); |
212 } else { | 212 } else { |
213 $configurator->setAttribute('function', $callable); | 213 $configurator->setAttribute('function', $callable); |
214 } | 214 } |
266 * @param \DOMElement $parent | 266 * @param \DOMElement $parent |
267 * @param string $keyAttribute | 267 * @param string $keyAttribute |
268 */ | 268 */ |
269 private function convertParameters(array $parameters, $type, \DOMElement $parent, $keyAttribute = 'key') | 269 private function convertParameters(array $parameters, $type, \DOMElement $parent, $keyAttribute = 'key') |
270 { | 270 { |
271 $withKeys = array_keys($parameters) !== range(0, count($parameters) - 1); | 271 $withKeys = array_keys($parameters) !== range(0, \count($parameters) - 1); |
272 foreach ($parameters as $key => $value) { | 272 foreach ($parameters as $key => $value) { |
273 $element = $this->document->createElement($type); | 273 $element = $this->document->createElement($type); |
274 if ($withKeys) { | 274 if ($withKeys) { |
275 $element->setAttribute($keyAttribute, $key); | 275 $element->setAttribute($keyAttribute, $key); |
276 } | 276 } |
277 | 277 |
278 if ($value instanceof ServiceClosureArgument) { | 278 if ($value instanceof ServiceClosureArgument) { |
279 $value = $value->getValues()[0]; | 279 $value = $value->getValues()[0]; |
280 } | 280 } |
281 if (is_array($value)) { | 281 if (\is_array($value)) { |
282 $element->setAttribute('type', 'collection'); | 282 $element->setAttribute('type', 'collection'); |
283 $this->convertParameters($value, $type, $element, 'key'); | 283 $this->convertParameters($value, $type, $element, 'key'); |
284 } elseif ($value instanceof TaggedIteratorArgument) { | 284 } elseif ($value instanceof TaggedIteratorArgument) { |
285 $element->setAttribute('type', 'tagged'); | 285 $element->setAttribute('type', 'tagged'); |
286 $element->setAttribute('tag', $value->getTag()); | 286 $element->setAttribute('tag', $value->getTag()); |
304 } elseif ($value instanceof Expression) { | 304 } elseif ($value instanceof Expression) { |
305 $element->setAttribute('type', 'expression'); | 305 $element->setAttribute('type', 'expression'); |
306 $text = $this->document->createTextNode(self::phpToXml((string) $value)); | 306 $text = $this->document->createTextNode(self::phpToXml((string) $value)); |
307 $element->appendChild($text); | 307 $element->appendChild($text); |
308 } else { | 308 } else { |
309 if (in_array($value, array('null', 'true', 'false'), true)) { | 309 if (\in_array($value, ['null', 'true', 'false'], true)) { |
310 $element->setAttribute('type', 'string'); | 310 $element->setAttribute('type', 'string'); |
311 } | 311 } |
312 $text = $this->document->createTextNode(self::phpToXml($value)); | 312 $text = $this->document->createTextNode(self::phpToXml($value)); |
313 $element->appendChild($text); | 313 $element->appendChild($text); |
314 } | 314 } |
321 * | 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 = []; |
327 foreach ($arguments as $k => $v) { | 327 foreach ($arguments as $k => $v) { |
328 if (is_array($v)) { | 328 if (\is_array($v)) { |
329 $args[$k] = $this->escape($v); | 329 $args[$k] = $this->escape($v); |
330 } elseif (is_string($v)) { | 330 } elseif (\is_string($v)) { |
331 $args[$k] = str_replace('%', '%%', $v); | 331 $args[$k] = str_replace('%', '%%', $v); |
332 } else { | 332 } else { |
333 $args[$k] = $v; | 333 $args[$k] = $v; |
334 } | 334 } |
335 } | 335 } |
355 return 'true'; | 355 return 'true'; |
356 case false === $value: | 356 case false === $value: |
357 return 'false'; | 357 return 'false'; |
358 case $value instanceof Parameter: | 358 case $value instanceof Parameter: |
359 return '%'.$value.'%'; | 359 return '%'.$value.'%'; |
360 case is_object($value) || is_resource($value): | 360 case \is_object($value) || \is_resource($value): |
361 throw new RuntimeException('Unable to dump a service container if a parameter is an object or a resource.'); | 361 throw new RuntimeException('Unable to dump a service container if a parameter is an object or a resource.'); |
362 default: | 362 default: |
363 return (string) $value; | 363 return (string) $value; |
364 } | 364 } |
365 } | 365 } |