Rfc3986
in package
Syntax predicates and canonicalization helpers for the URI grammar defined by RFC 3986.
Table of Contents
Methods
- canonicalizeIpv6() : string
- Returns the RFC 5952 canonical form of a valid IPv6 address.
- isValidHost() : bool
- Whether the string is a valid URI host.
- isValidPort() : bool
- Whether the string is a valid port number (0-65535).
- isValidScheme() : bool
- Whether the string is a valid URI scheme.
Methods
canonicalizeIpv6()
Returns the RFC 5952 canonical form of a valid IPv6 address.
public
static canonicalizeIpv6(string $address) : string
The address must be a valid textual IPv6 address without brackets and
without a zone identifier, such as the inside of an IP-literal accepted
by isValidHost(). Canonicalization lowercases the hexadecimal fields,
suppresses leading zeros, and collapses the longest run of two or more
zero fields (the leftmost on a tie) with ::. Embedded dotted-decimal
notation follows the rendering policy of BIND-derived inet_ntop()
implementations and curl: exactly the IPv4-mapped (::ffff:0:0/96) and
deprecated IPv4-compatible (::/96) layouts use it, while other
embedded-IPv4 forms, including translated (NAT64) well-known prefixes
such as 64:ff9b::/96 (RFC 6052), serialize in pure hexadecimal fields.
Validation is strict and platform-independent: the address is checked
against the RFC 3986 IPv6address grammar with PHP's
FILTER_VALIDATE_IP filter and parsed in pure PHP, so spellings that
only some platform parsers accept, such as the zero-padded dotted octets
in ::ffff:192.168.001.001, are rejected everywhere.
Parameters
- $address : string
Tags
Return values
stringisValidHost()
Whether the string is a valid URI host.
public
static isValidHost(string $host) : bool
Per RFC 3986 the host is IP-literal / IPv4address / reg-name. An empty
host is accepted, since the authority (and thus the host) may be empty.
Bracketed values are validated as IPv6 / IPvFuture literals; any other
value is rejected if it contains control characters, whitespace, an
authority or path delimiter (/ ? # @ \), an embedded colon denoting
a port, a malformed percent-sequence, or a percent-encoded octet that
decodes to one of those rejected bytes, to a bracket, or to % itself.
Parameters
- $host : string
Tags
Return values
boolisValidPort()
Whether the string is a valid port number (0-65535).
public
static isValidPort(string $port) : bool
RFC 3986 defines the port as *DIGIT, which also permits an empty port
and has no upper bound. This applies the stricter policy used throughout
the library instead: the value must be a non-empty run of digits (leading
zeros are accepted and normalized) that resolves to 0-65535.
Parameters
- $port : string
Tags
Return values
boolisValidScheme()
Whether the string is a valid URI scheme.
public
static isValidScheme(string $scheme) : bool
Per RFC 3986 a scheme must start with a letter, followed by letters,
digits, +, -, or .. The empty string is also accepted, since a URI
reference may omit the scheme.
Parameters
- $scheme : string