Documentation

Url
in package

Helper functions for working with URLs.

Table of Contents

Methods

addSocialDomain()  : string
Add a domain to provided social link, if it doesn't have one
addUrlScheme()  : string
Add a scheme (e.g. 'http://') to a URL which doesn't have one
base()  : string
Base URL, with or without the index page.
canonical()  : string
Return HTML for canonical URLs
checkRedirect()  : bool
Checks the provided argument is a valid redirect URL to the local site
current()  : string
Fetches the current URI.
file()  : string
Return the URL to a file. Absolute filenames and relative filenames are allowed.
merge()  : string
Merges an array of arguments with the current URI and query string to overload, instead of replace, the current query string.
redirect()  : never
Sends a page redirect header and runs the system.redirect Event.
site()  : string
Fetches an absolute site URL based on a URI segment.
withoutArgs()  : string
Removes one or more arguments from the current URL, returning a URL which can have arguments appended to it Multiple arguments can be specified
withParams()  : string
Appends query string parameter(s) to a URL.

Methods

addSocialDomain()

Add a domain to provided social link, if it doesn't have one

public static addSocialDomain(string $social_link, string $domain) : string
Parameters
$social_link : string

Social link, e.g. 'https://instagram.com/kbtestbot3000' or 'kbtestbot3000'

$domain : string

, e.g. 'instagram.com'

Return values
string —

Social link with domain, e.g. 'https://instagram.com/kbtestbot3000'

addUrlScheme()

Add a scheme (e.g. 'http://') to a URL which doesn't have one

public static addUrlScheme(string $url) : string
Parameters
$url : string

May or may not contain a scheme

Return values
string —

URL Always contains a scheme

base()

Base URL, with or without the index page.

public static base([bool $index = false ][, string|bool $protocol = false ]) : string

If protocol is specified, a full URL including the domain will be used otherwise only the root path will be used

If a subsite-section has a defined URL prefix, it will be added to the URL automatically

Parameters
$index : bool = false

include the index page

$protocol : string|bool = false

non-default protocol

Return values
string

canonical()

Return HTML for canonical URLs

public static canonical(string $canonical_url) : string
Parameters
$canonical_url : string
Return values
string —

HMTL

checkRedirect()

Checks the provided argument is a valid redirect URL to the local site

public static checkRedirect(string $url[, bool $allow_querysting = false ]) : bool

This is designed to prevent redirects to other domains, bad pages, etc

Parameters
$url : string
$allow_querysting : bool = false

If true, allow querystrings too

Return values
bool

current()

Fetches the current URI.

public static current([bool $qs = false ]) : string
Parameters
$qs : bool = false

include the query string

Return values
string

file()

Return the URL to a file. Absolute filenames and relative filenames are allowed.

public static file(string $file[, bool $index = false ]) : string
Parameters
$file : string

filename

$index : bool = false

include the index page

Return values
string

merge()

Merges an array of arguments with the current URI and query string to overload, instead of replace, the current query string.

public static merge(array<string|int, mixed> $arguments) : string
Parameters
$arguments : array<string|int, mixed>

associative array of arguments

Return values
string

redirect()

Sends a page redirect header and runs the system.redirect Event.

public static redirect([string|array<string|int, string> $uri = '' ][, string|int $method = '302' ]) : never
Parameters
$uri : string|array<string|int, string> = ''

site URI or URL to redirect to, or array of strings if method is 300

$method : string|int = '302'

HTTP method of redirect

Tags
throws
LogicException
Return values
never

site()

Fetches an absolute site URL based on a URI segment.

public static site([string $uri = '' ][, string|bool $protocol = false ]) : string
Parameters
$uri : string = ''

site URI to convert

$protocol : string|bool = false

non-default protocol

Return values
string

withoutArgs()

Removes one or more arguments from the current URL, returning a URL which can have arguments appended to it Multiple arguments can be specified

public static withoutArgs(mixed ...$args) : string

If the current URL is: /search?q=test&category=general and the function call is: Url::withoutArgs('q') the resulting URL will be: /search?category=general&

Use rtrim($url, '&?') if you do not desire the trailing ? or &

Parameters
$args : mixed
Return values
string

withParams()

Appends query string parameter(s) to a URL.

public static withParams(string $url, array<string|int, mixed> $params) : string

Supports URLs that already contain query string parameters, and those that do not.

Parameters
$url : string
$params : array<string|int, mixed>
Return values
string
On this page

Search results