public function route(string $method, string $pattern, $handler, $name = null, ?RouteInfo $info = null): void
    {
        if ($name instanceof RouteInfo) {
            $info = $name;
            $name = '@' . Route::nextId();
        } elseif ($name === null) {
            $name = '@' . Route::nextId();
        } elseif ($name === '' || $name[0] == '@' || false !== \strpos($name, ':')) {
            throw new \InvalidArgumentException(\sprintf('Invalid route name: "%s"', $name));
        }
        
        if (!$handler instanceof RequestHandlerInterface && !\is_string($handler) && !\is_callable($handler)) {
            $type = \is_object($handler) ? \get_class($handler) : \gettype($handler);
            
            throw new \InvalidArgumentException(\sprintf('Unsupported route handler type: %s', $type));
        }
        
        if (isset($this->routes[$name])) {
            throw new \RuntimeException(\sprintf('Duplicate registration of named route: "%s"', $name));
        }
        
        $produces = $info ? $info->getProducedTypes() : null;
        $consumes = $info ? $info->getConsumedTypes() : null;
        
        $this->routes[$name] = new Route($method, '/' . \trim($pattern, '/'), $handler, $name, $produces, $consumes);
    }