URL
in package
Helps build URLs which match the site's URL configuration.
Tags
Table of Contents
Constants
- URL_EXCLUDE_CHARS = [ '?', '&', '/', // Encoded slashes cause issues with Apache: https://stackoverflow.com/q/9206835/4833737 '#', '.', ]
Methods
- build() : string
- Returns a URL in the correct format (friendly or not).
- buildAssetPath() : string
- Build an asset path.
- getSelfURL() : string
- Get the server name.
- isExternalURL() : bool
- Is a URL internal or external? Accepts full URL and also just a path.
- replaceAnchorsWithText() : string
- Add target and rel attributes to external links only.
- urlSafe() : string
- Urlencode, but prettier.
- buildFriendly() : string
- Returns a friendly URL.
- buildNonFriendly() : string
- Returns a non-friendly URL.
Constants
URL_EXCLUDE_CHARS
private
mixed
URL_EXCLUDE_CHARS
= [
'?',
'&',
'/',
// Encoded slashes cause issues with Apache: https://stackoverflow.com/q/9206835/4833737
'#',
'.',
]
Methods
build()
Returns a URL in the correct format (friendly or not).
public
static build(string $url[, string $params = '' ][, string|null $force = null ]) : string
Parameters
- $url : string
-
Contains the URL which will be formatted.
- $params : string = ''
-
Contains string with URL parameters.
- $force : string|null = null
-
Determines whether to force a URL type (optional, can be either "friendly" or "non-friendly").
Return values
string —Assembled URL, false on failure.
buildAssetPath()
Build an asset path.
public
static buildAssetPath(string $path) : string
Parameters
- $path : string
-
Contains the asset path relative to the root Nameless directory
Return values
stringgetSelfURL()
Get the server name.
public
static getSelfURL([bool $show_protocol = true ]) : string
Parameters
- $show_protocol : bool = true
-
Whether to show http(s) at front or not.
Return values
string —Compiled URL.
isExternalURL()
Is a URL internal or external? Accepts full URL and also just a path.
public
static isExternalURL(string $url) : bool
Parameters
- $url : string
-
URL/path to check.
Return values
bool —Whether URL is external or not.
replaceAnchorsWithText()
Add target and rel attributes to external links only.
public
static replaceAnchorsWithText(string $data) : string
From https://stackoverflow.com/a/53461987.
Parameters
- $data : string
-
Data to replace.
Return values
string —Replaced string.
urlSafe()
Urlencode, but prettier.
public
static urlSafe(string $text) : string
- Spaces are replaced by dashes
- Cyrillic characters are converted to latin
- Some special characters are removed (see URL::URL_EXCLUDE_CHARS).
Parameters
- $text : string
-
String to URLify
Return values
string —Encoded string
buildFriendly()
Returns a friendly URL.
private
static buildFriendly(string $url, string $params) : string
Internal class use only. All external calls should use build()
.
Parameters
- $url : string
-
Contains the URL which will be formatted
- $params : string
-
URL paramaters to append to end.
Return values
string —Assembled URL.
buildNonFriendly()
Returns a non-friendly URL.
private
static buildNonFriendly(string $url, string $params) : string
Internal class use only. All external calls should use build()
.
Parameters
- $url : string
-
Contains the URL which will be formatted
- $params : string
-
URL paramaters to append to end.
Return values
string —Assembled URL.