Router
URL Router
class Winter\Storm\Router\Router
Used in Winter CMS for managing page routes.
Properties
public
static
$defaultValue
:
string
= "default"
Value to use when a required parameter is not specified
protected $matchedRouteRule : Winter\Storm\Router\Rule | null
A referred to the matched router rule
protected
$parameters
:
array
= []
A list of parameters names and values extracted from the URL pattern and URL string
protected
$routeMap
:
array
= []
A list of specified routes
Methods
public getParameters () : array
Returns a list of parameters specified in the requested page URL.
For example, if the URL pattern was /blog/post/:id and the actual URL was /blog/post/10, the $parameters['id'] element would be 10.
An associative array with keys matching the parameter names specified in the URL pattern and values matching the corresponding segments of the actual requested URL.
public getRouteMap () : array
Returns the active list of router rule objects
An associative array with keys matching the route rule names and values matching the router rule object.
public match (string $url) : bool
Match given URL string
Property | Type | Description |
---|---|---|
$url | string |
string
Request URL to match for |
public matchedRoute () : Winter\Storm\Router\Rule | false
Returns the matched route rule name.
The matched rule object. If no rule was matched, returns false
.
public reset () : $this
Clears all existing routes
public route ($name, $route)
Registers a new route rule
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
$route | mixed |
mixed
|
public sortRules () : void
Sorts all the routing rules by static segments, then dynamic
public
url (string $name, array $parameters = []
)
: string | null
Builds a URL together by matching route name and supplied parameters
Property | Type | Description |
---|---|---|
$name | string |
string
Name of the route previously defined. |
$parameters | array |
array
Parameter name => value items to fill in for given route. |
Full matched URL as string with given values put in place of named parameters. Returns null
if no route map is specified.
public
urlFromPattern (string $pattern, array $parameters = []
)
: string
Builds a URL together by matching route pattern and supplied parameters
Property | Type | Description |
---|---|---|
$pattern | string |
string
Route pattern string, eg: /path/to/something/:parameter |
$parameters | array |
array
Parameter name => value items to fill in for given route. |
Full matched URL as string with given values put in place of named parameters