File tree Expand file tree Collapse file tree
packages/utilities/src/Enum Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,7 +15,14 @@ public static function tryWrap(mixed $value): ?static;
1515 *
1616 * @return array<string|int, static>
1717 */
18- public static function values (): array ;
18+ // public static function values(): array;
19+
20+ /**
21+ * Return assoc array of cases with case name as key.
22+ *
23+ * @return array<string|int, static>
24+ */
25+ public static function assocCases (): array ;
1926
2027 public static function rawValues (): array ;
2128
Original file line number Diff line number Diff line change @@ -43,6 +43,9 @@ public static function tryWrap(mixed $value): ?static
4343 * Return assoc array of cases with case name as key.
4444 *
4545 * @return array<string|int, static>
46+ *
47+ * @deprecated Do not use this method since PHP 8.6 may override this method. Use `assocCases()` instead.
48+ * @see https://wiki.php.net/rfc/add_values_method_to_backed_enum
4649 */
4750 public static function values (): array
4851 {
@@ -60,6 +63,20 @@ public static function rawValues(): array
6063 return array_map (static fn (self $ case ) => $ case ->value , self ::values ());
6164 }
6265
66+ /**
67+ * @return array<string|int, static>
68+ */
69+ public static function assocCases (): array
70+ {
71+ $ cases = [];
72+
73+ foreach (self ::cases () as $ case ) {
74+ $ cases [$ case ->name ] = $ case ;
75+ }
76+
77+ return $ cases ;
78+ }
79+
6380 /**
6481 * Returns the names (keys) of all constants in the Enum class
6582 *
You can’t perform that action at this time.
0 commit comments