Documentation

Uri

Interfaces, Classes and Traits

InvalidUriException
Invalid Uri.
Version
This class contains the version number for this package.

Table of Contents

resolve()  : string
Resolves relative urls, like a browser would.
normalize()  : string
Takes a URI or partial URI as its argument, and normalizes it.
parse()  : array<string, string>
Parses a URI and returns its individual components.
build()  : string
This function takes the components returned from PHP's parse_url, and uses it to generate a new uri.
split()  : array<int, mixed>
Returns the 'dirname' and 'basename' for a path.
_parse_fallback()  : array<string, mixed>
This function is another implementation of parse_url, except this one is fully written in PHP.

Functions

resolve()

Resolves relative urls, like a browser would.

resolve(string $basePath, string $newPath) : string

This function takes a basePath, which itself may also be relative, and then applies the relative path on top of it.

Parameters
$basePath : string
$newPath : string
Tags
throws
InvalidUriException
Return values
string

normalize()

Takes a URI or partial URI as its argument, and normalizes it.

normalize(string $uri) : string

After normalizing a URI, you can safely compare it to other URIs. This function will for instance convert a %7E into a tilde, according to rfc3986.

It will also change a %3a into a %3A.

Parameters
$uri : string
Tags
throws
InvalidUriException
Return values
string

parse()

Parses a URI and returns its individual components.

parse(string $uri) : array<string, string>

This method largely behaves the same as PHP's parse_url, except that it will return an array with all the array keys, including the ones that are not set by parse_url, which makes it a bit easier to work with.

Unlike PHP's parse_url, it will also convert any non-ascii characters to percent-encoded strings. PHP's parse_url corrupts these characters on OS X.

Parameters
$uri : string
Tags
throws
InvalidUriException
Return values
array<string, string>

build()

This function takes the components returned from PHP's parse_url, and uses it to generate a new uri.

build(array<string, string> $parts) : string
Parameters
$parts : array<string, string>
Return values
string

split()

Returns the 'dirname' and 'basename' for a path.

split(string $path) : array<int, mixed>

The reason there is a custom function for this purpose, is because basename() is locale aware (behaviour changes if C locale or a UTF-8 locale is used) and we need a method that just operates on UTF-8 characters.

In addition basename and dirname are platform aware, and will treat backslash () as a directory separator on windows.

This method returns the 2 components as an array.

If there is no dirname, it will return an empty string. Any / appearing at the end of the string is stripped off.

Parameters
$path : string
Return values
array<int, mixed>

_parse_fallback()

This function is another implementation of parse_url, except this one is fully written in PHP.

_parse_fallback(string $uri) : array<string, mixed>

The reason is that the PHP bug team is not willing to admit that there are bugs in the parse_url implementation.

This function is only called if the main parse method fails. It's pretty crude and probably slow, so the original parse_url is usually preferred.

Parameters
$uri : string
Tags
throws
InvalidUriException
Return values
array<string, mixed>

Search results