Rewrites a relative URI.

@param  string  $uri
@return string
187575
protected function rewriteAbsolute($uri)
    {
        $request = $this->getRequest();

        $path = strtr($this->assetDirectory, '/', DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.strtr($uri, '/', DIRECTORY_SEPARATOR);

        foreach ($this->symlinks as $link => $target) {
            if (strpos($path, $target) === 0) {
                $path = $link.substr($path, strlen($target));

                break;
            }
        }

        $base = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null;

        if ($request->getHost()) {
            $base = $request->getSchemeAndHttpHost().$request->getBaseUrl();
        }

        // Strip the document root from the path.
        if (strpos($path, app('path.public')) !== false) {
            $path = str_replace(app('path.public'), '', $path);
        } elseif (strpos($path, app('path.resources')) !== false) {
            $path = str_replace(app('path.resources'), '', $path);
        }

        $uri = strtr($path, '/\\', '//');
        $uri = $this->removeDots($uri);

        return $uri;
    }
1106816
public static function base($uri = '', $relativeTo = '')
    {
        $app = App::getInstance();

        $scheme = parse_url($uri, PHP_URL_SCHEME);
        if (isset($scheme)) {
            return $uri;
        }

        // We use server script name instead from slim env script name
        // because slim env script name truncate the index.php file from the
        // result
        $dir = $_SERVER['SCRIPT_NAME'];
        if (substr($dir, -4) === '.php') {
            $dir = dirname($dir);
        }

        if ($dir === '/') {
            $dir = '';
        }

        if ($relativeTo === false) {
            $relativeTo = $dir;
        } elseif (!$relativeTo) {
            $relativeTo = $app->environment['slim.url_scheme'].'://'.$app->environment['HTTP_HOST'].$dir;
        }

        return $relativeTo.'/'.trim($uri, '/');
    }
1156404
private function prepareUriForLocalhostAccess($uri)
    {
        $public = 'public';
        $index = 'index.php';

        if (strpos($uri, $index)) {
            return substr($uri, strpos($uri, $index) + strlen($index));
        } elseif (strpos($uri, $public)) {
            return substr($uri, strpos($uri, $public) + strlen($public));
        }

        return false;
    }
131530
public function findURI(string $uri)
    {
        foreach ($this->members as $offset => $member) {
            if ($member->uri == $uri) {
                return $offset;
            }
        }
        return -1;
    }
682560
public function createRelative($uri = null)
    {
        if (empty($uri)) {
            // Empty uri means baseurl
            return $this->baseUrl;
        } elseif (substr($uri, 0, 7) == "http://"
            || substr($uri, 0, 8) == "https://"
            || substr($uri, 0, 2) == "//"
        ) {
            // Fully qualified, just leave as is.
            return rtrim($uri, '/');
        } elseif ($uri[0] == '/') {
            // Absolute url, prepend with siteUrl
            return rtrim($this->siteUrl . rtrim($uri, '/'), '/');
        }

        $uri = rtrim($uri, '/');
        return $this->baseUrl . '/' . $uri;
    }
486768
public function toRequestString(string $uri = ''): string
    {
        return !empty($this->raw) ? self::kvToRequestString($this->toRequestArray($uri)) : '';
    }
1311594
private function getPathFromUri($uri)
    {
        $uriParser = new UriParser($uri);
        // Prepare uri
        $uriParser->encode();
        $uri = $uriParser->stripFragment();
        if (strpos($uri, '/') === 0) {
            // URI is already an path
            return $uri;
        }
        if (!$uriParser->validate()) {
            throw new \InvalidArgumentException('Invalid URI');
        }
        $path = (($path = parse_url($uri, PHP_URL_PATH)) === null) ? '/' : $path;
        $query = (($query = parse_url($uri, PHP_URL_QUERY)) === null) ? '' : '?' . $query;
        return $path . $query;
    }
18639
public static function uriToPath(string $uri)
    {
        $fragments = parse_url($uri);
        if ($fragments === false || !isset($fragments['scheme']) || $fragments['scheme'] !== 'file') {
            throw new \InvalidArgumentException("Not a valid file URI: $uri");
        }
        $filepath = urldecode((string) $fragments['path']);
        if (strpos($filepath, ':') !== false) {
            if ($filepath[0] === '/') {
                $filepath = substr($filepath, 1);
            }
            $filepath = str_replace('/', '\\', $filepath);
        }
        return $filepath;
    }
1124028
protected function parseUri($uri)
    {
        if ($uri && stripos($uri, 'unix://') === 0) {
            // parse_url() doesn't like "unix:///foo", but parses "unix:/foo" fine.
            $uri = str_ireplace('unix://', 'unix:', $uri);
        } elseif ($uri && $uri[0] !== '/' && !preg_match('#^\w+://?.+#', $uri)) {
            // If no scheme given and path exists and isn't absolute, assume tcp scheme is wanted.
            // This allows both "127.0.0.1" and "/foo.sock" to work without specifying scheme.
            // If non absolute path is wanted, specify the scheme: "unix://foo.sock"
            $uri = 'tcp://' . $uri;
        }

        $parsed = new Uri($uri);

        return $parsed;
    }
1085749
public static function parse(string $uri): Uri
    {
        preg_match(static::URI_PATTERN, $uri, $matches);

        $components = static::componentsFromMatches($matches);
        $scheme = $components['scheme'];
        $authority = $components['authority'];
        $path = $components['path'];
        $query = $components['query'];
        $fragment = $components['fragment'];

        return new static($path, $scheme, $authority, $query, $fragment);
    }
1219674
public function getUriLocale($uri)
    {
        $parts = explode('/', $uri);
        $locale = $parts[1];

        if (count($parts) < 2 || ! in_array($locale, $this->getLocales())) {
            return;
        }

        return $locale;
    }
376770
public function withBaseUri(string $uri): self
    {
        return tap($this, function ($request) use ($uri) {
            return $this->options = array_merge_recursive($this->options, [
                'base_uri' => $uri,
            ]);
        });
    }
354463
public function setUri($uri)
    {
        if (in_array($uri, $this->uris, TRUE)) {
            throw new \Exception('Redirecting loop detected');
        }
        $this->uris[] = $uri;
        return $this;
    }
466565
protected function makeUriRelativeTo($uri, $root)
    {
        if (!$root) {
            return $uri;
        }

        if (is_array($uri)) {
            $uris = [];
            foreach ($uri as $u) {
                $uris[] = $this->makeUriRelativeTo($u, $root);
            }
            return $uris;
        }

        if (substr($uri, 0, 1) === '/' || preg_match('/^([a-zA-Z]+:\/\/|[a-zA-Z]:\/|[a-zA-Z]:\\\)/', $uri)) {
            return $uri;
        }
        return rtrim($root, '/') . "/$uri";
    }
1003181
public function internalRedirect($uri)
    {
        if (is_string($uri)) {

            // make a new URI instance, then make a new request
            $uri = $this->request->getUri()->withPath($uri);
            return $this->request->withUri($uri);

        } elseif ($uri instanceof UriInterface) {

            // get a new request with the specified URI instance
            return $this->request->withUri($uri);

        } else {

            // bad $uri value
            throw new InvalidArgumentException(
                'URI should be a string or instance of Psr\Http\Message\UriInterface'
            );

        }
    }
749570
protected function chopIndex($uri)
    {
        $subStr = strtolower(substr($uri,0, 10));
        if ("/index.php" == $subStr) {
            return (strlen($uri) > 10 ? substr($uri, 10) : '');
        }

        return $uri;
    }
1297940
public function &findPageByUri($uri)
    {
        foreach ($this->getRootSection()->getSections() as $section) {
            if ($page = $section->findPageByUri($uri)) {
                return $page;
            }
        }

        return;
    }