ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Slim\Http\Uri Class Reference

Value object representing a URI. More...

+ Inheritance diagram for Slim\Http\Uri:
+ Collaboration diagram for Slim\Http\Uri:

Public Member Functions

 __construct ( $scheme, $host, $port=null, $path='/', $query='', $fragment='', $user='', $password='')
 Create new Uri. More...
 
 getScheme ()
 Retrieve the scheme component of the URI. More...
 
 withScheme ($scheme)
 Return an instance with the specified scheme. More...
 
 getAuthority ()
 Retrieve the authority component of the URI. More...
 
 getUserInfo ()
 Retrieve the user information component of the URI. More...
 
 withUserInfo ($user, $password=null)
 Return an instance with the specified user information. More...
 
 getHost ()
 Retrieve the host component of the URI. More...
 
 withHost ($host)
 Return an instance with the specified host. More...
 
 getPort ()
 Retrieve the port component of the URI. More...
 
 withPort ($port)
 Return an instance with the specified port. More...
 
 getPath ()
 Retrieve the path component of the URI. More...
 
 withPath ($path)
 Return an instance with the specified path. More...
 
 getBasePath ()
 Retrieve the base path segment of the URI. More...
 
 withBasePath ($basePath)
 Set base path. More...
 
 getQuery ()
 Retrieve the query string of the URI. More...
 
 withQuery ($query)
 Return an instance with the specified query string. More...
 
 getFragment ()
 Retrieve the fragment component of the URI. More...
 
 withFragment ($fragment)
 Return an instance with the specified URI fragment. More...
 
 __toString ()
 Return the string representation as a URI reference. More...
 
 getBaseUrl ()
 Return the fully qualified base URL. More...
 

Static Public Member Functions

static createFromString ($uri)
 Create new Uri from string. More...
 
static createFromEnvironment (Environment $env)
 Create new Uri from environment. More...
 

Protected Member Functions

 filterScheme ($scheme)
 Filter Uri scheme. More...
 
 filterUserInfo ($query)
 Filters the user info string. More...
 
 hasStandardPort ()
 Does this Uri use a standard port? More...
 
 filterPort ($port)
 Filter Uri port. More...
 
 filterPath ($path)
 Filter Uri path. More...
 
 filterQuery ($query)
 Filters the query string or fragment of a URI. More...
 

Protected Attributes

 $scheme = ''
 
 $user = ''
 
 $password = ''
 
 $host = ''
 
 $port
 
 $basePath = ''
 
 $path = ''
 
 $query = ''
 
 $fragment = ''
 

Detailed Description

Value object representing a URI.

This interface is meant to represent URIs according to RFC 3986 and to provide methods for most common operations. Additional functionality for working with URIs can be provided on top of the interface or externally. Its primary use is for HTTP requests, but may also be used in other contexts.

Instances of this interface are considered immutable; all methods that might change state MUST be implemented such that they retain the internal state of the current instance and return an instance that contains the changed state.

Typically the Host header will be also be present in the request message. For server-side requests, the scheme will typically be discoverable in the server parameters.

(the URI specification)

Definition at line 35 of file Uri.php.

Constructor & Destructor Documentation

◆ __construct()

Slim\Http\Uri::__construct (   $scheme,
  $host,
  $port = null,
  $path = '/',
  $query = '',
  $fragment = '',
  $user = '',
  $password = '' 
)

Create new Uri.

Parameters
string$schemeUri scheme.
string$hostUri host.
int$portUri port number.
string$pathUri path.
string$queryUri query string.
string$fragmentUri fragment.
string$userUri user.
string$passwordUri password.

Definition at line 112 of file Uri.php.

References Slim\Http\Uri\$fragment, Slim\Http\Uri\$host, Slim\Http\Uri\$password, Slim\Http\Uri\$path, Slim\Http\Uri\$port, Slim\Http\Uri\$query, Slim\Http\Uri\$scheme, Slim\Http\Uri\$user, Slim\Http\Uri\filterPath(), Slim\Http\Uri\filterPort(), Slim\Http\Uri\filterQuery(), Slim\Http\Uri\filterScheme(), and user().

121  {
122  $this->scheme = $this->filterScheme($scheme);
123  $this->host = $host;
124  $this->port = $this->filterPort($port);
125  $this->path = empty($path) ? '/' : $this->filterPath($path);
126  $this->query = $this->filterQuery($query);
127  $this->fragment = $this->filterQuery($fragment);
128  $this->user = $user;
129  $this->password = $password;
130  }
filterPath($path)
Filter Uri path.
Definition: Uri.php:644
filterQuery($query)
Filters the query string or fragment of a URI.
Definition: Uri.php:717
filterPort($port)
Filter Uri port.
Definition: Uri.php:510
user()
Definition: user.php:4
filterScheme($scheme)
Filter Uri scheme.
Definition: Uri.php:295
+ Here is the call graph for this function:

Member Function Documentation

◆ __toString()

Slim\Http\Uri::__toString ( )

Return the string representation as a URI reference.

Depending on which components of the URI are present, the resulting string is either a full URI or relative reference according to RFC 3986, Section 4.1. The method concatenates the various components of the URI, using the appropriate delimiters:

  • If a scheme is present, it MUST be suffixed by ":".
  • If an authority is present, it MUST be prefixed by "//".
  • The path can be concatenated without delimiters. But there are two cases where the path has to be adjusted to make the URI reference valid as PHP does not allow to throw an exception in __toString():
    • If the path is rootless and an authority is present, the path MUST be prefixed by "/".
    • If the path is starting with more than one "/" and no authority is present, the starting slashes MUST be reduced to one.
  • If a query is present, it MUST be prefixed by "?".
  • If a fragment is present, it MUST be prefixed by "#".
See also
http://tools.ietf.org/html/rfc3986#section-4.1
Returns
string

Implements Psr\Http\Message\UriInterface.

Definition at line 806 of file Uri.php.

References $authority, Slim\Http\Uri\$basePath, Slim\Http\Uri\$fragment, Slim\Http\Uri\$path, Slim\Http\Uri\$query, Slim\Http\Uri\$scheme, Slim\Http\Uri\getAuthority(), Slim\Http\Uri\getBasePath(), Slim\Http\Uri\getFragment(), Slim\Http\Uri\getPath(), Slim\Http\Uri\getQuery(), and Slim\Http\Uri\getScheme().

807  {
808  $scheme = $this->getScheme();
809  $authority = $this->getAuthority();
810  $basePath = $this->getBasePath();
811  $path = $this->getPath();
812  $query = $this->getQuery();
813  $fragment = $this->getFragment();
814 
815  $path = $basePath . '/' . ltrim($path, '/');
816 
817  return ($scheme !== '' ? $scheme . ':' : '')
818  . ($authority !== '' ? '//' . $authority : '')
819  . $path
820  . ($query !== '' ? '?' . $query : '')
821  . ($fragment !== '' ? '#' . $fragment : '');
822  }
getFragment()
Retrieve the fragment component of the URI.
Definition: Uri.php:748
getBasePath()
Retrieve the base path segment of the URI.
Definition: Uri.php:602
getQuery()
Retrieve the query string of the URI.
Definition: Uri.php:679
getScheme()
Retrieve the scheme component of the URI.
Definition: Uri.php:257
getAuthority()
Retrieve the authority component of the URI.
Definition: Uri.php:337
getPath()
Retrieve the path component of the URI.
Definition: Uri.php:548
$authority
+ Here is the call graph for this function:

◆ createFromEnvironment()

static Slim\Http\Uri::createFromEnvironment ( Environment  $env)
static

Create new Uri from environment.

Parameters
Environment$env
Returns
self

Definition at line 166 of file Uri.php.

References Slim\Http\Uri\$basePath, Slim\Http\Uri\$fragment, Slim\Http\Uri\$host, Slim\Http\Uri\$password, Slim\Http\Uri\$port, Slim\Http\Uri\$scheme, Slim\Collection\get(), and Slim\Collection\has().

Referenced by Slim\Http\Request\createFromEnvironment().

167  {
168  // Scheme
169  $isSecure = $env->get('HTTPS');
170  $scheme = (empty($isSecure) || $isSecure === 'off') ? 'http' : 'https';
171 
172  // Authority: Username and password
173  $username = $env->get('PHP_AUTH_USER', '');
174  $password = $env->get('PHP_AUTH_PW', '');
175 
176  // Authority: Host and Port
177  if ($env->has('HTTP_HOST')) {
178  $host = $env->get('HTTP_HOST');
179  // set a port default
180  $port = null;
181  } else {
182  $host = $env->get('SERVER_NAME');
183  // set a port default
184  $port = (int)$env->get('SERVER_PORT', 80);
185  }
186 
187  if (preg_match('/^(\[[a-fA-F0-9:.]+\])(:\d+)?\z/', $host, $matches)) {
188  $host = $matches[1];
189 
190  if (isset($matches[2])) {
191  $port = (int) substr($matches[2], 1);
192  }
193  } else {
194  $pos = strpos($host, ':');
195  if ($pos !== false) {
196  $port = (int) substr($host, $pos + 1);
197  $host = strstr($host, ':', true);
198  }
199  }
200 
201  // Path
202  $requestScriptName = parse_url($env->get('SCRIPT_NAME'), PHP_URL_PATH);
203  $requestScriptDir = dirname($requestScriptName);
204 
205  // parse_url() requires a full URL. As we don't extract the domain name or scheme,
206  // we use a stand-in.
207  $requestUri = parse_url('http://example.com' . $env->get('REQUEST_URI'), PHP_URL_PATH);
208 
209  $basePath = '';
210  $virtualPath = $requestUri;
211  if (stripos($requestUri, $requestScriptName) === 0) {
212  $basePath = $requestScriptName;
213  } elseif ($requestScriptDir !== '/' && stripos($requestUri, $requestScriptDir) === 0) {
214  $basePath = $requestScriptDir;
215  }
216 
217  if ($basePath) {
218  $virtualPath = ltrim(substr($requestUri, strlen($basePath)), '/');
219  }
220 
221  // Query string
222  $queryString = $env->get('QUERY_STRING', '');
223  if ($queryString === '') {
224  $queryString = parse_url('http://example.com' . $env->get('REQUEST_URI'), PHP_URL_QUERY);
225  }
226 
227  // Fragment
228  $fragment = '';
229 
230  // Build Uri
231  $uri = new static($scheme, $host, $port, $virtualPath, $queryString, $fragment, $username, $password);
232  if ($basePath) {
233  $uri = $uri->withBasePath($basePath);
234  }
235 
236  return $uri;
237  }
$env
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createFromString()

static Slim\Http\Uri::createFromString (   $uri)
static

Create new Uri from string.

Parameters
string$uriComplete Uri string (i.e., https://user:pass@host:443/path?query).
Returns
self

Definition at line 140 of file Uri.php.

References Slim\Http\Uri\$fragment, Slim\Http\Uri\$host, $pass, Slim\Http\Uri\$path, Slim\Http\Uri\$port, Slim\Http\Uri\$query, Slim\Http\Uri\$scheme, and Slim\Http\Uri\$user.

141  {
142  if (!is_string($uri) && !method_exists($uri, '__toString')) {
143  throw new InvalidArgumentException('Uri must be a string');
144  }
145 
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'] : '';
155 
156  return new static($scheme, $host, $port, $path, $query, $fragment, $user, $pass);
157  }

◆ filterPath()

Slim\Http\Uri::filterPath (   $path)
protected

Filter Uri path.

This method percent-encodes all reserved characters in the provided path string. This method will NOT double-encode characters that are already percent-encoded.

Parameters
string$pathThe raw uri path.
Returns
string The RFC 3986 percent-encoded uri path. http://www.faqs.org/rfcs/rfc3986.html

Definition at line 644 of file Uri.php.

References Slim\Http\Uri\$path.

Referenced by Slim\Http\Uri\__construct(), Slim\Http\Uri\withBasePath(), and Slim\Http\Uri\withPath().

645  {
646  return preg_replace_callback(
647  '/(?:[^a-zA-Z0-9_\-\.~:@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/',
648  function ($match) {
649  return rawurlencode($match[0]);
650  },
651  $path
652  );
653  }
+ Here is the caller graph for this function:

◆ filterPort()

Slim\Http\Uri::filterPort (   $port)
protected

Filter Uri port.

Parameters
null | int$portThe Uri port number.
Returns
null|int
Exceptions
InvalidArgumentExceptionIf the port is invalid.

Definition at line 510 of file Uri.php.

References Slim\Http\Uri\$port.

Referenced by Slim\Http\Uri\__construct(), and Slim\Http\Uri\withPort().

511  {
512  if (is_null($port) || (is_integer($port) && ($port >= 1 && $port <= 65535))) {
513  return $port;
514  }
515 
516  throw new InvalidArgumentException('Uri port must be null or an integer between 1 and 65535 (inclusive)');
517  }
+ Here is the caller graph for this function:

◆ filterQuery()

Slim\Http\Uri::filterQuery (   $query)
protected

Filters the query string or fragment of a URI.

Parameters
string$queryThe raw uri query string.
Returns
string The percent-encoded query string.

Definition at line 717 of file Uri.php.

References Slim\Http\Uri\$query.

Referenced by Slim\Http\Uri\__construct(), Slim\Http\Uri\withFragment(), and Slim\Http\Uri\withQuery().

718  {
719  return preg_replace_callback(
720  '/(?:[^a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/',
721  function ($match) {
722  return rawurlencode($match[0]);
723  },
724  $query
725  );
726  }
+ Here is the caller graph for this function:

◆ filterScheme()

Slim\Http\Uri::filterScheme (   $scheme)
protected

Filter Uri scheme.

Parameters
string$schemeRaw Uri scheme.
Returns
string
Exceptions
InvalidArgumentExceptionIf the Uri scheme is not a string.
InvalidArgumentExceptionIf Uri scheme is not "", "https", or "http".

Definition at line 295 of file Uri.php.

References Slim\Http\Uri\$scheme, and $valid.

Referenced by Slim\Http\Uri\__construct(), and Slim\Http\Uri\withScheme().

296  {
297  static $valid = [
298  '' => true,
299  'https' => true,
300  'http' => true,
301  ];
302 
303  if (!is_string($scheme) && !method_exists($scheme, '__toString')) {
304  throw new InvalidArgumentException('Uri scheme must be a string');
305  }
306 
307  $scheme = str_replace('://', '', strtolower((string)$scheme));
308  if (!isset($valid[$scheme])) {
309  throw new InvalidArgumentException('Uri scheme must be one of: "", "https", "http"');
310  }
311 
312  return $scheme;
313  }
$valid
+ Here is the caller graph for this function:

◆ filterUserInfo()

Slim\Http\Uri::filterUserInfo (   $query)
protected

Filters the user info string.

Parameters
string$queryThe raw uri query string.
Returns
string The percent-encoded query string.

Definition at line 399 of file Uri.php.

References Slim\Http\Uri\$query.

Referenced by Slim\Http\Uri\withUserInfo().

400  {
401  return preg_replace_callback(
402  '/(?:[^a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=]+|%(?![A-Fa-f0-9]{2}))/u',
403  function ($match) {
404  return rawurlencode($match[0]);
405  },
406  $query
407  );
408  }
+ Here is the caller graph for this function:

◆ getAuthority()

Slim\Http\Uri::getAuthority ( )

Retrieve the authority component of the URI.

If no authority information is present, this method MUST return an empty string.

The authority syntax of the URI is:

[user-info@]host[:port]

If the port component is not set or is the standard port for the current scheme, it SHOULD NOT be included.

See also
https://tools.ietf.org/html/rfc3986#section-3.2
Returns
string The URI authority, in "[user-info@]host[:port]" format.

Implements Psr\Http\Message\UriInterface.

Definition at line 337 of file Uri.php.

References Slim\Http\Uri\$host, Slim\Http\Uri\$port, Slim\Http\Uri\getHost(), Slim\Http\Uri\getPort(), and Slim\Http\Uri\getUserInfo().

Referenced by Slim\Http\Uri\__toString(), and Slim\Http\Uri\getBaseUrl().

338  {
339  $userInfo = $this->getUserInfo();
340  $host = $this->getHost();
341  $port = $this->getPort();
342 
343  return ($userInfo !== '' ? $userInfo . '@' : '') . $host . ($port !== null ? ':' . $port : '');
344  }
getPort()
Retrieve the port component of the URI.
Definition: Uri.php:461
getUserInfo()
Retrieve the user information component of the URI.
Definition: Uri.php:361
getHost()
Retrieve the host component of the URI.
Definition: Uri.php:421
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBasePath()

Slim\Http\Uri::getBasePath ( )

Retrieve the base path segment of the URI.

Note: This method is not part of the PSR-7 standard.

This method MUST return a string; if no path is present it MUST return an empty string.

Returns
string The base path segment of the URI.

Definition at line 602 of file Uri.php.

References Slim\Http\Uri\$basePath.

Referenced by Slim\Http\Uri\__toString(), and Slim\Http\Uri\getBaseUrl().

603  {
604  return $this->basePath;
605  }
+ Here is the caller graph for this function:

◆ getBaseUrl()

Slim\Http\Uri::getBaseUrl ( )

Return the fully qualified base URL.

Note that this method never includes a trailing /

This method is not part of PSR-7.

Returns
string

Definition at line 833 of file Uri.php.

References $authority, Slim\Http\Uri\$basePath, Slim\Http\Uri\$scheme, Slim\Http\Uri\getAuthority(), Slim\Http\Uri\getBasePath(), and Slim\Http\Uri\getScheme().

834  {
835  $scheme = $this->getScheme();
836  $authority = $this->getAuthority();
837  $basePath = $this->getBasePath();
838 
839  if ($authority !== '' && substr($basePath, 0, 1) !== '/') {
840  $basePath = $basePath . '/' . $basePath;
841  }
842 
843  return ($scheme !== '' ? $scheme . ':' : '')
844  . ($authority ? '//' . $authority : '')
845  . rtrim($basePath, '/');
846  }
getBasePath()
Retrieve the base path segment of the URI.
Definition: Uri.php:602
getScheme()
Retrieve the scheme component of the URI.
Definition: Uri.php:257
getAuthority()
Retrieve the authority component of the URI.
Definition: Uri.php:337
$authority
+ Here is the call graph for this function:

◆ getFragment()

Slim\Http\Uri::getFragment ( )

Retrieve the fragment component of the URI.

If no fragment is present, this method MUST return an empty string.

The leading "#" character is not part of the fragment and MUST NOT be added.

The value returned MUST be percent-encoded, but MUST NOT double-encode any characters. To determine what characters to encode, please refer to RFC 3986, Sections 2 and 3.5.

See also
https://tools.ietf.org/html/rfc3986#section-2
https://tools.ietf.org/html/rfc3986#section-3.5
Returns
string The URI fragment.

Implements Psr\Http\Message\UriInterface.

Definition at line 748 of file Uri.php.

References Slim\Http\Uri\$fragment.

Referenced by Slim\Http\Uri\__toString().

749  {
750  return $this->fragment;
751  }
+ Here is the caller graph for this function:

◆ getHost()

Slim\Http\Uri::getHost ( )

Retrieve the host component of the URI.

If no host is present, this method MUST return an empty string.

The value returned MUST be normalized to lowercase, per RFC 3986 Section 3.2.2.

See also
http://tools.ietf.org/html/rfc3986#section-3.2.2
Returns
string The URI host.

Implements Psr\Http\Message\UriInterface.

Definition at line 421 of file Uri.php.

References Slim\Http\Uri\$host.

Referenced by Slim\Http\Uri\getAuthority().

422  {
423  return $this->host;
424  }
+ Here is the caller graph for this function:

◆ getPath()

Slim\Http\Uri::getPath ( )

Retrieve the path component of the URI.

The path can either be empty or absolute (starting with a slash) or rootless (not starting with a slash). Implementations MUST support all three syntaxes.

Normally, the empty path "" and absolute path "/" are considered equal as defined in RFC 7230 Section 2.7.3. But this method MUST NOT automatically do this normalization because in contexts with a trimmed base path, e.g. the front controller, this difference becomes significant. It's the task of the user to handle both "" and "/".

The value returned MUST be percent-encoded, but MUST NOT double-encode any characters. To determine what characters to encode, please refer to RFC 3986, Sections 2 and 3.3.

As an example, if the value should include a slash ("/") not intended as delimiter between path segments, that value MUST be passed in encoded form (e.g., "%2F") to the instance.

See also
https://tools.ietf.org/html/rfc3986#section-2
https://tools.ietf.org/html/rfc3986#section-3.3
Returns
string The URI path.

Implements Psr\Http\Message\UriInterface.

Definition at line 548 of file Uri.php.

References Slim\Http\Uri\$path.

Referenced by Slim\Http\Uri\__toString().

549  {
550  return $this->path;
551  }
+ Here is the caller graph for this function:

◆ getPort()

Slim\Http\Uri::getPort ( )

Retrieve the port component of the URI.

If a port is present, and it is non-standard for the current scheme, this method MUST return it as an integer. If the port is the standard port used with the current scheme, this method SHOULD return null.

If no port is present, and no scheme is present, this method MUST return a null value.

If no port is present, but a scheme is present, this method MAY return the standard port for that scheme, but SHOULD return null.

Returns
null|int The URI port.

Implements Psr\Http\Message\UriInterface.

Definition at line 461 of file Uri.php.

References Slim\Http\Uri\hasStandardPort().

Referenced by Slim\Http\Uri\getAuthority().

462  {
463  return $this->port && !$this->hasStandardPort() ? $this->port : null;
464  }
hasStandardPort()
Does this Uri use a standard port?
Definition: Uri.php:497
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getQuery()

Slim\Http\Uri::getQuery ( )

Retrieve the query string of the URI.

If no query string is present, this method MUST return an empty string.

The leading "?" character is not part of the query and MUST NOT be added.

The value returned MUST be percent-encoded, but MUST NOT double-encode any characters. To determine what characters to encode, please refer to RFC 3986, Sections 2 and 3.4.

As an example, if a value in a key/value pair of the query string should include an ampersand ("&") not intended as a delimiter between values, that value MUST be passed in encoded form (e.g., "%26") to the instance.

See also
https://tools.ietf.org/html/rfc3986#section-2
https://tools.ietf.org/html/rfc3986#section-3.4
Returns
string The URI query string.

Implements Psr\Http\Message\UriInterface.

Definition at line 679 of file Uri.php.

References Slim\Http\Uri\$query.

Referenced by Slim\Http\Uri\__toString().

680  {
681  return $this->query;
682  }
+ Here is the caller graph for this function:

◆ getScheme()

Slim\Http\Uri::getScheme ( )

Retrieve the scheme component of the URI.

If no scheme is present, this method MUST return an empty string.

The value returned MUST be normalized to lowercase, per RFC 3986 Section 3.1.

The trailing ":" character is not part of the scheme and MUST NOT be added.

See also
https://tools.ietf.org/html/rfc3986#section-3.1
Returns
string The URI scheme.

Implements Psr\Http\Message\UriInterface.

Definition at line 257 of file Uri.php.

References Slim\Http\Uri\$scheme.

Referenced by Slim\Http\Uri\__toString(), and Slim\Http\Uri\getBaseUrl().

258  {
259  return $this->scheme;
260  }
+ Here is the caller graph for this function:

◆ getUserInfo()

Slim\Http\Uri::getUserInfo ( )

Retrieve the user information component of the URI.

If no user information is present, this method MUST return an empty string.

If a user is present in the URI, this will return that value; additionally, if the password is also present, it will be appended to the user value, with a colon (":") separating the values.

The trailing "@" character is not part of the user information and MUST NOT be added.

Returns
string The URI user information, in "username[:password]" format.

Implements Psr\Http\Message\UriInterface.

Definition at line 361 of file Uri.php.

References user().

Referenced by Slim\Http\Uri\getAuthority().

362  {
363  return $this->user . ($this->password !== '' ? ':' . $this->password : '');
364  }
user()
Definition: user.php:4
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasStandardPort()

Slim\Http\Uri::hasStandardPort ( )
protected

Does this Uri use a standard port?

Returns
bool

Definition at line 497 of file Uri.php.

Referenced by Slim\Http\Uri\getPort().

498  {
499  return ($this->scheme === 'http' && $this->port === 80) || ($this->scheme === 'https' && $this->port === 443);
500  }
+ Here is the caller graph for this function:

◆ withBasePath()

Slim\Http\Uri::withBasePath (   $basePath)

Set base path.

Note: This method is not part of the PSR-7 standard.

Parameters
string$basePath
Returns
self

Definition at line 615 of file Uri.php.

References Slim\Http\Uri\$basePath, and Slim\Http\Uri\filterPath().

616  {
617  if (!is_string($basePath)) {
618  throw new InvalidArgumentException('Uri path must be a string');
619  }
620  if (!empty($basePath)) {
621  $basePath = '/' . trim($basePath, '/'); // <-- Trim on both sides
622  }
623  $clone = clone $this;
624 
625  if ($basePath !== '/') {
626  $clone->basePath = $this->filterPath($basePath);
627  }
628 
629  return $clone;
630  }
filterPath($path)
Filter Uri path.
Definition: Uri.php:644
+ Here is the call graph for this function:

◆ withFragment()

Slim\Http\Uri::withFragment (   $fragment)

Return an instance with the specified URI fragment.

This method MUST retain the state of the current instance, and return an instance that contains the specified URI fragment.

Users can provide both encoded and decoded fragment characters. Implementations ensure the correct encoding as outlined in getFragment().

An empty fragment value is equivalent to removing the fragment.

Parameters
string$fragmentThe fragment to use with the new instance.
Returns
self A new instance with the specified fragment.

Implements Psr\Http\Message\UriInterface.

Definition at line 767 of file Uri.php.

References Slim\Http\Uri\$fragment, and Slim\Http\Uri\filterQuery().

768  {
769  if (!is_string($fragment) && !method_exists($fragment, '__toString')) {
770  throw new InvalidArgumentException('Uri fragment must be a string');
771  }
772  $fragment = ltrim((string)$fragment, '#');
773  $clone = clone $this;
774  $clone->fragment = $this->filterQuery($fragment);
775 
776  return $clone;
777  }
filterQuery($query)
Filters the query string or fragment of a URI.
Definition: Uri.php:717
+ Here is the call graph for this function:

◆ withHost()

Slim\Http\Uri::withHost (   $host)

Return an instance with the specified host.

This method MUST retain the state of the current instance, and return an instance that contains the specified host.

An empty host value is equivalent to removing the host.

Parameters
string$hostThe hostname to use with the new instance.
Returns
self A new instance with the specified host.
Exceptions

Implements Psr\Http\Message\UriInterface.

Definition at line 438 of file Uri.php.

References Slim\Http\Uri\$host.

439  {
440  $clone = clone $this;
441  $clone->host = $host;
442 
443  return $clone;
444  }

◆ withPath()

Slim\Http\Uri::withPath (   $path)

Return an instance with the specified path.

This method MUST retain the state of the current instance, and return an instance that contains the specified path.

The path can either be empty or absolute (starting with a slash) or rootless (not starting with a slash). Implementations MUST support all three syntaxes.

If the path is intended to be domain-relative rather than path relative then it must begin with a slash ("/"). Paths not starting with a slash ("/") are assumed to be relative to some base path known to the application or consumer.

Users can provide both encoded and decoded path characters. Implementations ensure the correct encoding as outlined in getPath().

Parameters
string$pathThe path to use with the new instance.
Returns
self A new instance with the specified path.
Exceptions

Implements Psr\Http\Message\UriInterface.

Definition at line 575 of file Uri.php.

References Slim\Http\Uri\$path, and Slim\Http\Uri\filterPath().

576  {
577  if (!is_string($path)) {
578  throw new InvalidArgumentException('Uri path must be a string');
579  }
580 
581  $clone = clone $this;
582  $clone->path = $this->filterPath($path);
583 
584  // if the path is absolute, then clear basePath
585  if (substr($path, 0, 1) == '/') {
586  $clone->basePath = '';
587  }
588 
589  return $clone;
590  }
filterPath($path)
Filter Uri path.
Definition: Uri.php:644
+ Here is the call graph for this function:

◆ withPort()

Slim\Http\Uri::withPort (   $port)

Return an instance with the specified port.

This method MUST retain the state of the current instance, and return an instance that contains the specified port.

Implementations MUST raise an exception for ports outside the established TCP and UDP port ranges.

A null value provided for the port is equivalent to removing the port information.

Parameters
null | int$portThe port to use with the new instance; a null value removes the port information.
Returns
self A new instance with the specified port.
Exceptions

Implements Psr\Http\Message\UriInterface.

Definition at line 483 of file Uri.php.

References Slim\Http\Uri\$port, and Slim\Http\Uri\filterPort().

484  {
485  $port = $this->filterPort($port);
486  $clone = clone $this;
487  $clone->port = $port;
488 
489  return $clone;
490  }
filterPort($port)
Filter Uri port.
Definition: Uri.php:510
+ Here is the call graph for this function:

◆ withQuery()

Slim\Http\Uri::withQuery (   $query)

Return an instance with the specified query string.

This method MUST retain the state of the current instance, and return an instance that contains the specified query string.

Users can provide both encoded and decoded query characters. Implementations ensure the correct encoding as outlined in getQuery().

An empty query string value is equivalent to removing the query string.

Parameters
string$queryThe query string to use with the new instance.
Returns
self A new instance with the specified query string.
Exceptions

Implements Psr\Http\Message\UriInterface.

Definition at line 699 of file Uri.php.

References Slim\Http\Uri\$query, and Slim\Http\Uri\filterQuery().

700  {
701  if (!is_string($query) && !method_exists($query, '__toString')) {
702  throw new InvalidArgumentException('Uri query must be a string');
703  }
704  $query = ltrim((string)$query, '?');
705  $clone = clone $this;
706  $clone->query = $this->filterQuery($query);
707 
708  return $clone;
709  }
filterQuery($query)
Filters the query string or fragment of a URI.
Definition: Uri.php:717
+ Here is the call graph for this function:

◆ withScheme()

Slim\Http\Uri::withScheme (   $scheme)

Return an instance with the specified scheme.

This method MUST retain the state of the current instance, and return an instance that contains the specified scheme.

Implementations MUST support the schemes "http" and "https" case insensitively, and MAY accommodate other schemes if required.

An empty scheme is equivalent to removing the scheme.

Parameters
string$schemeThe scheme to use with the new instance.
Returns
self A new instance with the specified scheme.
Exceptions

Implements Psr\Http\Message\UriInterface.

Definition at line 277 of file Uri.php.

References Slim\Http\Uri\$scheme, and Slim\Http\Uri\filterScheme().

278  {
279  $scheme = $this->filterScheme($scheme);
280  $clone = clone $this;
281  $clone->scheme = $scheme;
282 
283  return $clone;
284  }
filterScheme($scheme)
Filter Uri scheme.
Definition: Uri.php:295
+ Here is the call graph for this function:

◆ withUserInfo()

Slim\Http\Uri::withUserInfo (   $user,
  $password = null 
)

Return an instance with the specified user information.

This method MUST retain the state of the current instance, and return an instance that contains the specified user information.

Password is optional, but the user information MUST include the user; an empty string for the user is equivalent to removing user information.

Parameters
string$userThe user name to use for authority.
null | string$passwordThe password associated with $user.
Returns
self A new instance with the specified user information.

Implements Psr\Http\Message\UriInterface.

Definition at line 380 of file Uri.php.

References Slim\Http\Uri\$password, Slim\Http\Uri\$user, and Slim\Http\Uri\filterUserInfo().

381  {
382  $clone = clone $this;
383  $clone->user = $this->filterUserInfo($user);
384  if ('' !== $clone->user) {
385  $clone->password = !in_array($password, [null, ''], true) ? $this->filterUserInfo($password) : '';
386  } else {
387  $clone->password = '';
388  }
389 
390  return $clone;
391  }
filterUserInfo($query)
Filters the user info string.
Definition: Uri.php:399
+ Here is the call graph for this function:

Field Documentation

◆ $basePath

◆ $fragment

◆ $host

◆ $password

Slim\Http\Uri::$password = ''
protected

◆ $path

◆ $port

◆ $query

◆ $scheme

◆ $user

Slim\Http\Uri::$user = ''
protected

The documentation for this class was generated from the following file: