ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
GuzzleHttp\Psr7\Uri Class Reference

PSR-7 URI implementation. More...

+ Inheritance diagram for GuzzleHttp\Psr7\Uri:
+ Collaboration diagram for GuzzleHttp\Psr7\Uri:

Public Member Functions

 __construct ($uri='')
 
 __toString ()
 Return the string representation as a URI reference. More...
 
 getScheme ()
 Retrieve the scheme component of the URI. More...
 
 getAuthority ()
 Retrieve the authority component of the URI. More...
 
 getUserInfo ()
 Retrieve the user information component of the URI. More...
 
 getHost ()
 Retrieve the host component of the URI. More...
 
 getPort ()
 Retrieve the port component of the URI. More...
 
 getPath ()
 Retrieve the path component of the URI. More...
 
 getQuery ()
 Retrieve the query string of the URI. More...
 
 getFragment ()
 Retrieve the fragment component of the URI. More...
 
 withScheme ($scheme)
 Return an instance with the specified scheme. More...
 
 withUserInfo ($user, $password=null)
 Return an instance with the specified user information. More...
 
 withHost ($host)
 Return an instance with the specified host. More...
 
 withPort ($port)
 Return an instance with the specified port. More...
 
 withPath ($path)
 Return an instance with the specified path. More...
 
 withQuery ($query)
 Return an instance with the specified query string. More...
 
 withFragment ($fragment)
 Return an instance with the specified URI fragment. More...
 

Static Public Member Functions

static composeComponents ($scheme, $authority, $path, $query, $fragment)
 Composes a URI reference string from its various components. More...
 
static isDefaultPort (UriInterface $uri)
 Whether the URI has the default port of the current scheme. More...
 
static isAbsolute (UriInterface $uri)
 Whether the URI is absolute, i.e. More...
 
static isNetworkPathReference (UriInterface $uri)
 Whether the URI is a network-path reference. More...
 
static isAbsolutePathReference (UriInterface $uri)
 Whether the URI is a absolute-path reference. More...
 
static isRelativePathReference (UriInterface $uri)
 Whether the URI is a relative-path reference. More...
 
static isSameDocumentReference (UriInterface $uri, UriInterface $base=null)
 Whether the URI is a same-document reference. More...
 
static removeDotSegments ($path)
 Removes dot segments from a path and returns the new path. More...
 
static resolve (UriInterface $base, $rel)
 Converts the relative URI into a new URI that is resolved against the base URI. More...
 
static withoutQueryValue (UriInterface $uri, $key)
 Creates a new URI with a specific query string value removed. More...
 
static withQueryValue (UriInterface $uri, $key, $value)
 Creates a new URI with a specific query string value. More...
 
static fromParts (array $parts)
 Creates a URI from a hash of parse_url components. More...
 

Data Fields

const HTTP_DEFAULT_HOST = 'localhost'
 Absolute http and https URIs require a host per RFC 7230 Section 2.7 but in generic URIs the host can be empty. More...
 

Private Member Functions

 applyParts (array $parts)
 Apply parse_url parts to a URI. More...
 
 filterScheme ($scheme)
 
 filterHost ($host)
 
 filterPort ($port)
 
 removeDefaultPort ()
 
 filterPath ($path)
 Filters the path of a URI. More...
 
 filterQueryAndFragment ($str)
 Filters the query string or fragment of a URI. More...
 
 rawurlencodeMatchZero (array $match)
 
 validateState ()
 

Private Attributes

 $scheme = ''
 
 $userInfo = ''
 
 $host = ''
 
 $port
 
 $path = ''
 
 $query = ''
 
 $fragment = ''
 

Static Private Attributes

static $defaultPorts
 
static static $charUnreserved = 'a-zA-Z0-9_\-\.~'
 
static $charSubDelims = '!\$&\'\(\)\*\+,;='
 
static $replaceQuery = ['=' => '%3D'
 

Detailed Description

PSR-7 URI implementation.

Author
Michael Dowling
Tobias Schultze
Matthew Weier O'Phinney

Definition at line 13 of file Uri.php.

Constructor & Destructor Documentation

◆ __construct()

GuzzleHttp\Psr7\Uri::__construct (   $uri = '')
Parameters
string$uriURI to parse

Definition at line 65 of file Uri.php.

References GuzzleHttp\Psr7\Uri\applyParts().

66  {
67  // weak type check to also accept null until we can add scalar type hints
68  if ($uri != '') {
69  $parts = parse_url($uri);
70  if ($parts === false) {
71  throw new \InvalidArgumentException("Unable to parse URI: $uri");
72  }
73  $this->applyParts($parts);
74  }
75  }
applyParts(array $parts)
Apply parse_url parts to a URI.
Definition: Uri.php:540
+ Here is the call graph for this function:

Member Function Documentation

◆ __toString()

GuzzleHttp\Psr7\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 77 of file Uri.php.

References GuzzleHttp\Psr7\Uri\getAuthority().

78  {
79  return self::composeComponents(
80  $this->scheme,
81  $this->getAuthority(),
82  $this->path,
83  $this->query,
84  $this->fragment
85  );
86  }
getAuthority()
Retrieve the authority component of the URI.
Definition: Uri.php:383
+ Here is the call graph for this function:

◆ applyParts()

GuzzleHttp\Psr7\Uri::applyParts ( array  $parts)
private

Apply parse_url parts to a URI.

Parameters
array$partsArray of parse_url parts to apply.

Definition at line 540 of file Uri.php.

References GuzzleHttp\Psr7\Uri\filterHost(), GuzzleHttp\Psr7\Uri\filterPath(), GuzzleHttp\Psr7\Uri\filterPort(), GuzzleHttp\Psr7\Uri\filterQueryAndFragment(), GuzzleHttp\Psr7\Uri\filterScheme(), and GuzzleHttp\Psr7\Uri\removeDefaultPort().

Referenced by GuzzleHttp\Psr7\Uri\__construct().

541  {
542  $this->scheme = isset($parts['scheme'])
543  ? $this->filterScheme($parts['scheme'])
544  : '';
545  $this->userInfo = isset($parts['user']) ? $parts['user'] : '';
546  $this->host = isset($parts['host'])
547  ? $this->filterHost($parts['host'])
548  : '';
549  $this->port = isset($parts['port'])
550  ? $this->filterPort($parts['port'])
551  : null;
552  $this->path = isset($parts['path'])
553  ? $this->filterPath($parts['path'])
554  : '';
555  $this->query = isset($parts['query'])
556  ? $this->filterQueryAndFragment($parts['query'])
557  : '';
558  $this->fragment = isset($parts['fragment'])
559  ? $this->filterQueryAndFragment($parts['fragment'])
560  : '';
561  if (isset($parts['pass'])) {
562  $this->userInfo .= ':' . $parts['pass'];
563  }
564 
565  $this->removeDefaultPort();
566  }
filterHost($host)
Definition: Uri.php:591
filterScheme($scheme)
Definition: Uri.php:575
filterPort($port)
Definition: Uri.php:607
filterPath($path)
Filters the path of a URI.
Definition: Uri.php:639
filterQueryAndFragment($str)
Filters the query string or fragment of a URI.
Definition: Uri.php:661
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ composeComponents()

static GuzzleHttp\Psr7\Uri::composeComponents (   $scheme,
  $authority,
  $path,
  $query,
  $fragment 
)
static

Composes a URI reference string from its various components.

Usually this method does not need to be called manually but instead is used indirectly via Psr\Http\Message\UriInterface::__toString.

PSR-7 UriInterface treats an empty component the same as a missing component as getQuery(), getFragment() etc. always return a string. This explains the slight difference to RFC 3986 Section 5.3.

Another adjustment is that the authority separator is added even when the authority is missing/empty for the "file" scheme. This is because PHP stream functions like file_get_contents only work with file:///myfile but not with file:/myfile although they are equivalent according to RFC 3986. But file:/// is the more common syntax for the file scheme anyway (Chrome for example redirects to that format).

Parameters
string$scheme
string$authority
string$path
string$query
string$fragment
Returns
string

https://tools.ietf.org/html/rfc3986#section-5.3

Definition at line 114 of file Uri.php.

References $authority, GuzzleHttp\Psr7\Uri\$fragment, GuzzleHttp\Psr7\Uri\$path, GuzzleHttp\Psr7\Uri\$query, and GuzzleHttp\Psr7\Uri\$scheme.

Referenced by GuzzleHttp\Psr7\UriResolver\resolve().

115  {
116  $uri = '';
117 
118  // weak type checks to also accept null until we can add scalar type hints
119  if ($scheme != '') {
120  $uri .= $scheme . ':';
121  }
122 
123  if ($authority != ''|| $scheme === 'file') {
124  $uri .= '//' . $authority;
125  }
126 
127  $uri .= $path;
128 
129  if ($query != '') {
130  $uri .= '?' . $query;
131  }
132 
133  if ($fragment != '') {
134  $uri .= '#' . $fragment;
135  }
136 
137  return $uri;
138  }
$authority
+ Here is the caller graph for this function:

◆ filterHost()

GuzzleHttp\Psr7\Uri::filterHost (   $host)
private
Parameters
string$host
Returns
string
Exceptions

Definition at line 591 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$host.

Referenced by GuzzleHttp\Psr7\Uri\applyParts(), and GuzzleHttp\Psr7\Uri\withHost().

592  {
593  if (!is_string($host)) {
594  throw new \InvalidArgumentException('Host must be a string');
595  }
596 
597  return strtolower($host);
598  }
+ Here is the caller graph for this function:

◆ filterPath()

GuzzleHttp\Psr7\Uri::filterPath (   $path)
private

Filters the path of a URI.

Parameters
string$path
Returns
string
Exceptions

Definition at line 639 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$path.

Referenced by GuzzleHttp\Psr7\Uri\applyParts(), and GuzzleHttp\Psr7\Uri\withPath().

640  {
641  if (!is_string($path)) {
642  throw new \InvalidArgumentException('Path must be a string');
643  }
644 
645  return preg_replace_callback(
646  '/(?:[^' . self::$charUnreserved . self::$charSubDelims . '%:@\/]++|%(?![A-Fa-f0-9]{2}))/',
647  [$this, 'rawurlencodeMatchZero'],
648  $path
649  );
650  }
+ Here is the caller graph for this function:

◆ filterPort()

GuzzleHttp\Psr7\Uri::filterPort (   $port)
private
Parameters
int | null$port
Returns
int|null
Exceptions

Definition at line 607 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$port.

Referenced by GuzzleHttp\Psr7\Uri\applyParts(), and GuzzleHttp\Psr7\Uri\withPort().

608  {
609  if ($port === null) {
610  return null;
611  }
612 
613  $port = (int) $port;
614  if (1 > $port || 0xffff < $port) {
615  throw new \InvalidArgumentException(
616  sprintf('Invalid port: %d. Must be between 1 and 65535', $port)
617  );
618  }
619 
620  return $port;
621  }
+ Here is the caller graph for this function:

◆ filterQueryAndFragment()

GuzzleHttp\Psr7\Uri::filterQueryAndFragment (   $str)
private

Filters the query string or fragment of a URI.

Parameters
string$str
Returns
string
Exceptions

Definition at line 661 of file Uri.php.

Referenced by GuzzleHttp\Psr7\Uri\applyParts(), GuzzleHttp\Psr7\Uri\withFragment(), and GuzzleHttp\Psr7\Uri\withQuery().

662  {
663  if (!is_string($str)) {
664  throw new \InvalidArgumentException('Query and fragment must be a string');
665  }
666 
667  return preg_replace_callback(
668  '/(?:[^' . self::$charUnreserved . self::$charSubDelims . '%:@\/\?]++|%(?![A-Fa-f0-9]{2}))/',
669  [$this, 'rawurlencodeMatchZero'],
670  $str
671  );
672  }
+ Here is the caller graph for this function:

◆ filterScheme()

GuzzleHttp\Psr7\Uri::filterScheme (   $scheme)
private
Parameters
string$scheme
Returns
string
Exceptions

Definition at line 575 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$scheme.

Referenced by GuzzleHttp\Psr7\Uri\applyParts(), and GuzzleHttp\Psr7\Uri\withScheme().

576  {
577  if (!is_string($scheme)) {
578  throw new \InvalidArgumentException('Scheme must be a string');
579  }
580 
581  return strtolower($scheme);
582  }
+ Here is the caller graph for this function:

◆ fromParts()

static GuzzleHttp\Psr7\Uri::fromParts ( array  $parts)
static

Creates a URI from a hash of parse_url components.

Parameters
array$parts
Returns
UriInterface If the components do not form a valid URI.

Definition at line 369 of file Uri.php.

370  {
371  $uri = new self();
372  $uri->applyParts($parts);
373  $uri->validateState();
374 
375  return $uri;
376  }

◆ getAuthority()

GuzzleHttp\Psr7\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 383 of file Uri.php.

References $authority, GuzzleHttp\Psr7\Uri\$host, and GuzzleHttp\Psr7\Uri\$port.

Referenced by GuzzleHttp\Psr7\Uri\__toString(), and GuzzleHttp\Psr7\Uri\validateState().

384  {
386  if ($this->userInfo !== '') {
387  $authority = $this->userInfo . '@' . $authority;
388  }
389 
390  if ($this->port !== null) {
391  $authority .= ':' . $this->port;
392  }
393 
394  return $authority;
395  }
$authority
+ Here is the caller graph for this function:

◆ getFragment()

GuzzleHttp\Psr7\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 422 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$fragment.

423  {
424  return $this->fragment;
425  }

◆ getHost()

GuzzleHttp\Psr7\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 402 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$host.

403  {
404  return $this->host;
405  }

◆ getPath()

GuzzleHttp\Psr7\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 412 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$path.

413  {
414  return $this->path;
415  }

◆ getPort()

GuzzleHttp\Psr7\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 407 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$port.

408  {
409  return $this->port;
410  }

◆ getQuery()

GuzzleHttp\Psr7\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 417 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$query.

418  {
419  return $this->query;
420  }

◆ getScheme()

GuzzleHttp\Psr7\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 378 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$scheme.

379  {
380  return $this->scheme;
381  }

◆ getUserInfo()

GuzzleHttp\Psr7\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 397 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$userInfo.

398  {
399  return $this->userInfo;
400  }

◆ isAbsolute()

static GuzzleHttp\Psr7\Uri::isAbsolute ( UriInterface  $uri)
static

Whether the URI is absolute, i.e.

it has a scheme.

An instance of UriInterface can either be an absolute URI or a relative reference. This method returns true if it is the former. An absolute URI has a scheme. A relative reference is used to express a URI relative to another URI, the base URI. Relative references can be divided into several forms:

  • network-path references, e.g. '//example.com/path'
  • absolute-path references, e.g. '/path'
  • relative-path references, e.g. 'subpath'
Parameters
UriInterface$uri
Returns
bool
See also
Uri::isNetworkPathReference
Uri::isAbsolutePathReference
Uri::isRelativePathReference https://tools.ietf.org/html/rfc3986#section-4

Definition at line 174 of file Uri.php.

References Psr\Http\Message\UriInterface\getScheme().

175  {
176  return $uri->getScheme() !== '';
177  }
+ Here is the call graph for this function:

◆ isAbsolutePathReference()

static GuzzleHttp\Psr7\Uri::isAbsolutePathReference ( UriInterface  $uri)
static

Whether the URI is a absolute-path reference.

A relative reference that begins with a single slash character is termed an absolute-path reference.

Parameters
UriInterface$uri
Returns
bool https://tools.ietf.org/html/rfc3986#section-4.2

Definition at line 204 of file Uri.php.

References Psr\Http\Message\UriInterface\getAuthority(), Psr\Http\Message\UriInterface\getPath(), and Psr\Http\Message\UriInterface\getScheme().

205  {
206  return $uri->getScheme() === ''
207  && $uri->getAuthority() === ''
208  && isset($uri->getPath()[0])
209  && $uri->getPath()[0] === '/';
210  }
+ Here is the call graph for this function:

◆ isDefaultPort()

static GuzzleHttp\Psr7\Uri::isDefaultPort ( UriInterface  $uri)
static

Whether the URI has the default port of the current scheme.

Psr\Http\Message\UriInterface::getPort may return null or the standard port. This method can be used independently of the implementation.

Parameters
UriInterface$uri
Returns
bool

Definition at line 150 of file Uri.php.

References Psr\Http\Message\UriInterface\getPort(), and Psr\Http\Message\UriInterface\getScheme().

Referenced by GuzzleHttp\Psr7\UriNormalizer\normalize().

151  {
152  return $uri->getPort() === null
153  || (isset(self::$defaultPorts[$uri->getScheme()]) && $uri->getPort() === self::$defaultPorts[$uri->getScheme()]);
154  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isNetworkPathReference()

static GuzzleHttp\Psr7\Uri::isNetworkPathReference ( UriInterface  $uri)
static

Whether the URI is a network-path reference.

A relative reference that begins with two slash characters is termed an network-path reference.

Parameters
UriInterface$uri
Returns
bool https://tools.ietf.org/html/rfc3986#section-4.2

Definition at line 189 of file Uri.php.

References Psr\Http\Message\UriInterface\getAuthority(), and Psr\Http\Message\UriInterface\getScheme().

190  {
191  return $uri->getScheme() === '' && $uri->getAuthority() !== '';
192  }
+ Here is the call graph for this function:

◆ isRelativePathReference()

static GuzzleHttp\Psr7\Uri::isRelativePathReference ( UriInterface  $uri)
static

Whether the URI is a relative-path reference.

A relative reference that does not begin with a slash character is termed a relative-path reference.

Parameters
UriInterface$uri
Returns
bool https://tools.ietf.org/html/rfc3986#section-4.2

Definition at line 222 of file Uri.php.

References Psr\Http\Message\UriInterface\getAuthority(), Psr\Http\Message\UriInterface\getPath(), and Psr\Http\Message\UriInterface\getScheme().

Referenced by GuzzleHttp\Psr7\UriNormalizer\normalize(), and GuzzleHttp\Psr7\UriResolver\relativize().

223  {
224  return $uri->getScheme() === ''
225  && $uri->getAuthority() === ''
226  && (!isset($uri->getPath()[0]) || $uri->getPath()[0] !== '/');
227  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isSameDocumentReference()

static GuzzleHttp\Psr7\Uri::isSameDocumentReference ( UriInterface  $uri,
UriInterface  $base = null 
)
static

Whether the URI is a same-document reference.

A same-document reference refers to a URI that is, aside from its fragment component, identical to the base URI. When no base URI is given, only an empty URI reference (apart from its fragment) is considered a same-document reference.

Parameters
UriInterface$uriThe URI to check
UriInterface | null$baseAn optional base URI to compare against
Returns
bool https://tools.ietf.org/html/rfc3986#section-4.4

Definition at line 242 of file Uri.php.

References $base, Psr\Http\Message\UriInterface\getAuthority(), Psr\Http\Message\UriInterface\getPath(), Psr\Http\Message\UriInterface\getQuery(), Psr\Http\Message\UriInterface\getScheme(), and GuzzleHttp\Psr7\UriResolver\resolve().

243  {
244  if ($base !== null) {
245  $uri = UriResolver::resolve($base, $uri);
246 
247  return ($uri->getScheme() === $base->getScheme())
248  && ($uri->getAuthority() === $base->getAuthority())
249  && ($uri->getPath() === $base->getPath())
250  && ($uri->getQuery() === $base->getQuery());
251  }
252 
253  return $uri->getScheme() === '' && $uri->getAuthority() === '' && $uri->getPath() === '' && $uri->getQuery() === '';
254  }
static resolve(UriInterface $base, UriInterface $rel)
Converts the relative URI into a new URI that is resolved against the base URI.
Definition: UriResolver.php:62
$base
Definition: index.php:4
+ Here is the call graph for this function:

◆ rawurlencodeMatchZero()

GuzzleHttp\Psr7\Uri::rawurlencodeMatchZero ( array  $match)
private

Definition at line 674 of file Uri.php.

675  {
676  return rawurlencode($match[0]);
677  }

◆ removeDefaultPort()

GuzzleHttp\Psr7\Uri::removeDefaultPort ( )
private

Definition at line 623 of file Uri.php.

Referenced by GuzzleHttp\Psr7\Uri\applyParts().

624  {
625  if ($this->port !== null && self::isDefaultPort($this)) {
626  $this->port = null;
627  }
628  }
+ Here is the caller graph for this function:

◆ removeDotSegments()

static GuzzleHttp\Psr7\Uri::removeDotSegments (   $path)
static

Removes dot segments from a path and returns the new path.

Parameters
string$path
Returns
string
Deprecated:
since version 1.4. Use UriResolver::removeDotSegments instead.
See also
UriResolver::removeDotSegments

Definition at line 266 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$path, and GuzzleHttp\Psr7\UriResolver\removeDotSegments().

267  {
269  }
static removeDotSegments($path)
Removes dot segments from a path and returns the new path.
Definition: UriResolver.php:23
+ Here is the call graph for this function:

◆ resolve()

static GuzzleHttp\Psr7\Uri::resolve ( UriInterface  $base,
  $rel 
)
static

Converts the relative URI into a new URI that is resolved against the base URI.

Parameters
UriInterface$baseBase URI
string | UriInterface$relRelative URI
Returns
UriInterface
Deprecated:
since version 1.4. Use UriResolver::resolve instead.
See also
UriResolver::resolve

Definition at line 282 of file Uri.php.

References GuzzleHttp\Psr7\UriResolver\resolve().

283  {
284  if (!($rel instanceof UriInterface)) {
285  $rel = new self($rel);
286  }
287 
288  return UriResolver::resolve($base, $rel);
289  }
static resolve(UriInterface $base, UriInterface $rel)
Converts the relative URI into a new URI that is resolved against the base URI.
Definition: UriResolver.php:62
$base
Definition: index.php:4
+ Here is the call graph for this function:

◆ validateState()

GuzzleHttp\Psr7\Uri::validateState ( )
private

Definition at line 679 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$path, and GuzzleHttp\Psr7\Uri\getAuthority().

680  {
681  if ($this->host === '' && ($this->scheme === 'http' || $this->scheme === 'https')) {
682  $this->host = self::HTTP_DEFAULT_HOST;
683  }
684 
685  if ($this->getAuthority() === '') {
686  if (0 === strpos($this->path, '//')) {
687  throw new \InvalidArgumentException('The path of a URI without an authority must not start with two slashes "//"');
688  }
689  if ($this->scheme === '' && false !== strpos(explode('/', $this->path, 2)[0], ':')) {
690  throw new \InvalidArgumentException('A relative URI must not have a path beginning with a segment containing a colon');
691  }
692  } elseif (isset($this->path[0]) && $this->path[0] !== '/') {
693  @trigger_error(
694  'The path of a URI with an authority must start with a slash "/" or be empty. Automagically fixing the URI ' .
695  'by adding a leading slash to the path is deprecated since version 1.4 and will throw an exception instead.',
696  E_USER_DEPRECATED
697  );
698  $this->path = '/'. $this->path;
699  //throw new \InvalidArgumentException('The path of a URI with an authority must start with a slash "/" or be empty');
700  }
701  }
getAuthority()
Retrieve the authority component of the URI.
Definition: Uri.php:383
+ Here is the call graph for this function:

◆ withFragment()

GuzzleHttp\Psr7\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
static A new instance with the specified fragment.

Implements Psr\Http\Message\UriInterface.

Definition at line 521 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$fragment, and GuzzleHttp\Psr7\Uri\filterQueryAndFragment().

522  {
524 
525  if ($this->fragment === $fragment) {
526  return $this;
527  }
528 
529  $new = clone $this;
530  $new->fragment = $fragment;
531 
532  return $new;
533  }
filterQueryAndFragment($str)
Filters the query string or fragment of a URI.
Definition: Uri.php:661
+ Here is the call graph for this function:

◆ withHost()

GuzzleHttp\Psr7\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
static A new instance with the specified host.
Exceptions

Implements Psr\Http\Message\UriInterface.

Definition at line 461 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$host, and GuzzleHttp\Psr7\Uri\filterHost().

462  {
463  $host = $this->filterHost($host);
464 
465  if ($this->host === $host) {
466  return $this;
467  }
468 
469  $new = clone $this;
470  $new->host = $host;
471  $new->validateState();
472 
473  return $new;
474  }
filterHost($host)
Definition: Uri.php:591
+ Here is the call graph for this function:

◆ withoutQueryValue()

static GuzzleHttp\Psr7\Uri::withoutQueryValue ( UriInterface  $uri,
  $key 
)
static

Creates a new URI with a specific query string value removed.

Any existing query string values that exactly match the provided key are removed.

Parameters
UriInterface$uriURI to use as a base.
string$keyQuery string key to remove.
Returns
UriInterface

Definition at line 302 of file Uri.php.

References $current, $key, $result, Psr\Http\Message\UriInterface\getQuery(), and Psr\Http\Message\UriInterface\withQuery().

303  {
304  $current = $uri->getQuery();
305  if ($current === '') {
306  return $uri;
307  }
308 
309  $decodedKey = rawurldecode($key);
310  $result = array_filter(explode('&', $current), function ($part) use ($decodedKey) {
311  return rawurldecode(explode('=', $part)[0]) !== $decodedKey;
312  });
313 
314  return $uri->withQuery(implode('&', $result));
315  }
$result
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ withPath()

GuzzleHttp\Psr7\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
static A new instance with the specified path.
Exceptions

Implements Psr\Http\Message\UriInterface.

Definition at line 492 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$path, and GuzzleHttp\Psr7\Uri\filterPath().

493  {
494  $path = $this->filterPath($path);
495 
496  if ($this->path === $path) {
497  return $this;
498  }
499 
500  $new = clone $this;
501  $new->path = $path;
502  $new->validateState();
503 
504  return $new;
505  }
filterPath($path)
Filters the path of a URI.
Definition: Uri.php:639
+ Here is the call graph for this function:

◆ withPort()

GuzzleHttp\Psr7\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
static A new instance with the specified port.
Exceptions

Implements Psr\Http\Message\UriInterface.

Definition at line 476 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$port, and GuzzleHttp\Psr7\Uri\filterPort().

477  {
478  $port = $this->filterPort($port);
479 
480  if ($this->port === $port) {
481  return $this;
482  }
483 
484  $new = clone $this;
485  $new->port = $port;
486  $new->removeDefaultPort();
487  $new->validateState();
488 
489  return $new;
490  }
filterPort($port)
Definition: Uri.php:607
+ Here is the call graph for this function:

◆ withQuery()

GuzzleHttp\Psr7\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
static A new instance with the specified query string.
Exceptions

Implements Psr\Http\Message\UriInterface.

Definition at line 507 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$query, and GuzzleHttp\Psr7\Uri\filterQueryAndFragment().

508  {
510 
511  if ($this->query === $query) {
512  return $this;
513  }
514 
515  $new = clone $this;
516  $new->query = $query;
517 
518  return $new;
519  }
filterQueryAndFragment($str)
Filters the query string or fragment of a URI.
Definition: Uri.php:661
+ Here is the call graph for this function:

◆ withQueryValue()

static GuzzleHttp\Psr7\Uri::withQueryValue ( UriInterface  $uri,
  $key,
  $value 
)
static

Creates a new URI with a specific query string value.

Any existing query string values that exactly match the provided key are removed and replaced with the given key value pair.

A value of null will set the query string key without a value, e.g. "key" instead of "key=value".

Parameters
UriInterface$uriURI to use as a base.
string$keyKey to set.
string | null$valueValue to set
Returns
UriInterface

Definition at line 332 of file Uri.php.

References $current, $key, $result, Psr\Http\Message\UriInterface\getQuery(), and Psr\Http\Message\UriInterface\withQuery().

333  {
334  $current = $uri->getQuery();
335 
336  if ($current === '') {
337  $result = [];
338  } else {
339  $decodedKey = rawurldecode($key);
340  $result = array_filter(explode('&', $current), function ($part) use ($decodedKey) {
341  return rawurldecode(explode('=', $part)[0]) !== $decodedKey;
342  });
343  }
344 
345  // Query string separators ("=", "&") within the key or value need to be encoded
346  // (while preventing double-encoding) before setting the query string. All other
347  // chars that need percent-encoding will be encoded by withQuery().
348  $key = strtr($key, self::$replaceQuery);
349 
350  if ($value !== null) {
351  $result[] = $key . '=' . strtr($value, self::$replaceQuery);
352  } else {
353  $result[] = $key;
354  }
355 
356  return $uri->withQuery(implode('&', $result));
357  }
$result
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ withScheme()

GuzzleHttp\Psr7\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
static A new instance with the specified scheme.
Exceptions

Implements Psr\Http\Message\UriInterface.

Definition at line 427 of file Uri.php.

References GuzzleHttp\Psr7\Uri\$scheme, and GuzzleHttp\Psr7\Uri\filterScheme().

428  {
429  $scheme = $this->filterScheme($scheme);
430 
431  if ($this->scheme === $scheme) {
432  return $this;
433  }
434 
435  $new = clone $this;
436  $new->scheme = $scheme;
437  $new->removeDefaultPort();
438  $new->validateState();
439 
440  return $new;
441  }
filterScheme($scheme)
Definition: Uri.php:575
+ Here is the call graph for this function:

◆ withUserInfo()

GuzzleHttp\Psr7\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
static A new instance with the specified user information.

Implements Psr\Http\Message\UriInterface.

Definition at line 443 of file Uri.php.

References $info, $password, and $user.

444  {
445  $info = $user;
446  if ($password != '') {
447  $info .= ':' . $password;
448  }
449 
450  if ($this->userInfo === $info) {
451  return $this;
452  }
453 
454  $new = clone $this;
455  $new->userInfo = $info;
456  $new->validateState();
457 
458  return $new;
459  }
$user
Definition: migrateto20.php:57
$password
Definition: cron.php:14
$info
Definition: index.php:5

Field Documentation

◆ $charSubDelims

GuzzleHttp\Psr7\Uri::$charSubDelims = '!\$&\'\(\)\*\+,;='
staticprivate

Definition at line 38 of file Uri.php.

◆ $charUnreserved

static GuzzleHttp\Psr7\Uri::$charUnreserved = 'a-zA-Z0-9_\-\.~'
staticprivate

Definition at line 37 of file Uri.php.

◆ $defaultPorts

GuzzleHttp\Psr7\Uri::$defaultPorts
staticprivate
Initial value:
= [
'http' => 80

Definition at line 23 of file Uri.php.

◆ $fragment

GuzzleHttp\Psr7\Uri::$fragment = ''
private

◆ $host

GuzzleHttp\Psr7\Uri::$host = ''
private

◆ $path

◆ $port

GuzzleHttp\Psr7\Uri::$port
private

◆ $query

GuzzleHttp\Psr7\Uri::$query = ''
private

◆ $replaceQuery

GuzzleHttp\Psr7\Uri::$replaceQuery = ['=' => '%3D'
staticprivate

Definition at line 39 of file Uri.php.

◆ $scheme

GuzzleHttp\Psr7\Uri::$scheme = ''
private

◆ $userInfo

GuzzleHttp\Psr7\Uri::$userInfo = ''
private

Definition at line 45 of file Uri.php.

Referenced by GuzzleHttp\Psr7\Uri\getUserInfo().

◆ HTTP_DEFAULT_HOST

const GuzzleHttp\Psr7\Uri::HTTP_DEFAULT_HOST = 'localhost'

Absolute http and https URIs require a host per RFC 7230 Section 2.7 but in generic URIs the host can be empty.

So for http(s) URIs we apply this default host when no host is given yet to form a valid URI.

Definition at line 21 of file Uri.php.


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