Returns instances of the Enum class of all Enum constants

@return static[] Constant name in key, Enum instance in value
162017
public static function values()
    {
        $values = array();
        foreach (static::toArray() as $key => $value) {
            $values[$key] = new static($value);
        }
        return $values;
    }
441971
public static function classes()
    {
        $objs = array();

        foreach (get_declared_classes() as $value) {
            $value = ltrim($value, '\\');
            $cname = new \ReflectionClass($value);

            if (false === $cname->isInternal()) {
                $objs[$value] = $cname->getDefaultProperties();
            }

            $cname = null;
        }

        return $objs;
    }
282057
@SuppressWarnings("unchecked")
    static <T> T[] getEnumConstants(Class<T> enm) {
        return Stream.of(enm.getFields())
                .filter(f -> f.getType() == enm)
                .map(f -> {
            try {
                return f.get(null);
            } catch (Exception e) {
                return null;
            }
        })
        .filter(Objects::nonNull)
        .toArray(len -> (T[]) Array.newInstance(enm, len));
    }
1113000
private static function constants(): array
    {
        $class = get_called_class();

        if (isset(self::$constants[$class])) {
            return self::$constants[$class];
        }

        $reflection = new \ReflectionClass($class);

        return self::$constants[$class] = $reflection->getConstants();
    }
69998
public static function getConstList() : array
    {
        if (static::$constList === null) {
            $reflection        = new ReflectionClass(get_called_class());
            static::$constList = array_values($reflection->getConstants());
        }

        return static::$constList;
    }
13086
public function getEnumerations()
    {
        $enums = array();
        foreach ($this->element->getElementsByTagName('enumeration') as $enum) {
            $enums[] = $enum->getAttribute('value');
        };
        return $enums;
    }
391227
private static function detectConstants($class)
    {
        if (!isset(self::$constants[$class])) {
            $reflection = new ReflectionClass($class);
            $constants  = [];

            do {
                $scopeConstants = [];
                // Enumerators must be defined as public class constants
                foreach ($reflection->getReflectionConstants() as $reflConstant) {
                    if ($reflConstant->isPublic()) {
                        $scopeConstants[ $reflConstant->getName() ] = $reflConstant->getValue();
                    }
                }

                $constants = $scopeConstants + $constants;
            } while (($reflection = $reflection->getParentClass()) && $reflection->name !== __CLASS__);

            assert(
                self::noAmbiguousValues($constants),
                "Ambiguous enumerator values detected for {$class}"
            );

            self::$constants[$class] = $constants;
            self::$names[$class] = \array_keys($constants);
        }

        return self::$constants[$class];
    }
370841
final public function getAllValues() {
        $subClass = get_called_class();

        // Subclass has already been registered
        if(isset($this->_cachedEnums[$subClass])) {
            return FALSE;
        }

        $reflection = new \ReflectionClass($subClass);

        return $reflection->getConstants();
    }
1243010
public static function fromName($name)
    {
        $names = static::getNames();
        if (array_key_exists($name, $names)) {
            return new static($name, $names[$name]);
        }
        throw new \InvalidArgumentException("No enum constant '$name' in class " . get_called_class());
    }
102750
public static function allKeys()
    {
        static $allKeys = null;

        if (is_null($allKeys)) {
            $allKeys = array_values((new ReflectionClass(get_called_class()))->getConstants());
        }

        return $allKeys;
    }
363159
private <T extends Enum<T>> Object[] getValidEnumConstants(Class<T> valueClass) {
        T[] constants = valueClass.getEnumConstants();
        if (!VersionedEnum.class.isAssignableFrom(valueClass)) {
            return constants;
        }

        List<T> valid = new ArrayList<T>(constants.length);
        for (T value : constants) {
            VersionedEnum versionedValue = (VersionedEnum) value;
            if (version >= versionedValue.getMinVersion()) {
                valid.add(value);
            }
        }

        return valid.toArray();
    }
226927
public function getTypes()
    {
        $list            = array();
        $reflectionClass = new \ReflectionClass(__CLASS__);
        foreach ($reflectionClass->getConstants() as $k => $v) {
            if (strrpos($k, "_PLATFORM") > 0) {
                $list[] = $v;
            }
        }
        return $list;
    }
690813
protected static function getConstants(): array
    {
        $calledClass = get_called_class();

        if (!array_key_exists($calledClass, static::$constCacheArray)) {
            $reflect = new ReflectionClass($calledClass);
            static::$constCacheArray[$calledClass] = $reflect->getConstants();
        }

        return static::$constCacheArray[$calledClass];
    }
1208264
private function staticOperand() {
    static $scalar_types = [
      T_STRING_VARNAME,
      T_CLASS_C,
      T_LNUMBER,
      T_DNUMBER,
      T_CONSTANT_ENCAPSED_STRING,
      T_LINE,
      T_FILE,
      T_DIR,
      T_TRAIT_C,
      T_METHOD_C,
      T_FUNC_C,
      T_NS_C,
    ];
    if ($scalar = $this->tryMatchToken($scalar_types)) {
      return $scalar;
    }
    elseif ($this->currentType === '(') {
      $node = new ParenthesisNode();
      $this->mustMatch('(', $node, 'openParen');
      $node->addChild($this->staticScalar(), 'expression');
      $this->mustMatch(')', $node, 'closeParen', TRUE);
      return $node;
    }
    elseif (in_array($this->currentType, self::$namespacePathTypes)) {
      $namespace_path = $this->name();
      if ($this->currentType === T_DOUBLE_COLON) {
        $colon_node = new PartialNode();
        $this->mustMatch(T_DOUBLE_COLON, $colon_node);
        if ($this->currentType === T_CLASS) {
          return $this->classNameScalar($namespace_path, $colon_node);
        }
        else {
          $class_constant = $this->mustMatchToken(T_STRING);
          return $this->classConstant($namespace_path, $colon_node, $class_constant);
        }
      }
      else {
        $node = new ConstantNode();
        $node->addChild($namespace_path, 'constantName');
        return $node;
      }
    }
    elseif ($this->currentType === T_STATIC) {
      $static_node = $this->mustMatchToken(T_STATIC);
      $colon_node = new PartialNode();
      $this->mustMatch(T_DOUBLE_COLON, $colon_node);
      if ($this->currentType === T_CLASS) {
        return $this->classNameScalar($static_node, $colon_node);
      }
      else {
        $class_constant = $this->mustMatchToken(T_STRING);
        return $this->classConstant($static_node, $colon_node, $class_constant);
      }
    }
    elseif ($this->currentType === T_START_HEREDOC) {
      $node = new HeredocNode();
      $this->mustMatch(T_START_HEREDOC, $node);
      if ($this->tryMatch(T_END_HEREDOC, $node)) {
        return $node;
      }
      $this->mustMatch(T_ENCAPSED_AND_WHITESPACE, $node);
      $this->mustMatch(T_END_HEREDOC, $node);
      return $node;
    }
    else {
      return NULL;
    }
  }
8800
private static function constant(string $name)
    {
        $constant = static::class . '::' . $name;

        if (!defined($constant)) {
            $message = sprintf('Enum %s does not contain value named %s.', static::class, $name);
            throw new InvalidArgumentException($message);
        }

        return constant($constant);
    }
18117
final public static function getMembers(): array
    {
        if (!isset(self::$constants[static::class])) {
            $reflection = new ReflectionClass(static::class);
            $constants = self::sortConstants($reflection);
            self::guardConstants($constants);
            self::$constants[static::class] = $constants;
        }

        return self::$constants[static::class];
    }
580993
public static final function values() {
		$calledClass = get_called_class();

		// let's check the cache so we don't have to call reflection constantly
		if (empty(self::$cachedValues[$calledClass])) {
			$class = new \ReflectionClass($calledClass);
			self::$cachedValues[$calledClass] = $class->getConstants();
		}

		return self::$cachedValues[$calledClass];
	}