Helper class method to create a Connectabl object from
a fully qualified base url.

@param   string  $baseUrl
@return  \NEM\Traits\Connectable
337042
public function fillFromBaseUrl($baseUrl)
    {
        $reg = "/^(https?):\/\/((www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6})(:([0-9]+))?/";
        $matches = [];

        $scheme = "http";
        $host   = "hugealice.nem.ninja";
        $port   = 7890;
        if ((bool) preg_match_all($reg, $baseUrl, $matches)) {
            $scheme = $matches[1][0];
            $host   = $matches[2][0];
            $port   = $matches[5][0];
        }

        $this->setUseSsl($scheme === "https");
        $this->setProtocol($scheme);
        $this->setHost($host);
        $this->setPort((int) $port);
        return $this;
    }
813140
public function setUrl($url)
    {
        $this->httpClientBuilder->removePlugin(AddHostPlugin::class);
        $this->httpClientBuilder->addPlugin(new AddHostPlugin(UriFactoryDiscovery::find()->createUri($url)));

        return $this;
    }
1138060
private function getRequest($url)
    {
        if ($this->baseUri && substr($url, 0, 1) != '/') {
            throw new \InvalidArgumentException(
                sprintf("Invalid uri '%s' with baseUri '%s'", $url, $this->baseUri->get(false))
            );
        }

        if ($this->baseUri && $url) {
            $uri = clone $this->baseUri;
            $uri->setPath($uri->getPath() . $url);
        } else {
            $uri = $url instanceof Uri ? $url : new Uri($url);
        }

        return new Request($uri);
    }
348568
public function setBaseUrl($baseUrl)
    {
        if (substr($baseUrl, 0, 2) === '//') {
            $baseUrl = 'http:'.$baseUrl;
            $this->isRelativeDomain = true;
        }

        $this->baseUrl = rtrim($baseUrl, '/');
    }
1314137
private function applyBaseUrl(string $url): string
    {
        if ($this->baseUrl === null) {
            return $url;
        }

        if (substr($url, 0, 7) === "http://") {
            return $url;
        }

        if (substr($url, 0, 8) === "https://") {
            return $url;
        }

        $baseUrl = $this->baseUrl;

        if (substr($url, 0, 1) === "/") {
            $path = parse_url($baseUrl, \PHP_URL_PATH);
            if ($path !== null) {
                $baseUrl = substr($baseUrl, 0, strlen($path) * -1);
            }
        }

        return "{$baseUrl}/" . ltrim($url, "/");
    }
870660
private function makeAbsoluteStr($base, $url)
    {
        if (!$url) {
            return false;
        }

        if (preg_match('!^https?://!i', $url)) {
            // already absolute
            return $url;
        }

        $base = new \SimplePie_IRI($base);

        // remove '//' in URL path (causes URLs not to resolve properly)
        if (isset($base->ipath)) {
            $base->ipath = preg_replace('!//+!', '/', $base->ipath);
        }

        if ($absolute = \SimplePie_IRI::absolutize($base, $url)) {
            return $absolute->get_uri();
        }

        return false;
    }
1192816
public function setUrl($url)
    {
        if (!is_null($url)) {
            if (!preg_match('@^https?://@', $url)) {
                throw new \InvalidArgumentException(sprintf('Invalid url: %s', $url));
            }

            $this->url = $url;
        } else {
            $this->url = null;
        }

        return $this;
    }
310326
public function baseUrl($url = null)
    {
        if (!is_null($url) && true !== $url) {
            $this->baseUrl = $url;
            return $this;
        } elseif (!$this->baseUrl) {
            $str           = $this->url();
            $this->baseUrl = strpos($str, '?') ? strstr($str, '?', true) : $str;
        }
        return true === $url ? $this->domain() . $this->baseUrl : $this->baseUrl;
    }
681204
public function baseUrl($targetPath = null)
    {
        if (!isset($this->baseUrl)) {
            throw new RuntimeException(sprintf(
                'The base URI is not defined for [%s]',
                get_class($this)
            ));
        }

        if ($targetPath !== null) {
            return $this->createAbsoluteUrl($this->baseUrl, $targetPath);
        }

        return rtrim($this->baseUrl, '/').'/';
    }
393603
protected function createUrl($url)
    {
        // is absolute URL?
        if (strpos($url, '://')) {
            return Url::createFromUrl($url);
        }

        // only query and path matters in relative url
        $url = Url::createFromUrl($url);
        $query = $this->baseUrl->getQuery();
        $path = $this->baseUrl->getPath();

        $query->modify($url->getQuery());
        $path->append($url->getPath());

        return $this->baseUrl->setQuery($query)->setPath($path);
    }
1082189
public function getBaseUrl()
    {
        if(!$this->_base_url instanceof HttpUrl)
        {
            $base = clone $this->getUrl();
            $base->setUrl(rtrim((string)$this->_base_url, '/'));

            $this->_base_url = $this->getObject('lib:http.url', array('url' => $base->toString(HttpUrl::BASE)));
        }

        return $this->_base_url;
    }
1080643
public function setUrl($url)
    {
        $relation = new RelationLink();
        $relation
            ->setRelationType('self')
            ->setUrl($url);
        return $this->setRelation($relation);
    }
17436
public function buildUrlString($baseUrl, $resource)
    {
        if (null === $baseUrl || '' == $baseUrl) {
            return null;
        }

        if (null === $resource || '' == $resource) {
            return $baseUrl;
        }

        $baseUrl = $this->removeTrainingSlash($baseUrl);
        if (!substr($resource, 0, 1) == '/') {
            $resource = '/' . $resource;
        }

        return $baseUrl . $resource;
    }
831400
public function getBaseUrl()
    {
        if ($this->baseUrl) {
            return $this->baseUrl;
        }
        if ($this->baseUrlProvider) {
            return call_user_func($this->baseUrlProvider, $this);
        }

        return $this->baseUrl;
    }
826401
public static function create(string $baseUrl, array $headers = [], $timeout = 30, bool $allowRedirects = false): Client
    {
        return new Client([
            'base_uri' => $baseUrl,
            'headers'  => $headers,
            'timeout'  => $timeout,
            'allow_redirects' => $allowRedirects,
        ]);
    }
677406
public static function getBaseURL($url){

		$parsed_url = parse_url($url);
		if($parsed_url === false){

			throw new ErrorException('Malformed URL.');
		}

		$base_url = [];

		if(empty($parsed_url['scheme'])){

			throw new ErrorException('Malformed URL, no scheme.');
		}

		$base_url[] = $parsed_url['scheme'];
		$base_url[] = '://';
		$base_url[] = $parsed_url['host'];

		// Check the path

		$path = $parsed_url['path'];
		$path_parts = explode('/', $path);

		// Discard the first slash.

		array_shift($path_parts);
		$base = array_shift($path_parts);

		// Check if we're on localhost
		if(strpos($base, '~') !== false){

			$base_url[] = '/' . $base;
		};

		$base_url[] = '/';

		return implode('', $base_url);
	}
112666
protected function createBaseRequest($relativeUrl)
	{
		$baseUrl = $this->getBaseUrl(false);
		$request = new \Zend\Http\Request();
		$request->setUri($baseUrl.$relativeUrl);
		$request->setMethod(\Zend\Http\Request::METHOD_POST);
		$request->getHeaders()->addHeaders(array(
			'Content-Type'=>'application/x-www-form-urlencoded; charset=UTF-8',
			'Accept-Encoding'=>'identity')); // plain text

		$this->addDefaultParameters($request);

		return $request;
	}