| @@ -16,9 +16,10 @@ | ||
| 16 | 16 | * |
| 17 | 17 | * @phpstan-type ClassAliasArray array{'type':'class',isabstract:bool,classname:string,namespace?:string,extends:string,implements:array<string>} |
| 18 | 18 | * @phpstan-type InterfaceAliasArray array{'type':'interface',interfacename:string,namespace?:string,extends:array<string>} |
| 19 | 19 | * @phpstan-type TraitAliasArray array{'type':'trait',traitname:string,namespace?:string,use:array<string>} |
| 20 | - * @phpstan-type AutoloadAliasArray array<string,ClassAliasArray|InterfaceAliasArray|TraitAliasArray> | |
| 20 | + * @phpstan-type EnumAliasArray array{'type':'enum',enumname:string,namespace?:string,concrete:string} | |
| 21 | + * @phpstan-type AutoloadAliasArray array<string,ClassAliasArray|InterfaceAliasArray|TraitAliasArray|EnumAliasArray> | |
| 21 | 22 | */ |
| 22 | 23 | class AliasAutoloader |
| 23 | 24 | { |
| 24 | 25 | private string $includeFilePath; |
| @@ -707,8 +708,20 @@ | ||
| 707 | 708 | $this->load( |
| 708 | 709 | $this->traitTemplate( |
| 709 | 710 | $this->autoloadAliases[$class] |
| 710 | 711 | ) |
| 712 | + ); | |
| 713 | + break; | |
| 714 | + case 'enum': | |
| 715 | + // Enums are final so cannot be aliased with an `extends` shim like classes are; `class_alias()` | |
| 716 | + // makes the original name a true alias of the renamed enum, preserving case identity (`===`), | |
| 717 | + // `match` arms, `::cases()`, `::from()` and `instanceof` the enum itself. Unlike the class shim, | |
| 718 | + // the alias does not implement the enum's original interface names, so `instanceof` against an | |
| 719 | + // original interface name is false. Enums require PHP 8.1, but this only executes when an enum | |
| 720 | + // is autoloaded by its original name, i.e. on a runtime already using enums. | |
| 721 | + \class_alias( | |
| 722 | + $this->autoloadAliases[$class]['concrete'], | |
| 723 | + $class | |
| 711 | 724 | ); |
| 712 | 725 | break; |
| 713 | 726 | default: |
| 714 | 727 | // Never. |