Replaces the components left of the path with the components of the given URL.

@param string|Url $newUrl
@param int $opt
@throws InvalidUrlException
@return self
770899
public function replaceHost($newUrl, $opt = self::SCHEME | self::HOST | self::PORT | self::CREDENTIALS)
	{
		if ($newUrl instanceof Url) {
			$url = $newUrl;
		} else if (is_string($newUrl)) {
			$url = new Url($newUrl);
		} else {
			throw new InvalidUrlException();
		}
		$scheme = ($opt & self::SCHEME) === self::SCHEME;
		$host = ($opt & self::HOST) === self::HOST;
		$port = ($opt & self::PORT) === self::PORT;
		$creds = ($opt & self::CREDENTIALS) === self::CREDENTIALS;
		if ($scheme) {
			$this->scheme->set($url->scheme->get());
		}
		if ($host) {
			$this->host->set($url->host->get());
		}
		if ($port) {
			$this->port->set($url->port->get());
		}
		if ($creds) {
			$this->credentials->username = $url->credentials->username;
			$this->credentials->password = $url->credentials->password;
		}
		return $this;
	}
379502
public function removeActiveUrl($activeUrl)
    {
        $activeUrls = json_decode($this->activeUrls, true);
        $positionFound = array_search($activeUrl, $activeUrls);
        if ($positionFound) {
            unset($activeUrls[$positionFound]);
            $this->activeUrls = json_encode($activeUrls);
        }

        return $this;
    }
1162326
public function setUrl($url)
    {
        if (is_string($url)) {
            $this->url = $url;
        } else {
            throw new \InvalidArgumentException(
                "Invalid type '" . gettype($url) . "' for argument 'url' given. String expected."
            );
        }
    }
150499
private function buildUrlWithoutHost($url, array $parameters)
    {
        return $this
            ->urlGeneratorInterface
            ->generate(
                $url,
                $parameters,
                UrlGeneratorInterface::ABSOLUTE_URL
            );
    }
1339880
public function setUrl($url) {
        if (!is_string($url)) throw new IllegalTypeException('Illegal type of parameter $url: '.gettype($url));

        // TODO: validate URL

        if (strpos($url, ' ') !== false)
            throw new InvalidArgumentException('Invalid argument $url: '.$url);

        $this->url = $url;
        return $this;
    }
974327
public function rename($path, $newpath)
    {
        $location = $this->applyPathPrefix($path);
        $destination = $this->applyPathPrefix($newpath);
        $this->ossClient->copyObject($this->bucket, $location, $this->bucket, $destination);
        $this->ossClient->deleteObject($this->bucket, $location);
        return true;
    }
542120
public function replace($old, $new): self
    {
        Assert::typeOf(['string', __CLASS__], $old, $new);

        return new static(str_replace((string) $old, (string) $new, $this->data), $this->encoding);
    }
1258377
public function replace($old, $new)
    {
        $this->str = $this->str->replace((string)$old, (string)$new);

        return $this;
    }
609049
public function setOrderUrl(string $orderUrl): self
    {
        $this->isValidUrl($orderUrl);

        $this->orderUrl = $orderUrl;

        return $this;
    }
1064724
public function refreshFrom($values, $opts, $partial = false)
    {
        $this->_opts = $opts;

        // Wipe old state before setting new.  This is useful for e.g. updating a
        // customer, where there is no persistent card parameter.  Mark those values
        // which don't persist as transient
        if ($partial) {
            $removed = new Util\Set();
        } else {
            $removed = array_diff(array_keys($this->_values), array_keys($values));
        }

        foreach ($removed as $k) {
            if (self::$permanentAttributes->includes($k)) {
                continue;
            }

            unset($this->$k);
        }

        foreach ($values as $k => $v) {
            if (self::$permanentAttributes->includes($k) && isset($this[$k])) {
                continue;
            }

            if (self::$nestedUpdatableAttributes->includes($k) && is_array($v)) {
                $this->_values[$k] = AttachedObject::constructFrom($v, $opts);
            } else {
                $this->_values[$k] = Util\Util::convertToPayjpObject($v, $opts);
            }

            $this->_transientValues->discard($k);
            $this->_unsavedValues->discard($k);
        }
    }
404011
private function format_url($opt) {
		$sign = $this->format_signature ( $opt );
		if ($sign === false) {
			trigger_error ( "Format signature failed, please check!" );
			return false;
		}
		$opt ['sign'] = $sign;
		$url = "";
		$url .= $this->use_ssl ? 'https://' : 'http://';
		$url .= $this->hostname;
		$url .= '/' . $opt [self::BUCKET];
		if (isset ( $opt [self::OBJECT] ) && '/' !== $opt [self::OBJECT]) {
			$url .= "/" . rawurlencode ( $opt [self::OBJECT] );
		}
		$url .= '?' . $sign;
		if (isset ( $opt [self::QUERY_STRING] )) {
			foreach ( $opt [self::QUERY_STRING] as $key => $value ) {
				$url .= '&' . $key . '=' . $value;
			}
		}
		return $url;
	}
613582
public function removeUrl(Url $url)
    {
        if ($this->urls->contains($url)) {
            $this->urls->removeElement($url);
            $url->setSiteroot(null);
        }

        return $this;
    }
657645
public function setUrl($url)
    {
        // validate url
        if (filter_var($url, FILTER_VALIDATE_URL)) {
            $this->url = $url;
        } else {
            throw new InvalidUrlException('"' . $url . '" is not a valid URL');
        }

        return $this;
    }
396363
public function setRewrittenUrl($locale, $url)
    {
        $currentUrl = $this->getRewrittenUrl($locale);
        if ($currentUrl == $url || null === $url) {
            /* no url update */

            return $this;
        }

        try {
            $resolver = new RewritingResolver($url);

            /* we can reassign old url */
            if (null === $resolver->redirectedToUrl) {
                /* else ... */
                if ($resolver->view == $this->getRewrittenUrlViewName() && $resolver->viewId == $this->getId()) {
                    /* it's an url related to the current object */

                    if ($resolver->locale != $locale) {
                        /* it is an url related to this product for another locale */
                        throw new UrlRewritingException(Translator::getInstance()->trans('URL_ALREADY_EXISTS'), UrlRewritingException::URL_ALREADY_EXISTS);
                    }

                    if (\count($resolver->otherParameters) > 0) {
                        /* it is an url related to this product but with more arguments */
                        throw new UrlRewritingException(Translator::getInstance()->trans('URL_ALREADY_EXISTS'), UrlRewritingException::URL_ALREADY_EXISTS);
                    }

                    /* here it must be a deprecated url */
                } else {
                    /* already related to another object */
                    throw new UrlRewritingException(Translator::getInstance()->trans('URL_ALREADY_EXISTS'), UrlRewritingException::URL_ALREADY_EXISTS);
                }
            }
        } catch (UrlRewritingException $e) {
            /* It's all good if URL is not found */
            if ($e->getCode() !== UrlRewritingException::URL_NOT_FOUND) {
                throw $e;
            }
        }

        /* set the new URL */
        if (isset($resolver)) {
            /* erase the old one */
            $rewritingUrl = RewritingUrlQuery::create()->findOneByUrl($url);
            $rewritingUrl->setView($this->getRewrittenUrlViewName())
                ->setViewId($this->getId())
                ->setViewLocale($locale)
                ->setRedirected(null)
                ->save()
            ;

            /* erase additional arguments if any : only happens in case it erases a deprecated url */
            RewritingArgumentQuery::create()->filterByRewritingUrl($rewritingUrl)->deleteAll();
        } else {
            /* just create it */
            $rewritingUrl = new RewritingUrl();
            $rewritingUrl->setUrl($url)
                ->setView($this->getRewrittenUrlViewName())
                ->setViewId($this->getId())
                ->setViewLocale($locale)
                ->save()
            ;
        }

        /* deprecate the old one if needed */
        if (null !== $oldRewritingUrl = RewritingUrlQuery::create()->findOneByUrl($currentUrl)) {
            $oldRewritingUrl->setRedirected($rewritingUrl->getId())->save();
        }

        return $this;
    }
444161
public function redirectTo($url, array $options = array())
    {
        $options = new Hash($options);
        $this->redirectUrl = $url;
        $this->setStatusCode($options->fetch('status', 302));

        $this->getHeaders()->offsetSet('Location', $url);

        return $this;
    }
866669
function buildNewOptions (options, newUrl) {

    // Old method
    /*
    var o = createDefaultOptions(newUrl);

    // Copy only options attributes that are in the options used for the previous request
    // Could be more simple ? ;-)

    o =  _.extend(o, _.pick(options, _.without(_.keys(o), "url")));
    */
    var o = _.clone(options);
    o.url = newUrl;


    o.depthLimit = options.depthLimit;
    o.currentRetries = 0;

    if (options.canCrawl) {
      o.canCrawl = options.canCrawl;
    }

    return o;

 }
964995
public function parseUrl($str)
	{
		if (! is_string($str)) {
			throw new InvalidUrlException('Unexpected type.');
		}
		if ($str === '') {
			throw new InvalidUrlException('Empty URL.');
		}
		if (trim($str, ' ') === '') {
			throw new InvalidUrlException('Empty URL.');
		}
		$components = $this->parseUrlComponents($str);
		$components = array_replace([
			'scheme' => '',
			'host' => '',
			'port' => '',
			'user' => '',
			'pass' => '',
			'path' => '',
			'query' => '',
			'fragment' => ''
		], $components);
		$this->scheme->parseComponent($components['scheme']);
		$this->host->parseComponent($components['host']);
		$this->port->parseComponent(strval($components['port']));
		if (empty($components['user']) && empty($components['pass'])) {
			$this->credentials->username = null;
			$this->credentials->password = null;
		} else {
			$this->credentials->parseComponent($components['user'] . ':' . $components['pass']);
		}
		$this->path->parseComponent($components['path']);
		$this->query->parseComponent($components['query']);
		$this->fragment->parseComponent($components['fragment']);
		return $this;
	}