phasync
HTTP client / Uri

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#

NameValueDescription
SCHEME_PORTSarray ( '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#

MethodDescription
__constructCreates a URI from $uri.
getSchemeReturns the scheme of the URI, lower case.
getHostReturns the host of the URI, lower case.
getUserReturns the user of the URI.
getPasswordReturns the password of the URI.
getParamReturns the value of the query parameter $param, an array for name[] parameters, or null when it is not there.
getAuthorityRetrieve the authority component of the URI.
getUserInfoRetrieve the user information component of the URI.
getPortRetrieve the port component of the URI.
getPathReturns the path of the URI, up to the query and fragment.
getQueryReturns the query of the URI: what follows the "?", up to the fragment.
getFragmentReturns the fragment of the URI: what follows the "#".
withSchemeReturns a copy of the URI with the scheme replaced.
withUserInfoReturns a copy of the URI with the user and password replaced.
withHostReturns a copy of the URI with the host replaced; '' removes it.
withPortReturns a copy of the URI with the port replaced; null removes it.
withPathReturns a copy of the URI with the path replaced.
withQueryReturns a copy of the URI with the query replaced.
withFragmentReturns a copy of the URI with the fragment replaced.
__toStringReturns the URI as a string.
jsonSerializeReturns the URI as a string, like __toString().

Examples#

Example 1
$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.