Router
Class to create and parse routes
| since |
1.5 |
|---|---|
| package |
Joomla CMS |
Methods
attachBuildRule
Attach a build rule
attachBuildRule( Warning: Array to string conversion in /opt/phpdoc/vendor/twig/twig/src/Extension/CoreExtension.php on line 841 |Array callback, stage = self::PROCESS_DURING) :
| since |
1.5 |
|---|
Arguments
- callback
callableThe function to be called- stage
stringThe stage of the build process that this should be added to. Possible values: 'preprocess', '' for the main build process, 'postprocess'
Response
void
attachParseRule
Attach a parse rule
attachParseRule( Warning: Array to string conversion in /opt/phpdoc/vendor/twig/twig/src/Extension/CoreExtension.php on line 841 |Array callback, stage = self::PROCESS_DURING) :
| since |
1.5 |
|---|
Arguments
- callback
callableThe function to be called.- stage
stringThe stage of the parse process that this should be added to. Possible values: 'preprocess', '' for the main parse process, 'postprocess'
Response
void
build
Function to convert an internal URI to a route
build(string|array|\Joomla\CMS\Uri\Uri url) : \Joomla\CMS\Uri\Uri
createUri
Create a uri based on a full or partial URL string
createUri( url) : \Joomla\CMS\Uri\Uri
detachRule
Remove a rule
detachRule( type, Warning: Array to string conversion in /opt/phpdoc/vendor/twig/twig/src/Extension/CoreExtension.php on line 841 |Array rule, stage = self::PROCESS_DURING) :
| since |
4.0.0 |
|---|---|
| throws |
|
Arguments
- type
stringType of rule to remove (parse or build)- rule
callableThe rule to be removed.- stage
stringThe stage of the parse process that this should be added to. Possible values: 'preprocess', '' for the main parse process, 'postprocess'
Response
boolWas a rule removed?
getInstance
Returns the global Router object, only creating it if it doesn't already exist.
getInstance( client, mixed||string|int options = []) : \Joomla\CMS\Router\Router
| since |
1.5 |
|---|---|
| throws |
|
| deprecated |
4.0 will be removed in 6.0 Inject the router or load it from the dependency injection container Example: Factory::getContainer()->get(SiteRouter::class); |
Arguments
- client
stringThe name of the client- options
array<string|int, mixed>An associative array of options
Response
RouterA Router object.
getRules
Get all currently attached rules
getRules() : mixed||string|int
| since |
4.0.0 |
|---|
Response
array<string|int, mixed>All currently attached rules in an array
getVar
Get a router variable
getVar( key) :
| since |
1.5 |
|---|
Arguments
- key
stringThe name of the variable
Response
mixedValue of the variable
getVars
Get the router variable array
getVars() : mixed||string|int
| since |
1.5 |
|---|
Response
array<string|int, mixed>An associative array of router variables
isTainted
Return if the last parsed URL was tainted.
isTainted() :
| since |
5.3.0 |
|---|
Response
bool
parse
Function to convert a route to an internal URI
parse(\Joomla\CMS\Uri\Uri &uri, setVars = false) : mixed||string|int
| since |
1.5 |
|---|---|
| throws |
|
Arguments
- uri
UriThe uri.- setVars
boolSet the parsed data in the internal storage for current-request-URLs
Response
array<string|int, mixed>
processBuildRules
Process the build uri query data based on custom defined rules
processBuildRules(\Joomla\CMS\Uri\Uri &uri, stage = self::PROCESS_DURING) :
| since |
3.2 |
|---|
Arguments
- uri
UriThe URI- stage
stringThe stage that should be processed. Possible values: 'preprocess', 'postprocess' and '' for the main build stage
Response
void
processParseRules
Process the parsed router variables based on custom defined rules
processParseRules(\Joomla\CMS\Uri\Uri &uri, stage = self::PROCESS_DURING) :
| since |
3.2 |
|---|
Arguments
- uri
UriThe URI to parse- stage
stringThe stage that should be processed. Possible values: 'preprocess', 'postprocess' and '' for the main parse stage
Response
void
setTainted
Set the currently parsed URL as tainted If a URL can be parsed, but not all parts were correct, (for example an ID was found, but the alias was wrong) the parsing can be marked as tainted. When the URL is marked as tainted, the router has to have returned correct data to create the right URL afterwards and can later do additional processing, like redirecting to the right URL.
setTainted() :
If the URL is demonstrably wrong, it should still throw a 404 exception.
| since |
5.3.0 |
|---|
Response
mixed
setVar
Set a router variable, creating it if it doesn't exist
setVar( key, value, create = true) :
| since |
1.5 |
|---|
Arguments
- key
stringThe name of the variable- value
mixedThe value of the variable- create
boolIf True, the variable will be created if it doesn't exist yet
Response
void
setVars
Set the router variable array
setVars(mixed||string|int vars = [], merge = true) :
| since |
1.5 |
|---|
Arguments
- vars
array<string|int, mixed>An associative array with variables- merge
boolIf True, the array will be merged instead of overwritten
Response
void
Constants
PROCESS_BEFORE
Mask for the before process stage
| Value | 'preprocess' |
|---|---|
| since |
3.4 |
Type(s)
string
PROCESS_DURING
Mask for the during process stage
| Value | '' |
|---|---|
| since |
3.4 |
Type(s)
string
PROCESS_AFTER
Mask for the after process stage
| Value | 'postprocess' |
|---|---|
| since |
3.4 |
Type(s)
string
Properties
vars
An array of variables
| since |
1.5 |
|---|
Type(s)
array<string|int, mixed>
rules
An array of rules
| since |
1.5 |
|---|
Type(s)
array<string|int, mixed>
cache
Caching of processed URIs
| since |
3.3 |
|---|
Type(s)
array<string|int, mixed>
tainted
Flag to mark the last parsed URL as tainted If a URL could be read, but has errors, this flag can be set to true to mark the URL as erroneous.
| since |
5.3.0 |
|---|
Type(s)
bool