1 | <?php |
||
17 | class EnumProvider |
||
18 | { |
||
19 | /** |
||
20 | * Enum mapping as an array with : |
||
21 | * |
||
22 | * - alias for Enum class as key |
||
23 | * - Enum FQCN as value |
||
24 | * |
||
25 | * Example : |
||
26 | * |
||
27 | * ``` |
||
28 | * [ |
||
29 | * 'Civility' => Civility::class, |
||
30 | * 'Gender' => Gender::class, |
||
31 | * ] |
||
32 | * ``` |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | private $enumMapping = []; |
||
37 | |||
38 | public function __construct(array $enumMapping) |
||
45 | |||
46 | /** |
||
47 | * @param string $enumValueShortcut As <ENUM_CLASS_ALIAS>::<ENUM_VALUE_CONSTANT> |
||
48 | * Examples: 'Gender::MALE', 'Gender::FEMALE', 'Permissions::READ|WRITE', etc. |
||
49 | * |
||
50 | * @throws InvalidArgumentException When the alias part of $enumValueShortcut is not a valid alias |
||
51 | * |
||
52 | * @return EnumInterface |
||
53 | */ |
||
54 | public function enum(string $enumValueShortcut): EnumInterface |
||
82 | |||
83 | /** |
||
84 | * @param string $enumClassAlias |
||
85 | * |
||
86 | * @throws InvalidArgumentException When $enumClassAlias is not a valid alias |
||
87 | * |
||
88 | * @return EnumInterface |
||
89 | */ |
||
90 | public function randomEnum(string $enumClassAlias): EnumInterface |
||
104 | |||
105 | /** |
||
106 | * Make sure that $enumClass is a proper Enum class. Throws exception otherwise. |
||
107 | * |
||
108 | * @param string $enumClass |
||
109 | * |
||
110 | * @throws InvalidArgumentException When $enumClass is not a class or is not a proper Enum |
||
111 | */ |
||
112 | private function ensureEnumClass(string $enumClass) |
||
118 | } |
||
119 |