1
0
Fork 0

Merge pull request #9670 from Ayesh/enums

Add support for autoloading Enums
pull/9542/head
Jordi Boggiano 2021-02-24 16:03:58 +01:00 committed by GitHub
commit 09639a0cfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 1 deletions

View File

@ -215,7 +215,7 @@ class ClassMapGenerator
private static function findClasses($path) private static function findClasses($path)
{ {
$extraTypes = PHP_VERSION_ID < 50400 ? '' : '|trait'; $extraTypes = PHP_VERSION_ID < 50400 ? '' : '|trait';
if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.3', '>=')) { if (PHP_VERSION_ID >= 80100 || (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.3', '>='))) {
$extraTypes .= '|enum'; $extraTypes .= '|enum';
} }

View File

@ -96,6 +96,16 @@ class ClassMapGeneratorTest extends TestCase
'Dummy\Test\AnonClassHolder' => __DIR__ . '/Fixtures/php7.0/anonclass.php', 'Dummy\Test\AnonClassHolder' => __DIR__ . '/Fixtures/php7.0/anonclass.php',
)); ));
} }
if (PHP_VERSION_ID >= 80100) {
$data[] = array(__DIR__ . '/Fixtures/php8.1', array(
'RolesBasicEnum' => __DIR__ . '/Fixtures/php8.1/enum_basic.php',
'RolesBackedEnum' => __DIR__ . '/Fixtures/php8.1/enum_backed.php',
'RolesClassLikeEnum' => __DIR__ . '/Fixtures/php8.1/enum_class_semantics.php',
'Foo\Bar\RolesClassLikeNamespacedEnum' => __DIR__ . '/Fixtures/php8.1/enum_namespaced.php',
));
}
if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.3', '>=')) { if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.3', '>=')) {
$data[] = array(__DIR__ . '/Fixtures/hhvm3.3', array( $data[] = array(__DIR__ . '/Fixtures/hhvm3.3', array(
'FooEnum' => __DIR__ . '/Fixtures/hhvm3.3/HackEnum.php', 'FooEnum' => __DIR__ . '/Fixtures/hhvm3.3/HackEnum.php',

View File

@ -0,0 +1,7 @@
<?php
enum RolesBackedEnum: string {
case Admin = 'Administrator';
case Guest = 'Guest';
case Moderator = 'Moderator';
}

View File

@ -0,0 +1,7 @@
<?php
enum RolesBasicEnum {
case ADMIN;
case Guest;
case Moderator;
}

View File

@ -0,0 +1,7 @@
<?php
enum RolesClassLikeEnum: string implements TestFoo {
case Admin = 'Administrator';
case Guest = 'Guest';
case Moderator = 'Moderator';
}

View File

@ -0,0 +1,9 @@
<?php
namespace Foo\Bar;
enum RolesClassLikeNamespacedEnum: string implements TestFoo {
case Admin = 'Administrator';
case Guest = 'Guest';
case Moderator = 'Moderator';
}