URL
URL
URL utility class.
class URLThis class provides a number of utility functions for working with URLs.
Methods
base64Encode
Encodes data to a Base64 URL-safe string.
public base64Encode(string $data): stringReturns: string
This function encodes the given data using Base64 encoding and then makes the encoded string URL-safe by replacing '+' with '-' and '/' with '_'. It also removes any trailing '=' characters.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | string | the data to be encoded |
base64Decode
Decodes a base64 URL encoded string.
public base64Decode(string $data): stringReturns: string
This function takes a base64 URL encoded string and decodes it back to its original form. It replaces URL-safe characters ('-' and '_') with standard base64 characters ('+' and '/'), and pads the string with '=' characters to ensure its length is a multiple of 4.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | string | the base64 URL encoded string to decode |
base64DecodeStrict
Decodes unpadded base64url (RFC 4648 section 5), rejecting anything that isn't exactly what
public base64DecodeStrict(string $data): ?stringReturns: string
Hazaar\Util\URL::base64Encode produces.
Unlike Hazaar\Util\URL::base64Decode, which is lenient, this refuses padding, characters outside the base64url alphabet (including +, / and whitespace), impossible lengths, and encodings with stray bits in the last character. Use it for values from untrusted clients, such as WebAuthn credential IDs and challenges, where two different strings must never decode to the same bytes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | string |
build
Build a correctly formatted URL from argument list.
public build(string $scheme = 'http', string $host = 'localhost', ?int $port, ?string $user, ?string $pass, ?string $path, array $query, ?string $fragment): stringReturns: string
This function will build a correctly formatted HTTP compliant URL using a list of parameters. If any of the parameters are null then they will be omitted from the formatted output, including any extra values.
For example, you can specify a username and a password which will be formatted as username:password@. However if you omit the password you will simply get username@.
Parameters
| Parameter | Type | Description |
|---|---|---|
$scheme | string | The protocol to use. Usually http or https. |
$host | string | Hostname |
$port | int | (optional) Port |
$user | string | (optional) Username |
$pass | string | (optional) User password. If set, a username is required. |
$path | string | (optional) Path suffix |
$query | array | (optional) Array of parameters to send. ie: the stuff after the '?'. Uses http_build_query to generate string. |
$fragment | string | (optional) Anything to go after the '#' |
Generated by Hazaar API Doc Generator on Sun, 08 Nov 2026 03:36:15 +0000