Returns the enum value instance representing the provided const name or null when the const name is not present in
the enum.

@param string $enumName

@return Enum
966147
public static final function byName($enumName)
    {
        $instances = self::getInstances(get_called_class());

        return isset($instances[$enumName])
            ? $instances[$enumName]
            : null;
    }
859599
def get_enum_from_name(self, enum_name):
        
        return next((e for e in self.enums if e.name == enum_name), None)
464502
public static function getEnum()
    {
        $enumClass = get_called_class();

        if (!isset(self::$ConstantsCache[$enumClass])) {
            $reflect = new \ReflectionClass($enumClass);
            self::$ConstantsCache[$enumClass] = $reflect->getConstants();
        }

        return self::$ConstantsCache[$enumClass];
    }
442929
protected function buildClass($name)
    {
        $className = $this->formatClassName($name);

        if (!class_exists($className)) {
            throw new RuntimeException('Enum '.$className.' is not exists');
        }

        $enum = new $className();
        if (!$enum instanceof Enumable) {
            throw new RuntimeException('Enum '.$className.' is not instance of '.Enumable::class);
        }

        return $enum;
    }
29528
public function remove(Enum $enum)
    {
        $this->checkType($enum);

        $enumName = $enum->getConstName();

        if (isset($this->valueMap[$enumName])) {
            $value = $this->valueMap[$enumName];

            unset($this->valueMap[$enumName]);

            $index = array_search($enum, $this->mappedEnums);
            unset($this->mappedEnums[$index]);

            return $value;
        }

        return null;
    }
1206127
public function enumValuesForField($tableName, $fieldName)
    {
        $classes = array();

        // Get the enum of all page types from the SiteTree table
        $clause = $this->getConstraintCheckClause($tableName, $fieldName);
        if ($clause) {
            $classes = $this->enumValuesFromCheckClause($clause);
        }

        return $classes;
    }
1101894
public static function enum()
    {
        $res = array();
        $r = self::getDbConnection()->query('SELECT * FROM menus ORDER BY name');
        while ($f = $r->fetch()) {
             $res[] = new self($f);
        }
        return $res;
    }
1011670
public static function valueOf($name)
    {
        $names = static::getNames();
        return isset($names[$name]) ? $names[$name] : null;
    }
314836
public function __getSerialisablePropertyValue($propertyName)
    {
        try {
            return parent::__getSerialisablePropertyValue($propertyName);
        } catch (PropertyNotReadableException $e) {
            if ($this->__strictMode) {
                throw $e;
            } else {
                return null;
            }
        }
    }
1299115
public function getAttributeValue($key)
    {
        $value = parent::getAttributeValue($key);

        if ($this->hasEnumCast($key)) {
            $value = $this->castToEnum($key, $value);
        }

        return $value;
    }
349051
final public function equals($value)
    {
        if ($value instanceof Enum) {
            return $this->value == $value->getValue();
        }
        return $this->value == $value;
    }
1045882
final public static function byName(string $name)
    {
        if (isset(self::$instances[static::class][$name])) {
            return self::$instances[static::class][$name];
        }

        $const = static::class . "::{$name}";
        if (!\defined($const)) {
            throw new InvalidArgumentException("{$const} not defined");
        }

        return self::$instances[static::class][$name] = new static(\constant($const));
    }
387488
public final function getHeaderValue($name)
    {
        self::checkString($name);

        foreach ($this->_headers as $headerName => $headerValue) {

            if (strcasecmp($name, $headerName) === 0) {

                return $headerValue;
            }
        }

        return null;
    }
397562
public static function getValue($enumKey = '')
    {
        foreach (self::all() as $key => $value) {
            if (strtolower($key) == strtolower($enumKey)) {
                return $value;
            }
        }

        return null;
    }
669497
public static function getValueForName($name)
    {
        foreach (self::getConstants() as $constant) {
            if ($constant['name'] === $name) {
                return $constant['value'];
            }
        }
        return false;
    }
394293
public function getValue($name)
    {
        if (isset($this->map[$name])) {
            return $this->map[$name]->getValue();
        }

        return null;
    }
969634
public Object getEnumValue(String name) {
		if (this.kind != Kind.ENUM)
			throw new RuntimeException("getEnumValue(..) can only be called on an enum");
		Object[] vals = getEnumValues();
		if (vals != null) {
			for (Object val : vals) {
				if (((Enum<?>)val).name().equals(name))
					return val;
			}
		}
		return null;
	}