Class
Uri
A PSR-7 URI.
Introduction#
Built from a string or another UriInterface. Immutable: the with...() methods return a modified copy.
Class synopsis#
class Uri implements UriInterface, \Stringable {
/* Methods */
public Uri::__construct(UriInterface|string $uri)
public Uri::getScheme(): string
public Uri::getHost(): string
public Uri::getUser(): string
public Uri::getPassword(): ?string
public Uri::getParam($param)
public Uri::getAuthority(): string
public Uri::getUserInfo(): string
public Uri::getPort(): ?int
public Uri::getPath(): string
public Uri::getQuery(): string
public Uri::getFragment(): string
public Uri::withScheme($scheme): UriInterface
public Uri::withUserInfo($user, $password = null): UriInterface
public Uri::withHost($host): UriInterface
public Uri::withPort($port): UriInterface
public Uri::withPath($path): UriInterface
public Uri::withQuery($query): UriInterface
public Uri::withFragment($fragment): UriInterface
public Uri::__toString(): string
public Uri::jsonSerialize()
}Constants#
| Name | Value | Description |
|---|---|---|
SCHEME_PORTS | array ( 'ftp' => 21, 'ssh' => 22, 'telnet' => 23, 'smtp' => 25, 'gopher' => 70, 'finger' => 79, 'http' => 80, 'rtelnet' => 107, 'pop3' => 110, 'sftp' => 115, 'nntp' => 119, 'ntp' => 123, 'imap' => 143, 'snmp' => 161, 'irc' => 194, 'ldap' => 389, 'smtpe' => 420, 'https' => 443, 'ftps' => 990, 'imaps' => 993, 'pop3s' => 995, 'wins' => 1512, 'rtmp' => 1935, ) |
Methods#
| Method | Description |
|---|---|
__construct | Creates a URI from $uri. |
getScheme | Returns the scheme of the URI, lower case. |
getHost | Returns the host of the URI, lower case. |
getUser | Returns the user of the URI. |
getPassword | Returns the password of the URI. |
getParam | Returns the value of the query parameter $param, an array for name[] parameters, or null when it is not there. |
getAuthority | Retrieve the authority component of the URI. |
getUserInfo | Retrieve the user information component of the URI. |
getPort | Retrieve the port component of the URI. |
getPath | Returns the path of the URI, up to the query and fragment. |
getQuery | Returns the query of the URI: what follows the "?", up to the fragment. |
getFragment | Returns the fragment of the URI: what follows the "#". |
withScheme | Returns a copy of the URI with the scheme replaced. |
withUserInfo | Returns a copy of the URI with the user and password replaced. |
withHost | Returns a copy of the URI with the host replaced; '' removes it. |
withPort | Returns a copy of the URI with the port replaced; null removes it. |
withPath | Returns a copy of the URI with the path replaced. |
withQuery | Returns a copy of the URI with the query replaced. |
withFragment | Returns a copy of the URI with the fragment replaced. |
__toString | Returns the URI as a string. |
jsonSerialize | Returns the URI as a string, like __toString(). |
Examples#
$uri = new Uri('https://example.com/search?q=phasync');
$uri->getHost(); // "example.com"
(string) $uri->withPath('/docs'); // "https://example.com/docs?q=phasync"See also#
Request::getUriReturns the attached URI override, or a URI derived from the request-target plus the Host header.