@@ -138,7 +138,7 @@ final public static function from(string $value): self
138138     */ 
139139    final  public  static  function  tryFrom (string  $ valueself 
140140    {
141-         $ constantsself ::getConstants ();
141+         $ constantsstatic ::getConstants ();
142142        foreach  ($ constantsas  $ name$ constantValue
143143            if  ($ constantValue$ value
144144                return  self ::getInstance ($ constantValue$ name
@@ -157,7 +157,7 @@ final public static function tryFrom(string $value): ?self
157157    final  public  static  function  cases (): array 
158158    {
159159        $ cases
160-         $ constantsself ::getConstants ();
160+         $ constantsstatic ::getConstants ();
161161        foreach  ($ constantsas  $ name$ value
162162            $ casesself ::getInstance ($ value$ name
163163        }
@@ -203,7 +203,7 @@ final public function is(self $other): bool
203203     */ 
204204    final  public  static  function  getValues (): array 
205205    {
206-         return  array_values (self ::getConstants ());
206+         return  array_values (static ::getConstants ());
207207    }
208208
209209    /** 
@@ -258,43 +258,60 @@ final protected static function getConstants(): array
258258        $ classNamestatic ::class;
259259
260260        if  (!isset (self ::$ cache$ className
261-             $ reflectionnew  ReflectionClass ($ className
262-             $ constants$ reflectiongetConstants ();
263- 
264-             // Validate all constants 
265-             $ enumConstants
266-             foreach  ($ constantsas  $ name$ value
267-                 // Check if constant name follows uppercase snake_case pattern 
268-                 if  (!preg_match ('/^[A-Z][A-Z0-9_]*$/ ' , $ name
269-                     throw  new  RuntimeException (
270-                         sprintf (
271-                             'Invalid enum constant name "%s" in %s. Constants must be UPPER_SNAKE_CASE. ' ,
272-                             $ name
273-                             $ className
274-                         )
275-                     );
276-                 }
277- 
278-                 // Check if value is valid type 
279-                 if  (!is_string ($ value
280-                     throw  new  RuntimeException (
281-                         sprintf (
282-                             'Invalid enum value type for constant %s::%s.  '  .
283-                             'Only string values are allowed, %s given. ' ,
284-                             $ className
285-                             $ name
286-                             gettype ($ value
287-                         )
288-                     );
289-                 }
290- 
291-                 $ enumConstants$ name$ value
261+             self ::$ cache$ classNamestatic ::determineClassEnumerations ($ className
262+         }
263+ 
264+         return  self ::$ cache$ className
265+     }
266+ 
267+     /** 
268+      * Determines the class enumerations by reflecting on class constants. 
269+      * 
270+      * This method can be overridden by subclasses to customize how 
271+      * enumerations are determined (e.g., to add dynamic constants). 
272+      * 
273+      * @since n.e.x.t 
274+      * 
275+      * @param class-string $className The fully qualified class name. 
276+      * @return array<string, string> Map of constant names to values. 
277+      * @throws RuntimeException If invalid constant found. 
278+      */ 
279+     protected  static  function  determineClassEnumerations (string  $ classNamearray 
280+     {
281+         $ reflectionnew  ReflectionClass ($ className
282+         $ constants$ reflectiongetConstants ();
283+ 
284+         // Validate all constants 
285+         $ enumConstants
286+         foreach  ($ constantsas  $ name$ value
287+             // Check if constant name follows uppercase snake_case pattern 
288+             if  (!preg_match ('/^[A-Z][A-Z0-9_]*$/ ' , $ name
289+                 throw  new  RuntimeException (
290+                     sprintf (
291+                         'Invalid enum constant name "%s" in %s. Constants must be UPPER_SNAKE_CASE. ' ,
292+                         $ name
293+                         $ className
294+                     )
295+                 );
296+             }
297+ 
298+             // Check if value is valid type 
299+             if  (!is_string ($ value
300+                 throw  new  RuntimeException (
301+                     sprintf (
302+                         'Invalid enum value type for constant %s::%s.  '  .
303+                         'Only string values are allowed, %s given. ' ,
304+                         $ className
305+                         $ name
306+                         gettype ($ value
307+                     )
308+                 );
292309            }
293310
294-             self :: $ cache [ $ className $ enumConstants 
311+             $ enumConstants [ $ name $ value 
295312        }
296313
297-         return  self :: $ cache [ $ className ] ;
314+         return  $ enumConstants 
298315    }
299316
300317    /** 
@@ -312,7 +329,7 @@ final public function __call(string $name, array $arguments): bool
312329        // Handle is* methods 
313330        if  (strpos ($ name'is ' ) === 0 ) {
314331            $ constantNameself ::camelCaseToConstant (substr ($ name2 ));
315-             $ constantsself ::getConstants ();
332+             $ constantsstatic ::getConstants ();
316333
317334            if  (isset ($ constants$ constantName
318335                return  $ this value  === $ constants$ constantName
@@ -337,7 +354,7 @@ final public function __call(string $name, array $arguments): bool
337354    final  public  static  function  __callStatic (string  $ namearray  $ argumentsself 
338355    {
339356        $ constantNameself ::camelCaseToConstant ($ name
340-         $ constantsself ::getConstants ();
357+         $ constantsstatic ::getConstants ();
341358
342359        if  (isset ($ constants$ constantName
343360            return  self ::getInstance ($ constants$ constantName$ constantName
0 commit comments