Router

URL Router

 class Winter\Storm\Router\Router

Used in Winter CMS for managing page routes.

Properties

public static $defaultValue : string

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.

Returns
array

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

Returns
array

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

Parameters
Property Description
$url
string

Request URL to match for

Returns
bool

public matchedRoute () : Winter\Storm\Router\Rule | false

Returns the matched route rule name.

Returns

The matched rule object. If no rule was matched, returns false.

public reset () : $this

Clears all existing routes

Returns
$this

public route ($name, $route)

Registers a new route rule

Parameters
Property Description
$name
mixed
$route
mixed
Returns
mixed

public sortRules () : void

Sorts all the routing rules by static segments, then dynamic

Returns
void

public url (string $name, array $parameters = []) : string | null

Builds a URL together by matching route name and supplied parameters

Parameters
Property Description
$name
string

Name of the route previously defined.

$parameters
array

Parameter name => value items to fill in for given route.

Returns
string | null

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

Parameters
Property Description
$pattern
string

Route pattern string, eg: /path/to/something/:parameter

$parameters
array

Parameter name => value items to fill in for given route.

Returns
string

Full matched URL as string with given values put in place of named parameters

Copyright © 2024 Winter CMS