Exemplo n.º 1
0
 /**
  * Returns the enumeration members for a given class
  *
  * @param   lang.XPClass class class object
  * @return  lang.Enum[]
  * @throws  lang.IllegalArgumentException in case the given class is not an enum
  */
 public static function valuesOf(XPClass $class)
 {
     if (!$class->isEnum()) {
         throw new IllegalArgumentException('Argument class must be lang.XPClass<? extends lang.Enum>');
     }
     $r = [];
     foreach ($class->reflect()->getStaticProperties() as $prop) {
         $class->isInstance($prop) && ($r[] = $prop);
     }
     return $r;
 }
Exemplo n.º 2
0
 /**
  * Returns the enumeration members for a given class
  *
  * @param  lang.XPClass class class object
  * @return self[]
  * @throws lang.IllegalArgumentException in case the given class is not an enum
  */
 public static function valuesOf(XPClass $class)
 {
     if (!$class->isEnum()) {
         throw new IllegalArgumentException('Argument class must be lang.XPClass<? extends lang.Enum>');
     }
     $r = [];
     if ($class->isSubclassOf(self::class)) {
         foreach ($class->reflect()->getStaticProperties() as $prop) {
             $class->isInstance($prop) && ($r[] = $prop);
         }
     } else {
         $t = ClassLoader::defineClass($class->getName() . 'Enum', self::class, []);
         foreach ($class->reflect()->getMethod('getValues')->invoke(null) as $name => $ordinal) {
             $r[] = $t->newInstance($ordinal, $name);
         }
     }
     return $r;
 }