Parse a given URI and populate the class fields.

@param   string  $uri  The URI string to parse.

@return  boolean  True on success.

@since   1.0
192461
protected function parse($uri)
	{
		// Set the original URI to fall back on
		$this->uri = $uri;

		/*
		 * Parse the URI and populate the object fields. If URI is parsed properly,
		 * set method return value to true.
		 */

		$parts = UriHelper::parse_url($uri);

		$retval = ($parts) ? true : false;

		// We need to replace &amp; with & for parse_str to work right...
		if (isset($parts['query']) && strpos($parts['query'], '&amp;'))
		{
			$parts['query'] = str_replace('&amp;', '&', $parts['query']);
		}

		$this->scheme   = isset($parts['scheme']) ? $parts['scheme'] : null;
		$this->user     = isset($parts['user']) ? $parts['user'] : null;
		$this->pass     = isset($parts['pass']) ? $parts['pass'] : null;
		$this->host     = isset($parts['host']) ? $parts['host'] : null;
		$this->port     = isset($parts['port']) ? $parts['port'] : null;
		$this->path     = isset($parts['path']) ? $parts['path'] : null;
		$this->query    = isset($parts['query']) ? $parts['query'] : null;
		$this->fragment = isset($parts['fragment']) ? $parts['fragment'] : null;

		// Parse the query
		if (isset($parts['query']))
		{
			parse_str($parts['query'], $this->vars);
		}

		return $retval;
	}
763238
public function check($uri)
    {
        $url = parse_url($uri);
        if (isset($url['query'])) {
            parse_str($url['query'], $params);
        } else {
            $params = [];
        }

        if (empty($params[$this->parameter])) {
            return false;
        }

        $hash = $params[$this->parameter];
        unset($params[$this->parameter]);

        return $this->computeHash($this->buildUrl($url, $params)) === $hash;
    }
386362
public function parseRequest(Message\Uri $uri = null)
    {
        $this->uri = is_null($uri) ? server_request()->getUri() : $uri;
        $uriSegments = $this->uri->getSegments()->getParts();
        $uriString = $this->uri->getSegments()->getString();

        if (count($uriSegments)) {
            if (strpos(end($uriSegments), '.json') !== false) {
                output()->setContentType('application/json');
                $endSegment = str_replace('.json', '', end($uriSegments));
                array_pop($uriSegments);
                array_push($uriSegments, $endSegment);
                $this->uri = $this->uri->withSegments(new Message\Uri\Segments($uriSegments));
                $uriString = $this->uri->getSegments()->getString();
            } elseif (strpos(end($uriSegments), '.xml') !== false) {
                output()->setContentType('application/xml');
                $endSegment = str_replace('.xml', '', end($uriSegments));
                array_pop($uriSegments);
                array_push($uriSegments, $endSegment);
                $this->uri = $this->uri->withSegments(new Message\Uri\Segments($uriSegments));
                $uriString = $this->uri->getSegments()->getString();
            }
        } else {
            $uriPath = urldecode(
                parse_url($_SERVER[ 'REQUEST_URI' ], PHP_URL_PATH)
            );

            $uriPathParts = explode('public/', $uriPath);
            $uriPath = end($uriPathParts);

            if ($uriPath !== '/') {
                $uriString = $uriPath;
                $uriSegments = array_filter(explode('/', $uriString));

                $this->uri = $this->uri->withSegments(new Message\Uri\Segments($uriSegments));
                $uriString = $this->uri->getSegments()->getString();
            }
        }

        // Try to translate from uri string
        if (false !== ($action = $this->addresses->getTranslation($uriString))) {
            if ( ! $action->isValidHttpMethod(server_request()->getMethod()) && ! $action->isAnyHttpMethod()) {
                output()->sendError(405);
            } else {
                if (false !== ($parseSegments = $action->getParseUriString($uriString))) {
                    $uriSegments = $parseSegments;
                } else {
                    $uriSegments = [];
                }

                $this->uri = $this->uri->withSegments(new Message\Uri\Segments($uriSegments));

                $this->parseAction($action, $uriSegments);

                if (services()->has('controller')) {
                    return true;
                }
            }
        }

        // Try to get route from controller & page
        if ($uriTotalSegments = count($uriSegments)) {
            $namespaces = [
                'App\Controllers\\',
                'App\Http\Controllers\\',
                'O2System\Reactor\Http\Controllers\\',
            ];

            for ($i = 0; $i <= $uriTotalSegments; $i++) {
                $uriRoutedSegments = array_slice($uriSegments, 0, ($uriTotalSegments - $i));

                foreach ($namespaces as $namespace) {

                    $controllerClassName = $namespace . implode('\\',
                            array_map('studlycase', $uriRoutedSegments));

                    if (class_exists($controllerClassName)) {
                        $uriSegments = array_diff($uriSegments, $uriRoutedSegments);
                        $this->setController(new Router\DataStructures\Controller($controllerClassName),
                            $uriSegments);
                        break;
                    }
                }

                // break the loop if the controller has been set
                if (services()->has('controller')) {
                    return true;
                    break;
                }
            }
        }

        // Let's the app do the rest when there is no controller found
        // the app should redirect to PAGE 404
    }
1096048
public function validateUri($uri)
    {
        $uri = (string)$uri;
        if (!$uri) {
            throw new InvalidArgumentException('Invalid URI');
        }

        $scheme = parse_url($uri, PHP_URL_SCHEME);
        $this->validateScheme($scheme);

        $host = parse_url($uri, PHP_URL_HOST);
        if (!$host) {
            throw new InvalidArgumentException("Invalid host");
        }

        $port = parse_url($uri, PHP_URL_PORT);
        if (!$port) {
            $port = $this->getPort($scheme);
        }

        $path = parse_url($uri, PHP_URL_PATH);
        if (!$path) {
            throw new InvalidArgumentException('Invalid path');
        }

        $query = parse_url($uri, PHP_URL_QUERY);

        return [$scheme, $host, $port, $path, $query];
    }
503734
protected function _loadFrom($uri) {
    if (empty($uri)) {
      return;
    }

    $response = $this->_client->request(Recurly_Client::GET, $uri);
    $response->assertValidResponse();

    $this->_objects = array();
    $this->__parseXmlToUpdateObject($response->body);
    $this->_afterParseResponse($response, $uri);
  }
910074
public static function getDomain($uri)
    {
        $returnValue = parse_url($uri, PHP_URL_HOST);
        if (empty($returnValue)) {
            return null;
        }

        return $returnValue;
    }
1115562
protected function performRequest(string $uri)
    {
        $httpResponse = $this->client->get($uri);
        Assert::eq($httpResponse->getStatusCode(), 200, 'Request failed.');

        $content = $httpResponse->getBody()->getContents();
        $xml = simplexml_load_string($content);

        $this->exceptionOnError($xml);

        return $this->responseFactory->getResponse($xml);
    }
1172895
public function match($uri)
    {
        // Normalization of the url of the nagivator.
        if (preg_match('~(.*)/$~', $uri, $match)) {
            $uri = end($match);
        }

        // Normalization of the path defined by the programmer.
        if (preg_match('~(.*)/$~', $this->path, $match)) {
            $this->path = end($match);
        }

        // We go straight back to gain performance.
        if ($this->path === $uri) {
            return true;
        }

        // We check the length of the path defined by the programmer
        // with that of the current url in the user's browser.
        $path = implode('', preg_split('/(\/:[a-z0-9-_]+\?)/', $this->path));

        if (count(explode('/', $path)) != count(explode('/', $uri))) {
            if (count(explode('/', $this->path)) != count(explode('/', $uri))) {
                return false;
            }
        }

        // Copie de l'url
        $path = $uri;

        // In case the developer did not add of constraint on captured variables
        if (empty($this->with)) {
            $path = preg_replace('~:\w+(\?)?~', '([^\s]+)$1', $this->path);

            preg_match_all('~:([a-z-0-9_-]+?)\?~', $this->path, $this->keys);

            $this->keys = end($this->keys);

            return $this->checkRequestUri($path, $uri);
        }

        // In case the developer has added constraints
        // on the captured variables
        if (!preg_match_all('~:([\w]+)?~', $this->path, $match)) {
            return $this->checkRequestUri($path, $uri);
        }

        $tmp_path = $this->path;

        $this->keys = end($match);

        // Association of criteria personalized.
        foreach ($this->keys as $key) {
            if (array_key_exists($key, $this->with)) {
                $tmp_path = preg_replace('~:' . $key . '~', '(' . $this->with[$key] . ')', $tmp_path);
            }
        }

        // Clear the custom criteria association table.
        $this->with = [];

        // In the case where the different path one recovers, one recovers the one in $tmp_path
        if ($tmp_path != $this->path) {
            $path = $tmp_path;
        }

        // Url check and path PARSER
        return $this->checkRequestUri($path, $uri);
    }
42194
public function load(string $url): bool
    {
        $this->parsedfile = (new Parser($url))->get();

        return $this->preValidate();
    }
300133
public function parseUri($uri)
    {
        $ret = [];
        foreach (explode($this->seperators['param'], $uri) as $params) {
            if ($params) {
                @list($key, $values) = explode($this->seperators['key_value'], $params, 2);
                $external = $key;
                if ($internal = $this->translateKeyInput($key)) {
                    $key = $internal;
                }
                $ret[$key] = [];
                foreach (explode($this->seperators['value'], $values) as $value) {
                    if (strlen($value) > 0) {
                        if ($internal = $this->translateValueInput($external, $value)) {
                            $value = $internal;
                        }
                        $ret[$key][] = urldecode($value);
                    }
                }
            }
        }

        return $ret;
    }
154740
public function parseUri()
    {
        $uri = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
        $uri = str_replace(['{', '}'], '', urldecode($uri));
        $extDir = dirname(dirname($_SERVER['SCRIPT_NAME']));
        $uri = str_replace($extDir, '', $uri);
        $uri = rtrim($uri, '/');
        $uri = empty($uri) ? '/' : $uri;
        $serverRequestMethod = $_SERVER['REQUEST_METHOD'];
        $params = $GLOBALS['_'.$serverRequestMethod];
        if(!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
            $https = true;
        }
        else {
            $https = false;
        }
        $host = $_SERVER['HTTP_HOST'].str_replace('\\', '/', $extDir);
        $ip = $_SERVER['REMOTE_ADDR'];
        
        if($serverRequestMethod === 'POST') {
            $params = ['GET' => $_GET, 'POST' => $params];
        }
        else {
            $params = ['GET' => $params, 'POST' => []];
        }

        return ['uri' => $uri, 'params' => $params, 'method' => $serverRequestMethod, 'https' => $https, 'host' => $host, 'ip' => $ip];
    }
920000
public static function parse(string $uri): URI
    {
        if ($uri == '') {
            return new static();
        }

        $parts = parse_url($uri);
        if ($parts === false) {
            throw new \InvalidArgumentException(sprintf('Cannot parse malformed uri "%s".', $uri));
        }

        if (!isset($parts['scheme'])) {
            throw new \InvalidArgumentException(sprintf('Missing scheme in uri "%s".', $uri));
        }

        if (count($parts) == 1 && isset($parts['scheme'])) {
            throw new \InvalidArgumentException(sprintf('Missing hierarchical segment in uri "%s".', $uri));
        }

        $defaults = [
            'scheme' => '',
            'host' => '',
            'user' => '',
            'pass' => '',
            'port' => null,
            'path' => '',
            'query' => '',
            'fragment' => '',
        ];

        $parts = array_merge($defaults, $parts);

        return new static(
            $parts['scheme'],
            $parts['host'],
            $parts['path'],
            $parts['query'],
            $parts['fragment'],
            $parts['user'],
            $parts['pass'],
            $parts['port']
        );
    }
482348
public function setUri($uri)
    {
        if (!is_array($uri)) {
            $uri = parse_url($uri);
        }

        $this->uri = $uri;
        return $this;
    }
72350
private function parseUri(string $uri): array
    {
        $defaults = [
            'scheme'   => '',
            'host'     => '',
            'port'     => '',
            'user'     => '',
            'pass'     => '',
            'path'     => '',
            'query'    => '',
            'fragment' => '',
        ];

        if (0 === strpos($uri, 'file://')) {
            // parse_url botches this up
            preg_match('@file://(?P<path>[^#]*)(?P<fragment>#.*)?@', $uri, $matches);

            return array_merge($defaults, array_intersect_key($matches, $defaults));
        }

        return array_merge($defaults, array_intersect_key(parse_url($uri), $defaults));
    }
141473
public function ping($uri) {
        $parsed_url = parse_url($uri);
        if (!$parsed_url || !is_array($parsed_url)) {
            return false;
        }
        
        $http = new \GuzzleHttp\Client(array('base_uri' => $parsed_url['host']));
        $res = $http->get($parsed_url['path'] . '?' . $parsed_url['query']);
        if ( 200 !== $res->getStatusCode()) {
            return false;
        }
        $content = $res->getBody();
        return true;
    }
204042
public static function check($uri)
    {
        try {
            $uri = self::factory($uri);
        } catch (Exception $e) {
            return false;
        }

        return $uri->valid();
    }
99436
protected static function splitUri($uri)
    {
        if (false === ($qm = strpos($uri, '?'))) {
            return array($uri, '');
        } else {
            return array(substr($uri, 0, $qm), substr($uri, $qm));
        }
    }