function YamlDumper::dumpValue
Dumps the value to YAML format.
Throws
RuntimeException When trying to dump object or resource
1 call to YamlDumper::dumpValue()
- YamlDumper::addService in vendor/
symfony/ dependency-injection/ Dumper/ YamlDumper.php
File
-
vendor/
symfony/ dependency-injection/ Dumper/ YamlDumper.php, line 249
Class
- YamlDumper
- YamlDumper dumps a service container as a YAML string.
Namespace
Symfony\Component\DependencyInjection\DumperCode
private function dumpValue(mixed $value) : mixed {
if ($value instanceof ServiceClosureArgument) {
$value = $value->getValues()[0];
return new TaggedValue('service_closure', $this->dumpValue($value));
}
if ($value instanceof ArgumentInterface) {
$tag = $value;
if ($value instanceof TaggedIteratorArgument || $value instanceof ServiceLocatorArgument && ($tag = $value->getTaggedIteratorArgument())) {
if (null === $tag->getIndexAttribute()) {
$content = $tag->getTag();
}
else {
$content = [
'tag' => $tag->getTag(),
'index_by' => $tag->getIndexAttribute(),
];
if (null !== $tag->getDefaultIndexMethod()) {
$content['default_index_method'] = $tag->getDefaultIndexMethod();
}
if (null !== $tag->getDefaultPriorityMethod()) {
$content['default_priority_method'] = $tag->getDefaultPriorityMethod();
}
}
if ($excludes = $tag->getExclude()) {
if (!\is_array($content)) {
$content = [
'tag' => $content,
];
}
$content['exclude'] = 1 === \count($excludes) ? $excludes[0] : $excludes;
}
if (!$tag->excludeSelf()) {
$content['exclude_self'] = false;
}
return new TaggedValue($value instanceof TaggedIteratorArgument ? 'tagged_iterator' : 'tagged_locator', $content);
}
if ($value instanceof IteratorArgument) {
$tag = 'iterator';
}
elseif ($value instanceof ServiceLocatorArgument) {
$tag = 'service_locator';
}
else {
throw new RuntimeException(\sprintf('Unspecified Yaml tag for type "%s".', get_debug_type($value)));
}
return new TaggedValue($tag, $this->dumpValue($value->getValues()));
}
if (\is_array($value)) {
$code = [];
foreach ($value as $k => $v) {
$code[$k] = $this->dumpValue($v);
}
return $code;
}
elseif ($value instanceof Reference) {
return $this->getServiceCall((string) $value, $value);
}
elseif ($value instanceof Parameter) {
return $this->getParameterCall((string) $value);
}
elseif ($value instanceof Expression) {
return $this->getExpressionCall((string) $value);
}
elseif ($value instanceof Definition) {
return new TaggedValue('service', (new Parser())->parse("_:\n" . $this->addService('_', $value), Yaml::PARSE_CUSTOM_TAGS)['_']['_']);
}
elseif ($value instanceof \UnitEnum) {
return new TaggedValue('php/enum', \sprintf('%s::%s', $value::class, $value->name));
}
elseif ($value instanceof AbstractArgument) {
return new TaggedValue('abstract', $value->getText());
}
elseif (\is_object($value) || \is_resource($value)) {
throw new RuntimeException(\sprintf('Unable to dump a service container if a parameter is an object or a resource, got "%s".', get_debug_type($value)));
}
return $value;
}