function XmlDumper::convertParameters
3 calls to XmlDumper::convertParameters()
- XmlDumper::addMethodCalls in vendor/
symfony/ dependency-injection/ Dumper/ XmlDumper.php - XmlDumper::addParameters in vendor/
symfony/ dependency-injection/ Dumper/ XmlDumper.php - XmlDumper::addService in vendor/
symfony/ dependency-injection/ Dumper/ XmlDumper.php
File
-
vendor/
symfony/ dependency-injection/ Dumper/ XmlDumper.php, line 293
Class
- XmlDumper
- XmlDumper dumps a service container as an XML string.
Namespace
Symfony\Component\DependencyInjection\DumperCode
private function convertParameters(array $parameters, string $type, \DOMElement $parent, string $keyAttribute = 'key') : void {
$withKeys = !array_is_list($parameters);
foreach ($parameters as $key => $value) {
$element = $this->document
->createElement($type);
if ($withKeys) {
$element->setAttribute($keyAttribute, $key);
}
if (\is_array($tag = $value)) {
$element->setAttribute('type', 'collection');
$this->convertParameters($value, $type, $element, 'key');
}
elseif ($value instanceof TaggedIteratorArgument || $value instanceof ServiceLocatorArgument && ($tag = $value->getTaggedIteratorArgument())) {
$element->setAttribute('type', $value instanceof TaggedIteratorArgument ? 'tagged_iterator' : 'tagged_locator');
$element->setAttribute('tag', $tag->getTag());
if (null !== $tag->getIndexAttribute()) {
$element->setAttribute('index-by', $tag->getIndexAttribute());
if (null !== $tag->getDefaultIndexMethod()) {
$element->setAttribute('default-index-method', $tag->getDefaultIndexMethod());
}
if (null !== $tag->getDefaultPriorityMethod()) {
$element->setAttribute('default-priority-method', $tag->getDefaultPriorityMethod());
}
}
if ($excludes = $tag->getExclude()) {
if (1 === \count($excludes)) {
$element->setAttribute('exclude', $excludes[0]);
}
else {
foreach ($excludes as $exclude) {
$element->appendChild($this->document
->createElement('exclude', $exclude));
}
}
}
if (!$tag->excludeSelf()) {
$element->setAttribute('exclude-self', 'false');
}
}
elseif ($value instanceof IteratorArgument) {
$element->setAttribute('type', 'iterator');
$this->convertParameters($value->getValues(), $type, $element, 'key');
}
elseif ($value instanceof ServiceLocatorArgument) {
$element->setAttribute('type', 'service_locator');
$this->convertParameters($value->getValues(), $type, $element, 'key');
}
elseif ($value instanceof ServiceClosureArgument && !$value->getValues()[0] instanceof Reference) {
$element->setAttribute('type', 'service_closure');
$this->convertParameters($value->getValues(), $type, $element, 'key');
}
elseif ($value instanceof Reference || $value instanceof ServiceClosureArgument) {
$element->setAttribute('type', 'service');
if ($value instanceof ServiceClosureArgument) {
$element->setAttribute('type', 'service_closure');
$value = $value->getValues()[0];
}
$element->setAttribute('id', (string) $value);
$behavior = $value->getInvalidBehavior();
if (ContainerInterface::NULL_ON_INVALID_REFERENCE == $behavior) {
$element->setAttribute('on-invalid', 'null');
}
elseif (ContainerInterface::IGNORE_ON_INVALID_REFERENCE == $behavior) {
$element->setAttribute('on-invalid', 'ignore');
}
elseif (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE == $behavior) {
$element->setAttribute('on-invalid', 'ignore_uninitialized');
}
}
elseif ($value instanceof Definition) {
$element->setAttribute('type', 'service');
$this->addService($value, null, $element);
}
elseif ($value instanceof Expression) {
$element->setAttribute('type', 'expression');
$text = $this->document
->createTextNode(self::phpToXml((string) $value));
$element->appendChild($text);
}
elseif (\is_string($value) && !preg_match('/^[^\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]*+$/u', $value)) {
$element->setAttribute('type', 'binary');
$text = $this->document
->createTextNode(self::phpToXml(base64_encode($value)));
$element->appendChild($text);
}
elseif ($value instanceof \UnitEnum) {
$element->setAttribute('type', 'constant');
$element->appendChild($this->document
->createTextNode(self::phpToXml($value)));
}
elseif ($value instanceof AbstractArgument) {
$element->setAttribute('type', 'abstract');
$text = $this->document
->createTextNode(self::phpToXml($value->getText()));
$element->appendChild($text);
}
else {
if (\in_array($value, [
'null',
'true',
'false',
], true)) {
$element->setAttribute('type', 'string');
}
if (\is_string($value) && (is_numeric($value) || preg_match('/^0b[01]*$/', $value) || preg_match('/^0x[0-9a-f]++$/i', $value))) {
$element->setAttribute('type', 'string');
}
$text = $this->document
->createTextNode(self::phpToXml($value));
$element->appendChild($text);
}
$parent->appendChild($element);
}
}