class Router

URL Router Used in managing page routes.

Adapted from october\rain\router\Router

Properties

static string $defaultValue
protected array $routeMap
protected Rule $matchedRouteRule
protected array $parameters

Methods

route($name, $route)

Registers a new route rule

bool
match(string $url)

Match given URL string

string
url(string $name, array $parameters = [])

Builds a URL together by matching route name and supplied parameters

string
urlFromPattern(string $pattern, array $parameters = [])

Builds a URL together by matching route pattern and supplied parameters

array
getRouteMap()

Returns the active list of router rule objects

array
getParameters()

Returns a list of parameters specified in the requested page URL.

matchedRoute()

Returns the matched route rule name.

reset()

Clears all existing routes

void
sortRules()

Sorts all the routing rules by static segments, then dynamic

Details

at line 38
route($name, $route)

Registers a new route rule

Parameters

$name
$route

at line 49
bool match(string $url)

Match given URL string

Parameters

string $url

Request URL to match for

Return Value

bool

at line 99
string url(string $name, array $parameters = [])

Builds a URL together by matching route name and supplied parameters

Parameters

string $name

Name of the route previously defined.

array $parameters

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

Return Value

string

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

at line 119
string urlFromPattern(string $pattern, array $parameters = [])

Builds a URL together by matching route pattern and supplied parameters

Parameters

string $pattern

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

array $parameters

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

Return Value

string

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

at line 211
array getRouteMap()

Returns the active list of router rule objects

Return Value

array

An associative array with keys matching the route rule names and values matching the router rule object.

at line 223
array getParameters()

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.

Return Value

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.

at line 232
Rule matchedRoute()

Returns the matched route rule name.

Return Value

Rule

The matched rule object.

at line 245
Router reset()

Clears all existing routes

Return Value

Router

at line 256
void sortRules()

Sorts all the routing rules by static segments, then dynamic

Return Value

void