11use InvalidArgumentException;
 
   12use \Psr\Http\Message\UriInterface;
 
  142        if (!is_string($uri) && !method_exists($uri, 
'__toString')) {
 
  143            throw new InvalidArgumentException(
'Uri must be a string');
 
  146        $parts = parse_url($uri);
 
  147        $scheme = isset($parts[
'scheme']) ? $parts[
'scheme'] : 
'';
 
  148        $user = isset($parts[
'user']) ? $parts[
'user'] : 
'';
 
  149        $pass = isset($parts[
'pass']) ? $parts[
'pass'] : 
'';
 
  150        $host = isset($parts[
'host']) ? $parts[
'host'] : 
'';
 
  151        $port = isset($parts[
'port']) ? $parts[
'port'] : 
null;
 
  152        $path = isset($parts[
'path']) ? $parts[
'path'] : 
'';
 
  153        $query = isset($parts[
'query']) ? $parts[
'query'] : 
'';
 
  154        $fragment = isset($parts[
'fragment']) ? $parts[
'fragment'] : 
'';
 
  169        $isSecure = 
$env->get(
'HTTPS');
 
  170        $scheme = (empty($isSecure) || $isSecure === 
'off') ? 
'http' : 
'https';
 
  173        $username = 
$env->get(
'PHP_AUTH_USER', 
'');
 
  177        if (
$env->has(
'HTTP_HOST')) {
 
  184            $port = (int)
$env->get(
'SERVER_PORT', 80);
 
  187        if (preg_match(
'/^(\[[a-fA-F0-9:.]+\])(:\d+)?\z/', 
$host, $matches)) {
 
  190            if (isset($matches[2])) {
 
  191                $port = (int) substr($matches[2], 1);
 
  194            $pos = strpos(
$host, 
':');
 
  195            if ($pos !== 
false) {
 
  202        $requestScriptName = parse_url(
$env->get(
'SCRIPT_NAME'), PHP_URL_PATH);
 
  203        $requestScriptDir = dirname($requestScriptName);
 
  207        $requestUri = parse_url(
'http://example.com' . 
$env->get(
'REQUEST_URI'), PHP_URL_PATH);
 
  210        $virtualPath = $requestUri;
 
  211        if (stripos($requestUri, $requestScriptName) === 0) {
 
  213        } elseif ($requestScriptDir !== 
'/' && stripos($requestUri, $requestScriptDir) === 0) {
 
  218            $virtualPath = ltrim(substr($requestUri, strlen(
$basePath)), 
'/');
 
  222        $queryString = 
$env->get(
'QUERY_STRING', 
'');
 
  223        if ($queryString === 
'') {
 
  224            $queryString = parse_url(
'http://example.com' . 
$env->get(
'REQUEST_URI'), PHP_URL_QUERY);
 
  280        $clone = clone $this;
 
  303        if (!is_string(
$scheme) && !method_exists(
$scheme, 
'__toString')) {
 
  304            throw new InvalidArgumentException(
'Uri scheme must be a string');
 
  309            throw new InvalidArgumentException(
'Uri scheme must be one of: "", "https", "http"');
 
  343        return ($userInfo !== 
'' ? $userInfo . 
'@' : 
'') . 
$host . (
$port !== 
null ? 
':' . 
$port : 
'');
 
  363        return $this->
user . ($this->password !== 
'' ? 
':' . $this->password : 
'');
 
  382        $clone = clone $this;
 
  384        if (
'' !== $clone->user) {
 
  387            $clone->password = 
'';
 
  401        return preg_replace_callback(
 
  402            '/(?:[^a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=]+|%(?![A-Fa-f0-9]{2}))/u',
 
  404                return rawurlencode($match[0]);
 
  440        $clone = clone $this;
 
  441        $clone->host = 
$host;
 
  486        $clone = clone $this;
 
  487        $clone->port = 
$port;
 
  499        return ($this->scheme === 
'http' && $this->port === 80) || ($this->scheme === 
'https' && $this->port === 443);
 
  516        throw new InvalidArgumentException(
'Uri port must be null or an integer between 1 and 65535 (inclusive)');
 
  577        if (!is_string(
$path)) {
 
  578            throw new InvalidArgumentException(
'Uri path must be a string');
 
  581        $clone = clone $this;
 
  585        if (substr(
$path, 0, 1) == 
'/') {
 
  586            $clone->basePath = 
'';
 
  618            throw new InvalidArgumentException(
'Uri path must be a string');
 
  623        $clone = clone $this;
 
  646        return preg_replace_callback(
 
  647            '/(?:[^a-zA-Z0-9_\-\.~:@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/',
 
  649                return rawurlencode($match[0]);
 
  701        if (!is_string(
$query) && !method_exists(
$query, 
'__toString')) {
 
  702            throw new InvalidArgumentException(
'Uri query must be a string');
 
  705        $clone = clone $this;
 
  719        return preg_replace_callback(
 
  720            '/(?:[^a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/',
 
  722                return rawurlencode($match[0]);
 
  770            throw new InvalidArgumentException(
'Uri fragment must be a string');
 
  773        $clone = clone $this;
 
An exception for terminatinating execution or to throw for unit testing.
Value object representing a URI.
static createFromString($uri)
Create new Uri from string.
getAuthority()
Retrieve the authority component of the URI.
withPath($path)
Return an instance with the specified path.
withFragment($fragment)
Return an instance with the specified URI fragment.
getPath()
Retrieve the path component of the URI.
__construct( $scheme, $host, $port=null, $path='/', $query='', $fragment='', $user='', $password='')
Create new Uri.
filterPort($port)
Filter Uri port.
withBasePath($basePath)
Set base path.
getScheme()
Retrieve the scheme component of the URI.
getFragment()
Retrieve the fragment component of the URI.
hasStandardPort()
Does this Uri use a standard port?
filterScheme($scheme)
Filter Uri scheme.
withHost($host)
Return an instance with the specified host.
getPort()
Retrieve the port component of the URI.
withUserInfo($user, $password=null)
Return an instance with the specified user information.
getHost()
Retrieve the host component of the URI.
__toString()
Return the string representation as a URI reference.
withQuery($query)
Return an instance with the specified query string.
filterPath($path)
Filter Uri path.
withScheme($scheme)
Return an instance with the specified scheme.
static createFromEnvironment(Environment $env)
Create new Uri from environment.
withPort($port)
Return an instance with the specified port.
getQuery()
Retrieve the query string of the URI.
getUserInfo()
Retrieve the user information component of the URI.
filterQuery($query)
Filters the query string or fragment of a URI.
getBasePath()
Retrieve the base path segment of the URI.
filterUserInfo($query)
Filters the user info string.
getBaseUrl()
Return the fully qualified base URL.
Value object representing a URI.
Slim Framework (https://slimframework.com)