12 use \Psr\Http\Message\UriInterface;
142 if (!is_string($uri) && !method_exists($uri,
'__toString')) {
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) {
212 $basePath = $requestScriptName;
213 } elseif ($requestScriptDir !==
'/' && stripos($requestUri, $requestScriptDir) === 0) {
214 $basePath = $requestScriptDir;
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);
233 $uri = $uri->withBasePath($basePath);
280 $clone = clone $this;
303 if (!is_string(
$scheme) && !method_exists(
$scheme,
'__toString')) {
308 if (!isset(
$valid[$scheme])) {
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);
577 if (!is_string(
$path)) {
581 $clone = clone $this;
585 if (substr(
$path, 0, 1) ==
'/') {
586 $clone->basePath =
'';
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')) {
705 $clone = clone $this;
719 return preg_replace_callback(
720 '/(?:[^a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/',
722 return rawurlencode($match[0]);
773 $clone = clone $this;
filterPath($path)
Filter Uri path.
withQuery($query)
Return an instance with the specified query string.
filterQuery($query)
Filters the query string or fragment of a URI.
getFragment()
Retrieve the fragment component of the URI.
static createFromEnvironment(Environment $env)
Create new Uri from environment.
Value object representing a URI.
withScheme($scheme)
Return an instance with the specified scheme.
filterUserInfo($query)
Filters the user info string.
getBasePath()
Retrieve the base path segment of the URI.
getQuery()
Retrieve the query string of the URI.
filterPort($port)
Filter Uri port.
hasStandardPort()
Does this Uri use a standard port?
static createFromString($uri)
Create new Uri from string.
get($key, $default=null)
Get collection item for key.
getScheme()
Retrieve the scheme component of the URI.
getPort()
Retrieve the port component of the URI.
getAuthority()
Retrieve the authority component of the URI.
withPath($path)
Return an instance with the specified path.
withUserInfo($user, $password=null)
Return an instance with the specified user information.
has($key)
Does this collection have a given key?
Slim Framework (https://slimframework.com)
Value object representing a URI.
getBaseUrl()
Return the fully qualified base URL.
filterScheme($scheme)
Filter Uri scheme.
withFragment($fragment)
Return an instance with the specified URI fragment.
__construct( $scheme, $host, $port=null, $path='/', $query='', $fragment='', $user='', $password='')
Create new Uri.
withPort($port)
Return an instance with the specified port.
__toString()
Return the string representation as a URI reference.
getUserInfo()
Retrieve the user information component of the URI.
withBasePath($basePath)
Set base path.
withHost($host)
Return an instance with the specified host.
getPath()
Retrieve the path component of the URI.
getHost()
Retrieve the host component of the URI.