public function toAbsoluteUrl(Url $root = null)
    {
        $root = $this->getRoot() ?: $root;
        if (!$root->isUrlAbsolute()) {
            throw new \InvalidArgumentException();
        }
        if (!$this->isUrlAbsolute()) {
            $this->setScheme($root->getScheme());
            $this->setHost($root->getHost());
            if (!$this->isPathAbsolute()) {
                $path = $root->getPath();
                $path = substr($path, 0, strrpos($path, '/') + 1);
                $this->setPath($path . $this->getPath());
            }
        }
        return $this;
    }