Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite51e651

Browse files
bug#41072 [VarExporter] Add support of PHP enumerations (alexandre-daubois)
This PR was merged into the 4.4 branch.Discussion----------[VarExporter] Add support of PHP enumerations| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |Fix#40237| License | MIT| Doc PR | _none_Commits-------4b0f299 [VarExporter] Add support of PHP enumerations
2 parents72b6001 +4b0f299 commite51e651

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
6262
$value =self::prepare($value,$objectsPool,$refsPool,$objectsCount,$valueIsStatic);
6363
}
6464
goto handle_value;
65-
}elseif (!\is_object($value) && !$valueinstanceof \__PHP_Incomplete_Class) {
65+
}elseif (!\is_object($value) && !$valueinstanceof \__PHP_Incomplete_Class ||$valueinstanceof \UnitEnum) {
6666
goto handle_value;
6767
}
6868

@@ -190,7 +190,7 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
190190
publicstaticfunctionexport($value,$indent ='')
191191
{
192192
switch (true) {
193-
case\is_int($value) ||\is_float($value):returnvar_export($value,true);
193+
case\is_int($value) ||\is_float($value) ||$valueinstanceof \UnitEnum:returnvar_export($value,true);
194194
case [] ===$value:return'[]';
195195
casefalse ===$value:return'false';
196196
casetrue ===$value:return'true';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespaceSymfony\Component\VarExporter\Tests\Fixtures;
4+
5+
enum FooUnitEnum
6+
{
7+
case Bar;
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
Symfony\Component\VarExporter\Tests\Fixtures\FooUnitEnum::Bar,
5+
];

‎src/Symfony/Component/VarExporter/Tests/VarExporterTest.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
useSymfony\Component\VarExporter\Exception\ClassNotFoundException;
1717
useSymfony\Component\VarExporter\Exception\NotInstantiableTypeException;
1818
useSymfony\Component\VarExporter\Internal\Registry;
19+
useSymfony\Component\VarExporter\Tests\Fixtures\FooUnitEnum;
1920
useSymfony\Component\VarExporter\VarExporter;
2021

2122
class VarExporterTestextends TestCase
@@ -209,6 +210,10 @@ public function provideExport()
209210
yield ['private-constructor', PrivateConstructor::create('bar')];
210211

211212
yield ['php74-serializable',newPhp74Serializable()];
213+
214+
if (\PHP_VERSION_ID >=80100) {
215+
yield ['unit-enum', [FooUnitEnum::Bar],true];
216+
}
212217
}
213218
}
214219

‎src/Symfony/Component/VarExporter/VarExporter.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static function export($value, bool &$isStaticValue = null): string
4343
{
4444
$isStaticValue =true;
4545

46-
if (!\is_object($value) && !(\is_array($value) &&$value) && !$valueinstanceof \__PHP_Incomplete_Class && !\is_resource($value)) {
46+
if (!\is_object($value) && !(\is_array($value) &&$value) && !$valueinstanceof \__PHP_Incomplete_Class && !\is_resource($value) ||$valueinstanceof \UnitEnum) {
4747
return Exporter::export($value);
4848
}
4949

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp