October\Rain\Router\Router

Source: ~/vendor/october/rain/src/Router/Router.php

URL Router

Used in October CMS for managing page routes.

Public properties

public static string $defaultValue

Value to use when a required parameter is not specified

Protected properties

protected array $routeMap

A list of specified routes

protected October\Rain\Router\Rule $matchedRouteRule

A referred to the matched router rule

protected array $parameters

A list of parameters names and values extracted from the URL pattern and URL string

Public methods

public 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.

public array getRouteMap()

Returns the active list of router rule objects

public array match(string $url)

Match given URL string

Parameters
  • string $url - Request URL to match for

public October\Rain\Router\Rule matchedRoute()

Returns the matched route rule name.

public $this reset()

Clears all existing routes

public void route($name, $route)

Registers a new route rule

Parameters
  • $name
  • $route

public void sortRules()

Sorts all the routing rules by static segments, then dynamic

public string url(string $name, array $parameters=array())

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.

public string urlFromPattern(string $pattern, array $parameters=array())

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.