* @author Dennis Eichhorn * @copyright 2013 Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 * @link http://orange-management.com */ namespace phpOMS\Datatypes; /** * Enum class. * * Replacing the SplEnum class and providing basic enum. * * @category Framework * @package phpOMS\Datatypes * @author OMS Development Team * @author Dennis Eichhorn * @license OMS License 1.0 * @link http://orange-management.com * @since 1.0.0 */ abstract class Enum { /** * Caching constant values. * * @var array * @since 1.0.0 */ private static $constCache = null; /** * Checking enum name. * * Checking if a certain const name exists (case sensitive) * * @param \string $name Name of the value (case sensitive) * * @return \bool * * @since 1.0.0 * @author Dennis Eichhorn */ public static function isValidName(\string $name) : \bool { $constants = self::getConstants(); return array_key_exists($name, $constants); } /** * Getting all constants of this enum. * * @return array * * @since 1.0.0 * @author Dennis Eichhorn */ public static function getConstants() : array { if (!isset(self::$constCache)) { $reflect = new \ReflectionClass(get_called_class()); self::$constCache = $reflect->getConstants(); } return self::$constCache; } /** * Check enum value. * * Checking if a given value is part of this enum * * @param mixed $value Value to check * * @return \bool * * @since 1.0.0 * @author Dennis Eichhorn */ public static function isValidValue($value) : \bool { $values = array_values(self::getConstants()); return in_array($value, $values, $strict = true); } }