_value = $value; } /** * Check if the enum has the given value * * @param string $value * @return bool the enum has the value */ public function has($value) { return in_array($value, self::toArray(), true); } /** * Check if the enum is defined * * @param string $value the value of the enum * * @return bool True if the value is defined */ public function is($value) { return $this->_value === $value; } /** * Create a new class for the enum in question * * @return mixed * @throws \ReflectionException */ public function toArray() { $class = get_called_class(); if (!(array_key_exists($class, self::$constants))) { $reflectionObj = new \ReflectionClass($class); self::$constants[$class] = $reflectionObj->getConstants(); } return self::$constants[$class]; } /** * Get the value of the enum * * @return string value of the enum */ public function value() { return $this->_value; } }