public static function getKeyByValue($needle)
    {
        $classname = get_called_class();
        $reflection = new ReflectionClass($classname);

        foreach ($reflection->getConstants() as $name => $value) {
            if (strtolower($value) === strtolower($needle)
             || strtolower($name) === strtolower($needle)) {
                return $name;
            }
        }

        throw new ErrorException("Value '{$needle}' does not match enumeration '{$classname}'");
    }