private static function initializeEnum($enumClass)
    {
        self::$isInInitializationState = true;
        try {
            $classReflection = new ReflectionClass($enumClass);

            // Enumerable must be final:
            if (!$classReflection->isFinal()) {
                throw new LogicException(
                    sprintf('Enumerable class must be final, but "%s" is not final.', $enumClass)
                );
            }

            // Enumerable cannot be Serializable:
            if (is_subclass_of($enumClass, \Serializable::class)) {
                throw new LogicException(
                    sprintf(
                        'Enumerable cannot be serializable, but enum class "%s" implements "Serializable" interface.',
                        $enumClass
                    )
                );
            }

            $methods = $classReflection->getMethods(ReflectionMethod::IS_STATIC);

            self::$enums[$enumClass] = [];
            foreach ($methods as $method) {
                if (self::isServiceMethod($method)) {
                    continue;
                }

                /** @var Enumerable $value */
                $value = $method->invoke(null);

                if (!is_object($value) || get_class($value) !== $enumClass) {
                    throw new LogicException(sprintf(
                        '"%s:%s()" should return an instance of its class. But value of type "%s" returned.',
                        $enumClass,
                        $method,
                        is_object($value) ? get_class($value) : gettype($value)
                    ));
                }

                // Detect duplication of indexes:
                if (array_key_exists($value->getRawValue(), self::$enums[$enumClass])) {
                    throw new LogicException(
                        sprintf('Duplicate of index "%s" in enumerable "%s".', $value->getRawValue(), $enumClass)
                    );
                }
                self::$enums[$enumClass][$value->getRawValue()] = $value;
            }
        } finally {
            self::$isInInitializationState = false;
        }
    }
private static function initializeEnum($enumClass)
    {
        self::$isInInitializationState = true;
        try {
            $classReflection = new ReflectionClass($enumClass);

            // Enumerable must be final:
            if (!$classReflection->isFinal()) {
                throw new LogicException(
                    sprintf('Enumerable class must be final, but "%s" is not final.', $enumClass)
                );
            }

            // Enumerable cannot be Serializable:
            if (is_subclass_of($enumClass, \Serializable::class)) {
                throw new LogicException(
                    sprintf(
                        'Enumerable cannot be serializable, but enum class "%s" implements "Serializable" interface.',
                        $enumClass
                    )
                );
            }

            $methods = $classReflection->getMethods(ReflectionMethod::IS_STATIC);

            self::$enums[$enumClass] = [];
            foreach ($methods as $method) {
                if (self::isServiceMethod($method)) {
                    continue;
                }

                /** @var Enumerable $value */
                $value = $method->invoke(null);

                if (!is_object($value) || get_class($value) !== $enumClass) {
                    throw new LogicException(sprintf(
                        '"%s:%s()" should return an instance of its class. But value of type "%s" returned.',
                        $enumClass,
                        $method,
                        is_object($value) ? get_class($value) : gettype($value)
                    ));
                }

                // Detect duplication of indexes:
                if (array_key_exists($value->getRawValue(), self::$enums[$enumClass])) {
                    throw new LogicException(
                        sprintf('Duplicate of index "%s" in enumerable "%s".', $value->getRawValue(), $enumClass)
                    );
                }
                self::$enums[$enumClass][$value->getRawValue()] = $value;
            }
        } finally {
            self::$isInInitializationState = false;
        }
    }
private static function initializeEnum ( $ enumClass ) { self :: $ isInInitializationState = true ; try { $ classReflection = new ReflectionClass ( $ enumClass ) ; // Enumerable must be final: if ( ! $ classReflection -> isFinal ( ) ) { throw new LogicException ( sprintf ( 'Enumerable class must be final, but "%s" is not final.' , $ enumClass ) ) ; } // Enumerable cannot be Serializable: if ( is_subclass_of ( $ enumClass , \ Serializable :: class ) ) { throw new LogicException ( sprintf ( 'Enumerable cannot be serializable, but enum class "%s" implements "Serializable" interface.' , $ enumClass ) ) ; } $ methods = $ classReflection -> getMethods ( ReflectionMethod :: IS_STATIC ) ; self :: $ enums [ $ enumClass ] = [ ] ; foreach ( $ methods as $ method ) { if ( self :: isServiceMethod ( $ method ) ) { continue ; } /** @var Enumerable $value */ $ value = $ method -> invoke ( null ) ; if ( ! is_object ( $ value ) || get_class ( $ value ) !== $ enumClass ) { throw new LogicException ( sprintf ( '"%s:%s()" should return an instance of its class. But value of type "%s" returned.' , $ enumClass , $ method , is_object ( $ value ) ? get_class ( $ value ) : gettype ( $ value ) ) ) ; } // Detect duplication of indexes: if ( array_key_exists ( $ value -> getRawValue ( ) , self :: $ enums [ $ enumClass ] ) ) { throw new LogicException ( sprintf ( 'Duplicate of index "%s" in enumerable "%s".' , $ value -> getRawValue ( ) , $ enumClass ) ) ; } self :: $ enums [ $ enumClass ] [ $ value -> getRawValue ( ) ] = $ value ; } } finally { self :: $ isInInitializationState = false ; } }
Initializes values of enumerable class.

@param string $enumClass
Initializes values of enumerable class .