10000 Fix dumping enums on PHP 8.2 · symfony/symfony@4244aa8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4244aa8

Browse files
Fix dumping enums on PHP 8.2
1 parent f0ffa47 commit 4244aa8

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ abstract protected function describeCallable($callable, array $options = []);
150150
*/
151151
protected function formatValue($value): string
152152
{
153+
if ($value instanceof \UnitEnum) {
154+
return ltrim(var_export($value, true), '\\');
155+
}
156+
153157
if (\is_object($value)) {
154158
return sprintf('object(%s)', \get_class($value));
155159
}
@@ -158,7 +162,7 @@ protected function formatValue($value): string
158162
return $value;
159163
}
160164

161-
return preg_replace("/\n\s*/s", '', var_export($value, true));
165+
return preg_replace("/\n\s*/s", '', ltrim(var_export($value, true)), '\\');
162166
}
163167

164168
/**
@@ -169,15 +173,15 @@ protected function formatValue($value): string
169173
protected function formatParameter($value): string
170174
{
171175
if ($value instanceof \UnitEnum) {
172-
return var_export($value, true);
176+
return ltrim(var_export($value, true), '\\');
173177
}
174178

175179
// Recursively search for enum values, so we can replace it
176180
// before json_encode (which will not display anything for \UnitEnum otherwise)
177181
if (\is_array($value)) {
178182
array_walk_recursive($value, static function (&$value) {
179183
if ($value instanceof \UnitEnum) {
180-
$value = var_export($value, true);
184+
$value = ltrim(var_export($value, true), '\\');
181185
}
182186
});
183187
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private function writeData(array $data, array $options)
162162
// before json_encode (which will not display anything for \UnitEnum otherwise)
163163
array_walk_recursive($data, static function (&$value) {
164164
if ($value instanceof \UnitEnum) {
165-
$value = var_export($value, true);
165+
$value = ltrim(var_export($value, true), '\\');
166166
}
167167
});
168168

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
343343
} elseif ($argument instanceof Definition) {
344344
$argumentsInformation[] = 'Inlined Service';
345345
} elseif ($argument instanceof \UnitEnum) {
346-
$argumentsInformation[] = var_export($argument, true);
346+
$argumentsInformation[] = ltrim(var_export($argument, true), '\\');
347347
} else {
348348
$argumentsInformation[] = \is_array($argument) ? sprintf('Array (%d element(s))', \count($argument)) : $argument;
349349
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ private function getArgumentNodes(array $arguments, \DOMDocument $dom): array
388388
}
389389
} elseif ($argument instanceof \UnitEnum) {
390390
$argumentXML->setAttribute('type', 'constant');
391-
$argumentXML->appendChild(new \DOMText(var_export($argument, true)));
391+
$argumentXML->appendChild(new \DOMText(ltrim(var_export($argument, true), '\\')));
392392
} else {
393393
$argumentXML->appendChild(new \DOMText($argument));
394394
}

src/Symfony/Component/VarExporter/Internal/Exporter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,13 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
195195
public static function export($value, $indent = '')
196196
{
197197
switch (true) {
198-
case \is_int($value) || \is_float($value) || $value instanceof \UnitEnum: return var_export($value, true);
198+
case \is_int($value) || \is_float($value): return var_export($value, true);
199199
case [] === $value: return '[]';
200200
case false === $value: return 'false';
201201
case true === $value: return 'true';
202202
case null === $value: return 'null';
203203
case '' === $value: return "''";
204+
case $value instanceof \UnitEnum: return ltrim(var_export($value, true), '\\');
204205
}
205206

206207
if ($value instanceof Reference) {

0 commit comments

Comments
 (0)
0