File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Warengo \Enum ;
4+
5+ final class EnumMapping
6+ {
7+
8+ /** @var string[] */
9+ private array $ mapping = [];
10+
11+ private string $ class ;
12+
13+ /**
14+ * @param bool[] $mapping
15+ */
16+ public function __construct (string $ class , array $ mapping )
17+ {
18+ $ this ->class = $ class ;
19+ foreach ($ mapping as $ key => $ bool ) {
20+ $ this ->mapping [strtoupper ($ key )] = $ key ;
21+ }
22+ }
23+
24+ public function getClass (): string
25+ {
26+ return $ this ->class ;
27+ }
28+
29+ public function callableGetter (): callable
30+ {
31+ return [$ this ->getClass (), 'get ' ];
32+ }
33+
34+ /**
35+ * @return string[]
36+ */
37+ public function getMapping (): array
38+ {
39+ return $ this ->mapping ;
40+ }
41+
42+ }
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ abstract class EnumStatic
2222 */
2323 abstract protected static function getEnums (): array ;
2424
25+ final public static function createMapping (): EnumMapping {
26+ return new EnumMapping (static ::class, self ::getEnumsCached ());
27+ }
28+
2529 /**
2630 * @param mixed[] $arguments
2731 */
You can’t perform that action at this time.
0 commit comments