public function withMiddleware(...$middleware): RouteInterface
    {
        $route = clone $this;

        // array fallback
        if (count($middleware) == 1 && is_array($middleware[0])) {
            $middleware = $middleware[0];
        }

        foreach ($middleware as $item) {
            if (!is_string($item) && !$item instanceof MiddlewareInterface) {
                if (is_object($item)) {
                    $name = get_class($item);
                } else {
                    $name = gettype($item);
                }

                throw new RouteException("Invalid middleware `{$name}`.");
            }

            $route->middleware[] = $item;
        }

        if (!empty($route->pipeline)) {
            $route->pipeline = $route->makePipeline();
        }

        return $route;
    }