Url
in package
An URL container
Tags
Table of Contents
Constants
Properties
- $backend : bool
- $domain : string
- example.com
- $fragment : string
- The fragment (after #) part of the URL
- $frontend : bool
- $langDir : string
- Virtual language directory, like 'de', 'en' or 'en-GB'
- $originUrl : string
- $path : string
- The path and query part of the URL
- $pathPart : string
- The actual path part of the URL Example: The/Special/Module/With/Params
- $port : int
- The port of the URL
- $protocol : string
- http or https
- $state : mixed
- $suggestedAnchor : string
- #anchor
- $suggestedParams : string
- ?a=10&b=foo ?section=x&cmd=y
- $suggestedTargetPath : string
- The/Module index.php The/Special/Module/With/Params
- $systemInternetServiceProtocolPorts : array<string|int, mixed>
- Holds the cache for Url::getSystemPortByServiceName()
- $targetPath : string
- The/Module Found/Path/To/Module The/Special/Module
- $useReverseProxyPorts : bool
Methods
- __construct() : mixed
- Initializes $domain, $protocol, $port and $path.
- __toString() : type
- Returns an absolute link;
- array2params() : string
- Convert array to parameter string.
- encode_amp() : string
- Returns the given string with any ampersands ("&") replaced by "&"
- fromApi() : Url
- Returns the URL object for a command mode command accessed via HTTP(s)
- fromBackend() : Url
- Returns an Url object for a backend section
- fromCapturedRequest() : mixed
- fromDocumentRoot() : Url
- Returns an Url object pointing to the documentRoot of the website
- fromMagic() : self|Url
- This returns an Url object for an absolute or relative url or an Url object
- fromModuleAndCmd() : Url
- Returns an Url object for module, cmd and lang
- fromNode() : Url
- Returns an Url object for node and language
- fromNodeId() : Url
- Returns an Url object for node and language
- fromPage() : Url
- Returns the URL object for a page
- fromPageId() : Url
- Returns the URL object for a page id
- fromRequest() : mixed
- getAnchor() : string
- Get the anchor of the URL
- getDomain() : mixed
- getLangDir() : string
- Returns the virtual language directory for this URL This returns an empty string if virtual language directories are not in use.
- getMode() : mixed
- getParamArray() : array<string|int, mixed>
- getPath() : string
- getPathPart() : string
- getPort() : mixed
- gets port of URL;
- getProtocol() : string
- Get the protocol
- getSuggestedAnchor() : mixed
- getSuggestedParams() : mixed
- getSuggestedTargetPath() : mixed
- getSystemPortByServiceName() : int
- Get port number associated with an Internet service and protocol.
- getTargetPath() : mixed
- isBackend() : bool|null
- isFrontend() : bool|null
- isInternal() : bool
- Checks whether this Url points to a location within this installation
- isRouted() : mixed
- Whether the routing already treated this url
- isVirtualLanguageDirsActive() : bool
- Tells wheter virtual language directories are in use or not This only returns true if there's but one frontend language active
- params2array() : array<string|int, mixed>
- Convert parameter string to array.
- removeAllParams() : mixed
- Remove all params from path
- setAnchor() : mixed
- Set an anchor to the URL
- setDomain() : mixed
- setLangDir() : mixed
- setMode() : mixed
- setParam() : mixed
- Set a single parameter.
- setParams() : mixed
- Set multiple parameters.
- setPath() : mixed
- Update path part of URL
- setPathPart() : mixed
- Set path part of the URL
- setPort() : mixed
- sets port of URL;
- setProtocol() : void
- Set the protocol
- setSuggestedParams() : mixed
- setSuggestedTargetPath() : mixed
- setTargetPath() : mixed
- suggest() : mixed
- sets $this->suggestedParams and $this->suggestedTargetPath
- toString() : type
- Returns an absolute or relative link
- autoAdjustPort() : mixed
- Set enforced port (as set by base configuration) in case Url is a local location ({@see Url::isInternal()}).
- autoAdjustProtocol() : mixed
- Set enforced protocol (as set by base configuration) in case Url is a local location ({@see Url::isInternal()}).
- detectLocation() : mixed
- Tries to find out if this Url is a local frontend or backend location.
- getDefaultPort() : mixed
- gets default port from settings
- addParamsToPath() : mixed
- Add new parameters to path: - Existing parameters (having not an array as value) will be overwritten by the value of the new parameter (having the same key).
- addPassedParams() : mixed
- Add all passed parameters which are skin related.
- splitParamsFromPath() : array<string|int, mixed>
- Split parameters from path.
- writeParamsToPath() : mixed
- Write parameters to path.
Constants
ROUTED
public
mixed
ROUTED
= 2
SUGGESTED
public
mixed
SUGGESTED
= 1
Properties
$backend
protected
bool
$backend
= false
TRUE if Url is a local (Url::isInternal()) backend location.
$domain
example.com
protected
string
$domain
= null
$fragment
The fragment (after #) part of the URL
protected
string
$fragment
= ''
$frontend
protected
bool
$frontend
= false
TRUE if Url is a local (Url::isInternal()) frontend location. Be aware that in case the path part is empty, then this will not be set to TRUE.
$langDir
Virtual language directory, like 'de', 'en' or 'en-GB'
protected
string
$langDir
= ''
$originUrl
protected
string
$originUrl
= ''
The origin string the instance has been instantiated on.
$path
The path and query part of the URL
protected
string
$path
= ''
Examples: The/Module?a=10&b=foo index.php?section=x&cmd=y The/Special/Module/With/Params
$pathPart
The actual path part of the URL Example: The/Special/Module/With/Params
protected
string
$pathPart
= ''
$port
The port of the URL
protected
int
$port
= 0
$protocol
http or https
protected
string
$protocol
= 'http'
Containing the URL protocol
Tags
$state
protected
mixed
$state
= 0
$suggestedAnchor
#anchor
protected
string
$suggestedAnchor
= ''
$suggestedParams
?a=10&b=foo ?section=x&cmd=y
protected
string
$suggestedParams
= ''
$suggestedTargetPath
The/Module index.php The/Special/Module/With/Params
protected
string
$suggestedTargetPath
= ''
$systemInternetServiceProtocolPorts
Holds the cache for Url::getSystemPortByServiceName()
protected
static array<string|int, mixed>
$systemInternetServiceProtocolPorts
= array()
$targetPath
The/Module Found/Path/To/Module The/Special/Module
protected
string
$targetPath
= null
$useReverseProxyPorts
protected
bool
$useReverseProxyPorts
= false
TRUE if the Url shall be enhanced to use the ports of the configured reverse proxy.
Methods
__construct()
Initializes $domain, $protocol, $port and $path.
public
__construct(string $url[, bool $useReverseProxyPorts = false ][, bool $forceLangDirDetection = false ]) : mixed
Parameters
- $url : string
-
http://example.com/Test
- $useReverseProxyPorts : bool = false
-
Indicates if we need to replace ports with those from the base configuration.
- $forceLangDirDetection : bool = false
-
Set to
true
to force the detection of a virtual language dir. If set tofalse
(default), then the detection will only be occur for internal URLs (static::isInternal()) and when the use of virtual language dirs (static::isVirtualLanguageDirsActive()) has been enabled.
__toString()
Returns an absolute link;
public
__toString() : type
Return values
typearray2params()
Convert array to parameter string.
public
static array2params([array<string|int, mixed> $array = array() ]) : string
Parameters
- $array : array<string|int, mixed> = array()
Tags
Return values
stringencode_amp()
Returns the given string with any ampersands ("&") replaced by "&"
public
static encode_amp(string $url) : string
Any "&"s already present in the string won't be changed; no double encoding takes place.
Parameters
- $url : string
-
The URL to be encoded
Return values
string —The URL with ampersands encoded
fromApi()
Returns the URL object for a command mode command accessed via HTTP(s)
public
static fromApi(string $command, array<string|int, mixed> $arguments[, array<string|int, mixed> $parameters = array() ]) : Url
Parameters
- $command : string
-
Command mode command name
- $arguments : array<string|int, mixed>
-
List of non-named arguments
- $parameters : array<string|int, mixed> = array()
-
List of named parameters (key=>value style array)
Return values
Url —Url object for the supplied command name
fromBackend()
Returns an Url object for a backend section
public
static fromBackend(string $componentName[, mixed $cmd = '' ][, int $lang = 0 ][, array<string|int, mixed> $parameters = array() ][, string $protocol = '' ]) : Url
Parameters
- $componentName : string
-
Component name
- $cmd : mixed = ''
- $lang : int = 0
-
(optional) Language to use, default is BACKEND_LANG_ID
- $parameters : array<string|int, mixed> = array()
-
(optional) HTTP GET parameters to append
- $protocol : string = ''
-
(optional) The protocol to use
Return values
Url —Url object for the supplied info
fromCapturedRequest()
public
static fromCapturedRequest(mixed $request, mixed $pathOffset, mixed $get) : mixed
Parameters
- $request : mixed
- $pathOffset : mixed
- $get : mixed
fromDocumentRoot()
Returns an Url object pointing to the documentRoot of the website
public
static fromDocumentRoot([array<string|int, mixed> $arrParameters = array() ][, int $lang = '' ][, string $protocol = '' ]) : Url
Parameters
- $arrParameters : array<string|int, mixed> = array()
-
(optional) URL arguments for the query string.
- $lang : int = ''
-
(optional) Language to use, default is FRONTEND_LANG_ID
- $protocol : string = ''
-
(optional) The protocol to use
Return values
Url —Url object for the documentRoot of the website
fromMagic()
This returns an Url object for an absolute or relative url or an Url object
public
static fromMagic(mixed $url) : self|Url
Parameters
- $url : mixed
-
Url object or absolute or relative url as string
Tags
Return values
self|Url —Url object representing $url
fromModuleAndCmd()
Returns an Url object for module, cmd and lang
public
static fromModuleAndCmd(string $module[, string $cmd = '' ][, int $lang = '' ][, array<string|int, mixed> $parameters = array() ][, string $protocol = '' ][, bool $returnErrorPageOnError = true ]) : Url
Parameters
- $module : string
-
Module name
- $cmd : string = ''
-
(optional) Module command, default is empty string
- $lang : int = ''
-
(optional) Language to use, default is FRONTENT_LANG_ID
- $parameters : array<string|int, mixed> = array()
-
(optional) HTTP GET parameters to append
- $protocol : string = ''
-
(optional) The protocol to use
- $returnErrorPageOnError : bool = true
-
(optional) If set to TRUE, this method will return an URL object that point to the error page of Cloudrexx. Defaults to TRUE.
Tags
Return values
Url —Url object for the supplied module, cmd and lang
fromNode()
Returns an Url object for node and language
public
static fromNode(Node $node[, int $lang = '' ][, array<string|int, mixed> $parameters = array() ][, string $protocol = '' ]) : Url
Parameters
- $node : Node
-
Node to get the Url of
- $lang : int = ''
-
(optional) Language to use, default is FRONTENT_LANG_ID
- $parameters : array<string|int, mixed> = array()
-
(optional) HTTP GET parameters to append
- $protocol : string = ''
-
(optional) The protocol to use
Return values
Url —Url object for the supplied module, cmd and lang
fromNodeId()
Returns an Url object for node and language
public
static fromNodeId(int $nodeId[, int $lang = '' ][, array<string|int, mixed> $parameters = array() ][, string $protocol = '' ]) : Url
Parameters
- $nodeId : int
-
Node id
- $lang : int = ''
-
(optional) Language to use, default is FRONTEND_LANG_ID
- $parameters : array<string|int, mixed> = array()
-
(optional) HTTP GET parameters to append
- $protocol : string = ''
-
(optional) The protocol to use
Tags
Return values
Url —Url object for the supplied module, cmd and lang
fromPage()
Returns the URL object for a page
public
static fromPage(Page $page[, array<string|int, mixed> $parameters = array() ][, string $protocol = '' ]) : Url
Parameters
- $page : Page
-
Page to get the URL to
- $parameters : array<string|int, mixed> = array()
-
(optional) HTTP GET parameters to append
- $protocol : string = ''
-
(optional) The protocol to use
Return values
Url —Url object for the supplied page
fromPageId()
Returns the URL object for a page id
public
static fromPageId(int $pageId[, array<string|int, mixed> $parameters = array() ][, string $protocol = '' ]) : Url
Parameters
- $pageId : int
-
ID of the page you'd like the URL to
- $parameters : array<string|int, mixed> = array()
-
(optional) HTTP GET parameters to append
- $protocol : string = ''
-
(optional) The protocol to use
Return values
Url —Url object for the supplied page id
fromRequest()
public
static fromRequest() : mixed
getAnchor()
Get the anchor of the URL
public
getAnchor() : string
Return values
string —The part after the # in the URL
getDomain()
public
getDomain() : mixed
getLangDir()
Returns the virtual language directory for this URL This returns an empty string if virtual language directories are not in use.
public
getLangDir([bool $fromUrl = false ]) : string
If $fromUrl is set to true and the URL contained a virtual language directory on initialization, this returns the supplied directory even if virtual language directories are not in use.
Parameters
- $fromUrl : bool = false
-
(optional) Return supplied instead of calculated directory if set to true, default false
Return values
string —Virtual language directory
getMode()
public
getMode() : mixed
Use Url::isFrontend() or Url::isBackend() instead.
getParamArray()
public
getParamArray() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getPath()
public
getPath() : string
Tags
Return values
string —Returns the path incl. query part of the URL. Use Url::getPathPart() to only return the actual path part of the URL.
getPathPart()
public
getPathPart() : string
Return values
string —Path part of the URL
getPort()
gets port of URL;
public
getPort() : mixed
getProtocol()
Get the protocol
public
getProtocol() : string
Return values
stringgetSuggestedAnchor()
public
getSuggestedAnchor() : mixed
getSuggestedParams()
public
getSuggestedParams() : mixed
getSuggestedTargetPath()
public
getSuggestedTargetPath() : mixed
getSystemPortByServiceName()
Get port number associated with an Internet service and protocol.
public
static getSystemPortByServiceName(string $service, string $protocol) : int
This method is an alias to getservbyname(), whereas the result will be cached for later usages.
Parameters
- $service : string
-
The Internet service name, as a string.
- $protocol : string
-
Either "tcp" or "udp" (in lowercase).
Return values
int —The Internet port which corresponds to service for the specified protocol as per /etc/services.
getTargetPath()
public
getTargetPath() : mixed
isBackend()
public
isBackend([bool $backend = null ]) : bool|null
Parameters
- $backend : bool = null
-
Set to TRUE to force behavior as if Url was poiting to a local backend location. Or set to FALSE to force the behavior of a non local Url. Note: setting this to true will imply Url::isFrontend(false).
Return values
bool|null —NULL if $backend is set. Otherwise TRUE if Url points to a local backend location or FALSE otherwise.
isFrontend()
public
isFrontend([bool $frontend = null ]) : bool|null
Parameters
- $frontend : bool = null
-
Set to TRUE to force behavior as if Url was poiting to a local frontend location. Or set to FALSE to force the behavior of a non local Url. Note: setting this to true will imply Url::isBackend(false).
Return values
bool|null —NULL if $frontend is set. Otherwise TRUE if Url points to a local frontend location or FALSE otherwise.
isInternal()
Checks whether this Url points to a location within this installation
public
isInternal() : bool
The check works by checking if the domain of the url is a registered domain in the repo of \Cx\Core\Net\Model\Entity\Domain. If for some reason, the domain repo can't be loaded and the check is therefore unable to perform its task, it will return TRUE as fallback.
Return values
bool —True for internal URL, false otherwise. In case the domain repository can't be loaded, the method will always return TRUE.
isRouted()
Whether the routing already treated this url
public
isRouted() : mixed
isVirtualLanguageDirsActive()
Tells wheter virtual language directories are in use or not This only returns true if there's but one frontend language active
public
static isVirtualLanguageDirsActive() : bool
Return values
bool —True if virtual language directories are in use, false otherwise
params2array()
Convert parameter string to array.
public
static params2array([string $params = '' ]) : array<string|int, mixed>
Parameters
- $params : string = ''
Tags
Return values
array<string|int, mixed> —$array
removeAllParams()
Remove all params from path
public
removeAllParams() : mixed
setAnchor()
Set an anchor to the URL
public
setAnchor(string $anchor) : mixed
Parameters
- $anchor : string
-
The part after the # in the URL
setDomain()
public
setDomain(Domain $domain) : mixed
Parameters
- $domain : Domain
setLangDir()
public
setLangDir(mixed $langDir[, mixed $page = null ]) : mixed
Parameters
- $langDir : mixed
- $page : mixed = null
setMode()
public
setMode(mixed $mode) : mixed
Use Url::isFrontend() or Url::isBackend() instead.
Parameters
- $mode : mixed
setParam()
Set a single parameter.
public
setParam(mixed $key, mixed $value) : mixed
Parameters
- $key : mixed
- $value : mixed
Tags
setParams()
Set multiple parameters.
public
setParams(mixed $params) : mixed
Parameters
- $params : mixed
Tags
setPath()
Update path part of URL
public
setPath(string $path[, bool $forceLangDirDetection = false ]) : mixed
Note: $path can be set to anything that follows the domain part of the URL. This also includes the query and fragment part. However, neither setting the query nor the fragment part is properly supported and must therefore not be used and is considered deprecated and will be removed in the future.
Parameters
- $path : string
- $forceLangDirDetection : bool = false
-
Set to
true
to force the detection of a virtual language dir. If set tofalse
(default), then the detection will only be occur for internal URLs (static::isInternal()) and when the use of virtual language dirs (static::isVirtualLanguageDirsActive()) has been enabled.
Tags
setPathPart()
Set path part of the URL
public
setPathPart(string $path) : mixed
This strips of a leading slash from $path and then forwards it to Url::setPath().
Parameters
- $path : string
setPort()
sets port of URL;
public
setPort(mixed $port) : mixed
Parameters
- $port : mixed
setProtocol()
Set the protocol
public
setProtocol(string $protocol) : void
Parameters
- $protocol : string
-
Protocol to set. One of 'https', 'http' or 'file'
Tags
setSuggestedParams()
public
setSuggestedParams(mixed $params) : mixed
Parameters
- $params : mixed
setSuggestedTargetPath()
public
setSuggestedTargetPath(mixed $path) : mixed
Parameters
- $path : mixed
setTargetPath()
public
setTargetPath(mixed $path) : mixed
Parameters
- $path : mixed
suggest()
sets $this->suggestedParams and $this->suggestedTargetPath
public
suggest() : mixed
toString()
Returns an absolute or relative link
public
toString([bool $absolute = true ][, mixed $forcePort = false ]) : type
Parameters
- $absolute : bool = true
-
(optional) set to false to return a relative URL
- $forcePort : mixed = false
Return values
typeautoAdjustPort()
Set enforced port (as set by base configuration) in case Url is a local location ({@see Url::isInternal()}).
protected
autoAdjustPort() : mixed
autoAdjustProtocol()
Set enforced protocol (as set by base configuration) in case Url is a local location ({@see Url::isInternal()}).
protected
autoAdjustProtocol() : mixed
In case it is a local location then this method will call Url::autoAdjustPort() to ensure the Url uses the correct port as defined by the base configuration.
detectLocation()
Tries to find out if this Url is a local frontend or backend location.
protected
detectLocation() : mixed
In case it is a local location then this method will call Url::autoAdjustProtocol() to ensure the Url uses the correct protocol as defined by the base configuration.
getDefaultPort()
gets default port from settings
protected
getDefaultPort() : mixed
addParamsToPath()
Add new parameters to path: - Existing parameters (having not an array as value) will be overwritten by the value of the new parameter (having the same key).
private
addParamsToPath(array<string|int, mixed> $paramsToAdd) : mixed
- Existing parameters (having an array as value) will be merged with the value of the new parameter.
- New parameters will simply be added.
Parameters
- $paramsToAdd : array<string|int, mixed>
Tags
addPassedParams()
Add all passed parameters which are skin related.
private
addPassedParams() : mixed
Tags
splitParamsFromPath()
Split parameters from path.
private
splitParamsFromPath() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —$params
writeParamsToPath()
Write parameters to path.
private
writeParamsToPath(array<string|int, mixed> $params) : mixed
Parameters
- $params : array<string|int, mixed>