October\Rain\Router\Router

Overview

Router used in October CMS for managing page routes.


Public Properties

public static string $defaultValue

defaultValue to use when a required parameter is not specified

Protected Properties

protected array $routeMap

routeMap is a list of specified routes

protected October\Rain\Router\Rule $matchedRouteRule

matchedRouteRule reference

protected array $parameters

parameters with names and values extracted from the URL pattern and URL string


Public Methods

public fromArray()

public fromArray($routes): void

fromArray loads routes from an array.

public getParameters()

public getParameters(): 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 getRouteMap()

public getRouteMap(): array 

getRouteMap returns the active list of router rule objects

public match()

public match(string $url): bool 

match given URL string

public matchedRoute()

public matchedRoute(): October\Rain\Router\Rule 

matchedRoute returns the matched route rule name.

public reset()

public reset(): $this 

reset clears all existing routes

public route()

public route($name, $route): void

route registers a new route rule

public sortRules()

public sortRules(): void 

sortRules sorts all the routing rules by static segments (long to short), then dynamic segments (short to long), then wild segments (at end).

public toArray()

public toArray(): array 

toArray converts the rules to an array.

public url()

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

url builds a URL together by matching route name and supplied parameters

public urlFromPattern()

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

urlFromPattern builds a URL together by matching route pattern and supplied parameters