public static function create(ContainerInterface $container, string $class, array $map = [], array $params = null)
    {
        if (!\class_exists($class)) {
            throw new \InvalidArgumentException("unable to create component: {$class} (autoloading failed)");
        }

        if (\method_exists($class, 'getInstance')) {
            return $class::getInstance();
        }

        if ($params === null) {
            $reflection = new \ReflectionClass($class);

            if (!$reflection->isInstantiable()) {
                throw new \InvalidArgumentException("unable to create instance of abstract class: {$class}");
            }

            $constructor = $reflection->getConstructor();

            if ($constructor && ($params = $constructor->getParameters()) !== []) {
                $params = static::resolve($container, $params, $map, false);
            } else {
                $params = [];
            }

            return $reflection->newInstanceArgs($params);
        }

        if ($params !== []) {
            $params = static::resolve($container, $params, $map, false);
        }

        return new $class(...$params);
    }