URL
URL
- Full name:
\Hazaar\Application\URL
- This class implements:
\JsonSerializable
Properties
path
public string $path
params
public array $params
hash
public ?string $hash
basePath
public ?string $basePath
baseURL
public static ?string $baseURL
- This property is static.
rewriteURL
public static bool $rewriteURL
- This property is static.
aliases
public static string[] $aliases
- This property is static.
encoded
private bool $encoded
Methods
__construct
public __construct(): mixed
__toString
Returns the string representation of the Url object.
public __toString(): string
Return Value:
the string representation of the Url object
initialise
Initializes the URL class with the provided configuration.
public static initialise(\Hazaar\Map $config): void
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$config | \Hazaar\Map | the configuration object containing the base URL, rewrite URL, and default controller |
toString
Write the URL as a string.
public toString(null|array $values = null): string
This method optionally takes an array to use to filter any placeholder parameters. Parameters support special placholder values that are prefixed with a '$', such as $name. The actual value is then taken from the array supplied to this method and replaced in the output. This allows a single URL object to be used multiple times and it's parameters changed
Example:
$url = new \Hazaar\Application\Url('controller', 'action', ['id' => '$id']);
echo $url->toString(['id' => 1234]);
This will output something like:
http://localhost/controller/action?id=1234
Parameters:
Parameter | Type | Description |
---|---|---|
$values | null|array | override the default params with parameters in this array |
Return Value:
the resulting URL based on the constructor arguments
setParams
Set the HTTP request parameters on the URL.
public setParams(array $params, bool $merge = false): void
Parameters:
Parameter | Type | Description |
---|---|---|
$params | array | |
$merge | bool |
encode
Toggle encoding of the URL.
public encode(bool $encode = true): self
This will enable a feature that will encode the URL with a serialised base64 parameter list so that the path and parameters are obscured.
This is NOT a security feature and merely obscures the exact destination of the URL using standard reversible encoding functions that "normal" people won't understand. It can also make your URL look a bit 'tidier' or 'more professional' by making the parameters look weird. 😉
Parameters:
Parameter | Type | Description |
---|---|---|
$encode | bool | Boolean to enable/disable encoding. Defaults to TRUE. |
getOrigin
Retrieves the origin of the URL.
public getOrigin(): string
This method extracts the origin from the rendered URL by using a regular expression pattern. The origin is defined as the protocol and domain of the URL.
Return Value:
the origin of the URL
jsonSerialize
Returns the URL as a JSON serialized string.
public jsonSerialize(): mixed
Return Value:
the JSON serialized string representation of the URL
renderObject
Write the URL as a string.
private renderObject(array $params = null, bool $encode = false): string
Parameters:
Parameter | Type | Description |
---|---|---|
$params | array | override the default params with parameters in this array |
$encode | bool | encode the URL as a Hazaar MVC encoded query string URL |
Return Value:
the resulting URL based on the constructor arguments
Automatically generated on 2024-11-14