src/Leevel/Database/Ddd/Entity.php
public static function enum(string $prop, $enum = null, string $separate = ',')
    {
        $prop = static::normalize($prop);
        $enumDefined = static::class.'::'.strtoupper($prop).'_ENUM';

        if (!defined($enumDefined)) {
            return false;
        }

        if (!isset(static::$leevelEnums[static::class]) ||
            !isset(static::$leevelEnums[static::class][$prop])) {
            $enums = constant($enumDefined);
            $enums = array_values($enums);

            foreach ($enums as &$e) {
                if (!isset($e[1])) {
                    $e = sprintf('Invalid enum in the field `%s` of entity `%s`.', $prop, static::class);

                    throw new InvalidArgumentException($e);
                }

                $e[1] = __($e[1]);
            }

            static::$leevelEnums[static::class][$prop] = $enums;
        } else {
            $enums = static::$leevelEnums[static::class][$prop];
        }

        if (null === $enum) {
            return $enums;
        }

        $enums = array_column($enums, 1, 0);
        $enumSep = explode(',', (string) $enum);

        foreach ($enumSep as $v) {
            if (!isset($enums[$v]) && !isset($enums[(int) $v])) {
                $e = sprintf('Value not a enum in the field `%s` of entity `%s`.', $prop, static::class);

                throw new InvalidArgumentException($e);
            }

            $result[] = isset($enums[$v]) ? $enums[$v] : $enums[(int) $v];
        }

        return implode($separate, $result);
    }
public static function enum(string $prop, $enum = null, string $separate = ',')
    {
        $prop = static::normalize($prop);
        $enumDefined = static::class.'::'.strtoupper($prop).'_ENUM';

        if (!defined($enumDefined)) {
            return false;
        }

        if (!isset(static::$leevelEnums[static::class]) ||
            !isset(static::$leevelEnums[static::class][$prop])) {
            $enums = constant($enumDefined);
            $enums = array_values($enums);

            foreach ($enums as &$e) {
                if (!isset($e[1])) {
                    $e = sprintf('Invalid enum in the field `%s` of entity `%s`.', $prop, static::class);

                    throw new InvalidArgumentException($e);
                }

                $e[1] = __($e[1]);
            }

            static::$leevelEnums[static::class][$prop] = $enums;
        } else {
            $enums = static::$leevelEnums[static::class][$prop];
        }

        if (null === $enum) {
            return $enums;
        }

        $enums = array_column($enums, 1, 0);
        $enumSep = explode(',', (string) $enum);

        foreach ($enumSep as $v) {
            if (!isset($enums[$v]) && !isset($enums[(int) $v])) {
                $e = sprintf('Value not a enum in the field `%s` of entity `%s`.', $prop, static::class);

                throw new InvalidArgumentException($e);
            }

            $result[] = isset($enums[$v]) ? $enums[$v] : $enums[(int) $v];
        }

        return implode($separate, $result);
    }
获取 enum.
不存在返回 false.

@param string $prop
@param mixed  $enum
@param string $separate

@return mixed