final public static function byValue($value)
    {
        if (!isset(self::$constants[static::class])) {
            self::detectConstants(static::class);
        }

        $name = \array_search($value, self::$constants[static::class], true);
        if ($name === false) {
            throw new InvalidArgumentException(sprintf(
                'Unknown value %s for enumeration %s',
                \is_scalar($value)
                    ? \var_export($value, true)
                    : 'of type ' . (\is_object($value) ? \get_class($value) : \gettype($value)),
                static::class
            ));
        }

        if (!isset(self::$instances[static::class][$name])) {
            self::$instances[static::class][$name] = new static(self::$constants[static::class][$name]);
        }

        return self::$instances[static::class][$name];
    }