Parse a url string into an object

@param string $url
@return \sndsgd\Url
490771
public static function createFromString($url)
    {
        if (!is_string($url)) {
            throw new \InvalidArgumentException(
                "invalid value provided for 'url'; expecting a string"
            );
        }

        $ret = new Url;
        if (($url = trim($url)) === '') {
            return $ret;
        }

        if (($url = parse_url($url)) === false) {
            throw new \InvalidArgumentException(
                "invalid value provided for 'url'; ".
                "url parsing failed"
            );
        }

        foreach ($url as $k => $v) {
            $fn = 'set'.ucfirst($k);
            call_user_func([$ret, $fn], $v);
        }
        return $ret;
    }
967625
public static function segmentizeUrl($url)
        {
            $url = self::normalizeUrl($url);
            $segments = explode('/', $url);

            $result = array();

            foreach ($segments as $segment) {
                if (strlen($segment)) $result[] = $segment;
            }

            return $result;
        }
521995
public static function parse_URL($url)
	{
		$params = parse_url($url);
		$params['extras'] = array();
		if (isset($params['query']))
		{
			parse_str($params['query'], $params['extras']);
		}
		return $params;
	}
486994
public static function multibyteParseUrl($url)
    {
        $enc_url = preg_replace_callback(
            '%[^:/@?&=#]+%usD',
            function ($matches) {
                return urlencode($matches[0]);
            },
            $url
        );

        $parts = parse_url($enc_url);

        if($parts === false) {
            throw new \InvalidArgumentException('Malformed URL: ' . $url);
        }

        foreach($parts as $name => $value) {
            $parts[$name] = urldecode($value);
        }

        return $parts;
    }
919349
protected static function parseUrl($url)
	{
		$regexp = '(^(?:([a-z][-+.\\w]*):)?(?://(?:([^:/?#]*)(?::([^/?#]*)?)?@)?(?:(\\[[a-f\\d:]+\\]|[^:/?#]+)(?::(\\d*))?)?(?![^/?#]))?([^?#]*)(\\?[^#]*)?(#.*)?$)Di';

		// NOTE: this regexp always matches because of the last three captures
		preg_match($regexp, $url, $m);

		$parts  = [];
		$tokens = ['scheme', 'user', 'pass', 'host', 'port', 'path', 'query', 'fragment'];
		foreach ($tokens as $i => $name)
		{
			$parts[$name] = (isset($m[$i + 1])) ? $m[$i + 1] : '';
		}

		/**
		* @link http://tools.ietf.org/html/rfc3986#section-3.1
		*
		* 'An implementation should accept uppercase letters as equivalent to lowercase in
		* scheme names (e.g., allow "HTTP" as well as "http") for the sake of robustness but
		* should only produce lowercase scheme names for consistency.'
		*/
		$parts['scheme'] = strtolower($parts['scheme']);

		/**
		* Normalize the domain label separators and remove trailing dots
		* @link http://url.spec.whatwg.org/#domain-label-separators
		*/
		$parts['host'] = rtrim(preg_replace("/\xE3\x80\x82|\xEF(?:\xBC\x8E|\xBD\xA1)/s", '.', $parts['host']), '.');

		// Test whether host has non-ASCII characters and punycode it if possible
		if (preg_match('#[^[:ascii:]]#', $parts['host']) && function_exists('idn_to_ascii'))
		{
			$variant = (defined('INTL_IDNA_VARIANT_UTS46')) ? INTL_IDNA_VARIANT_UTS46 : 0;
			$parts['host'] = idn_to_ascii($parts['host'], 0, $variant);
		}

		return $parts;
	}
434572
public static function google(Url $url)
    {
        if (($value = $url->getQueryParameter('url'))) {
            return Url::create($value);
        }

        return $url;
    }
783931
protected function parseUrl($url)
    {
        if ($parsed = parse_url($url)) {
            return $this->addPassword($parsed);
        }

        // A second try for not file:// schemes which does support absolute
        // paths (like sqlite:///)

        // Cut the scheme by hand
        $parts = explode(':', $url, 2);

        if (count($parts) != 2 || strlen($parts[0]) > 24) {
            throw new InvalidArgumentException("Unparseable url $url");
        }

        // Now cheat parse_url by giving it a file url
        if (!$parsed = parse_url('file:'.$parts[1])) {
            throw new InvalidArgumentException("Unparseable url $url");
        }

        $parsed['scheme'] = $parts[0];

        return $this->addPassword($parsed);
    }
1235776
public function url($url)
    {
        if (parse_url($url, PHP_URL_SCHEME) == '') {
            $url = wei()->request->getUrlFor($url);
        }

        $this->request['url'] = $url;

        return $this;
    }
1261690
public function parse($url)
    {
        if (!$url) {
            $url = '/';
        }

        $Routes = TableRegistry::get('Wasabi/Core.Routes');

        $route = $Routes->find()
            ->orWhere([$Routes->aliasField('page_type') => 'collection'])
            ->orWhere([$Routes->aliasField('page_type') => 'simple'])
            ->andWhere([$Routes->aliasField('url') => $url])
            ->first();

        $pageNumber = false;

        $urlParts = explode('/', $url);

        // no direct route found -> try paged collection routes
        if (!$route) {
            $part = array_pop($urlParts);

            if (preg_match('/^[0-9]+$/', $part)) {
                $pageNumber = (int)$part;
                $part = array_pop($urlParts);
            }

            // paged url found so lets try to find a proper collection route
            if ($pageNumber !== false && $part === self::PAGE_PART) {
                $route = $Routes->find()->where([
                    $Routes->aliasField('page_type') => 'collection',
                    $Routes->aliasField('url') => join('/', $urlParts)
                ])->first();
            }
        }

        if (!$route) {
            return false;
        }

        if ($route->redirect_to !== null) {
            /** @var \Wasabi\Core\Model\Entity\Route $redirectRoute */
            $redirectRoute = $Routes->get($route->redirect_to);

            $redirectUrl = $redirectRoute->url;
            $statusCode = 301;
            if ($pageNumber !== false && $pageNumber > 1) {
                $redirectUrl .= '/' . self::PAGE_PART . '/' . $pageNumber;
            }
            if ($route->status_code !== null) {
                $statusCode = (int)$route->status_code;
            }

            $this->_redirect($redirectUrl, $statusCode);
        }

        // Dispatch Wasabi.Routes.parse event to all plugin listeners to get params.
        $routesParseEvent = new Event('Wasabi.Routes.parse', $url, [
            'route' => $route,
            'pageNumber' => $pageNumber
        ]);

        EventManager::instance()->dispatch($routesParseEvent);

        if (!$routesParseEvent->isStopped() || empty($routesParseEvent->result['params'])) {
            return false;
        }

        $params = $routesParseEvent->result['params'];

        return $params;
    }
879394
public static function normalizeUrl($url)
        {
            if (substr($url, 0, 1) != '/') $url = '/' . $url;

            if (substr($url, -1) == '/') $url = substr($url, 0, -1);

            if (!strlen($url)) $url = '/';

            return $url;
        }
1106594
public static function parse(string $url): UrlInterface
    {
        if (!self::myParse(null, $url, $scheme, $host, $port, $path, $queryString, $fragment, $error)) {
            throw new UrlInvalidArgumentException($error);
        }

        return new self($scheme, $host, $port, $path, $queryString, $fragment);
    }
100056
public function url($url)
    {
        if (strpos($url, 'https:') === 0) {
            $this->def['ssl'] = true;
        } else {
            if (strpos($url, 'http:') === false && strpos($url, '//') === false) {
                $url = 'http://' . $url;
            }
        }
        
        $this->def['url'] = $url;
        return $this;
    }
924050
protected static function parseHost($url)
    {
        // Get base hostname
        $host = parse_url($url, PHP_URL_HOST);
        if (!$host) {
            return null;
        }

        // Include port
        $port = parse_url($url, PHP_URL_PORT);
        if ($port) {
            $host .= ':' . $port;
        }

        return $host;
    }
989552
protected function parseURL($url)
    {
        $parsed = parse_url($url);
        if ($parsed === false) {
            return false;
        } elseif (!isset($parsed['scheme']) || !$this->isValidScheme($parsed['scheme'])) {
            return false;
        } else {
            if (!isset($parsed['host']) || !$this->isValidHostName($parsed['host'])) {
                return false;
            } else {
                if (!isset($parsed['port'])) {
                    $parsed['port'] = getservbyname($parsed['scheme'], 'tcp');
                    if (!is_int($parsed['port'])) {
                        return false;
                    }
                }
            }
        }
        $parsed['custom'] = (isset($parsed['path']) ? $parsed['path'] : '/') . (isset($parsed['query']) ? '?' . $parsed['query'] : '');
        return $parsed;
    }
851106
public function parse($url) {
		// iterate all rules
		$hit = false;

		foreach ($this->_routes as $rule => $new_class) {
			$regex		= trim($rule, '/');

			// rebuild route to a preg pattern
			if (preg_match($regex, $url, $parameters)) {
				$class = preg_replace($regex, $new_class, $url);
				$class = str_replace('/', '_', $class);
				unset($parameters[0]);
				$hit = true;
				break;
			}
		}

		if ($hit === false) {
			$class = call_user_func($this->_fallback, $url);
		}

		$class_shards = explode('\\', $class);
		$class_shards[count($class_shards)-1] = ucfirst(strtolower($class_shards[count($class_shards)-1]));
		$class = implode('\\', $class_shards);

		return [
			'controller'		=> $class,
			'parameters'		=> isset($parameters) ? $parameters : [],
		];
	}
1004014
protected function createUri($url)
	{
		if ($url instanceof Uri)
		{
			return $url;
		}

		// Create full URL if we are only appending variables to it
		if (substr($url, 0, 1) == '&')
		{
			$vars = array();

			if (strpos($url, '&amp;') !== false)
			{
				$url = str_replace('&amp;', '&', $url);
			}

			parse_str($url, $vars);

			$vars = array_merge($this->vars(), $vars);

			foreach ($vars as $key => $var)
			{
				if ($var == '')
				{
					unset($vars[$key]);
				}
			}

			$url = 'index.php?' . urldecode(http_build_query($vars, '', '&'));
		}

		return new Uri($url);
	}
86211
protected static function parseUrl($url)
    {
        $components = @parse_url($url);
        if (! empty($components)) {
            return $components;
        }

        if (is_null(static::$is_parse_url_bugged)) {
            static::$is_parse_url_bugged = ! is_array(@parse_url("//example.org:80"));
        }

        //bugfix for https://bugs.php.net/bug.php?id=68917
        if (static::$is_parse_url_bugged &&
            strpos($url, '/') === 0 &&
            is_array($components = @parse_url('http:'.$url))
        ) {
            unset($components['scheme']);
            return $components;
        }
        throw new RuntimeException(sprintf("The given URL: `%s` could not be parse", $url));
    }