-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathReflectEnumCase.php
40 lines (31 loc) · 984 Bytes
/
ReflectEnumCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types=1);
namespace Crell\AttributeUtils\Attributes\Reflect;
use Crell\AttributeUtils\FromReflectionEnumCase;
#[\Attribute(\Attribute::TARGET_CLASS_CONSTANT)]
class ReflectEnumCase implements FromReflectionEnumCase
{
/**
* The name of the enum, as PHP defines it.
*/
public readonly string $phpName;
/**
* The value of the enum, if it is a backed enum.
*/
public readonly int|string $value;
/**
* True if this is a backed enum, false otherwise.
*/
public readonly bool $isBacked;
public function fromReflection(\ReflectionEnumUnitCase $subject): void
{
$this->phpName = $subject->getName();
if ($subject instanceof \ReflectionEnumBackedCase) {
$this->isBacked = true;
$this->value = $subject->getBackingValue();
} else {
$this->isBacked = false;
}
// @todo Do we include doc comment, or the declaring class?
}
}