-
Notifications
You must be signed in to change notification settings - Fork 1
Uri
Sometimes it's useful to have a URI wrapped into a class which provides methods to work with this URI. Stubbles Core provides stubbles\peer\Uri
for such cases.
New instances can be created via Uri::fromString('ftp://user:secret@example.net/');
. The following rules apply:
- If the supplied uri string is empty no instance will be returned, but
null
instead. - If the supplied uri string is not a valid URI a
stubbles\peer\MalformedUriException
will be thrown. - For all other cases, an instance of
stubbles\peer\Uri
is returned.
In order for a uri string to be a valid URI it must adhere to the specification laid out in RFC 3986.
Please note that hostnames will be normalized, which means if the given hostname is e.g. eXAMple.net, it will be normalized to example.net and always returned in normalized form.
For the methods, the following rules apply:
-
hasDnsRecord()
returnsfalse
if the URI does not contain a host. -
hasDnsRecord()
always returns true for localhost, 127.0.0.1 and [::1]. -
hasDefaultPort()
always returns false. This method is meant for child classed which provide additional methods for certain protocols.
URI instances can only be changed regarding their URI parameters. It is not possible to change the scheme, host, user, password, port, or fragment of the URI.