src/Headzoo/Core/AbstractEnum.php
private static function validate()
    {
        $me = get_called_class();
        if (!isset(self::$consts[$me])) {
            $constants = self::constants();
            if (!isset($constants["__DEFAULT"])) {
                self::toss(
                    "UndefinedConstantException",
                    "Class {me} does have a __DEFAULT constant."
                );
            }

            foreach($constants as $name => $value) {
                if ("__DEFAULT" !== $name && $name !== $value) {
                    self::toss(
                        "LogicException",
                        "Constant {me}:{0} does not match value {1}.",
                        $name,
                        $value
                    );
                }
            }

            self::$consts[$me] = $constants;
        }

        return self::$consts[$me];
    }
private static function validate()
    {
        $me = get_called_class();
        if (!isset(self::$consts[$me])) {
            $constants = self::constants();
            if (!isset($constants["__DEFAULT"])) {
                self::toss(
                    "UndefinedConstantException",
                    "Class {me} does have a __DEFAULT constant."
                );
            }

            foreach($constants as $name => $value) {
                if ("__DEFAULT" !== $name && $name !== $value) {
                    self::toss(
                        "LogicException",
                        "Constant {me}:{0} does not match value {1}.",
                        $name,
                        $value
                    );
                }
            }

            self::$consts[$me] = $constants;
        }

        return self::$consts[$me];
    }
private static function validate ( ) { $ me = get_called_class ( ) ; if ( ! isset ( self :: $ consts [ $ me ] ) ) { $ constants = self :: constants ( ) ; if ( ! isset ( $ constants [ "__DEFAULT" ] ) ) { self :: toss ( "UndefinedConstantException" , "Class {me} does have a __DEFAULT constant." ) ; } foreach ( $ constants as $ name => $ value ) { if ( "__DEFAULT" !== $ name && $ name !== $ value ) { self :: toss ( "LogicException" , "Constant {me}:{0} does not match value {1}." , $ name , $ value ) ; } } self :: $ consts [ $ me ] = $ constants ; } return self :: $ consts [ $ me ] ; }
Validates the enum class definition for correctness

Checks the class has defined a __DEFAULT constant, and that the constant names and values
match each other. This check only needs to be performed the first time an instance of the
class is created, so the results of the validation are cached in the self::$consts property.
Future invocations of the class will skip the validation checks.

The self::$consts property must be static so each instance has access to the same cache data.
Once a class has been validated, an array of the class constants are saved in the self::$consts
array using the name of the validated class as the key.

Returns an array of the class constants.

@return array
@throws \Headzoo\Core\Exceptions\LogicException When the child class defines constants with non-string values
@throws \Headzoo\Core\Exceptions\UndefinedConstantException When the child class does not define a __DEFAULT constant
Validates the enum class definition for correctness