-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReflectionEnumBackedCase.php
51 lines (45 loc) · 1.38 KB
/
ReflectionEnumBackedCase.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
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Part of SplTypes package.
*
* (c) Adrien Loyant <donald_duck@team-df.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Ducks\Polyfill\Enum;
class ReflectionEnumBackedCase extends ReflectionEnumUnitCase
{
/**
* Instantiates a ReflectionEnumBackedCase object
*
* @param object|string $class An enum instance or a name.
* @param string $constant An enum constant name.
*
* @throws ReflectionException if $class is not a \ReflectionEnumBackedCase
*
* @link https://www.php.net/manual/en/reflectionenumbackedcase.construct.php
*/
public function __construct($class, string $constant)
{
parent::__construct($class, $constant);
if (!$this->getEnum()->isBacked()) {
throw new \ReflectionException(
'Enum case ' . $this->class . '::' . $this->name . ' is not a backed case'
);
}
}
/**
* Gets the scalar value backing this Enum case
*
* @return int|string The scalar equivalent of this enum case.
*
* @link https://www.php.net/manual/en/reflectionenumbackedcase.getbackingvalue.php
*/
public function getBackingValue()
{
return $this->getDeclaringClass()
->getConstant($this->name);
}
}