Library
Class

Library\Router

class Router implements RouterInterface

The global router class

Methods

__construct(string $route = null, array $routes_table = array(), array $arguments_table = array(), array $matchers_table = array())

Construction

Collection getCollection(array $collection)

Get a collection object if it was not

Router setUrl(string $url)

Set the current URL

string getUrl()

Get the current URL

Router setRoute(string $route)

Set the current route

string getRoute()

Get the current route

Router setRouteParsed(array $infos)

Set the current route parsed infos

array getRouteParsed()

Get the current route parsed infos

Router setRoutes(Collection $collection)

Set the routes collection

Collection getRoutes()

Get the routes collection

Router setArgumentsMap(Collection $collection)

Set the arguments correspondances table like ( true arg in URL => true arg name in the app )

Collection getArgumentsMap()

Get the arguments table

Router setMatchers(Collection $collection)

Set a collection of masks to parse and match a route URL

Collection getMatchers()

Get the route matcher

bool routeExists(string $route)

Check if a route exists

string generateUrl(mixed $route_infos, string $base_uri = null, string $hash = null, string $separator = '&')

Build a new route URL

false|mixed matchUrl(mixed $pathinfo)

Test if an URL has a corresponding route

Router distribute()

Actually dispatch the current route

void forward(mixed $pathinfo, string $hash = null)

Forward the application to a new route (no HTTP redirect)

void redirect(mixed $pathinfo, string $hash = null)

Make a redirection to a new route (HTTP redirect)

static string urlEncode(string $str = null, bool $keep_mask = true)

Special 'urlencode' function to only encode strings and let any "%s" mask not encoded

Details

at line 78
public __construct(string $route = null, array $routes_table = array(), array $arguments_table = array(), array $matchers_table = array())

Construction

Parameters

string $route
array $routes_table
array $arguments_table
array $matchers_table

at line 101
public Collection getCollection(array $collection)

Get a collection object if it was not

Parameters

array $collection

Return Value

Collection

at line 120
public Router setUrl(string $url)

Set the current URL

Parameters

string $url

Return Value

Router

at line 131
public string getUrl()

Get the current URL

Return Value

string

at line 142
public Router setRoute(string $route)

Set the current route

Parameters

string $route

Return Value

Router

at line 153
public string getRoute()

Get the current route

Return Value

string

at line 164
public Router setRouteParsed(array $infos)

Set the current route parsed infos

Parameters

array $infos

Return Value

Router

at line 175
public array getRouteParsed()

Get the current route parsed infos

Return Value

array

at line 186
public Router setRoutes(Collection $collection)

Set the routes collection

Parameters

Collection $collection

Return Value

Router

at line 197
public Collection getRoutes()

Get the routes collection

Return Value

Collection

at line 208
public Router setArgumentsMap(Collection $collection)

Set the arguments correspondances table like ( true arg in URL => true arg name in the app )

Parameters

Collection $collection

Return Value

Router

at line 219
public Collection getArgumentsMap()

Get the arguments table

Return Value

Collection

at line 230
public Router setMatchers(Collection $collection)

Set a collection of masks to parse and match a route URL

Parameters

Collection $collection

Return Value

Router

at line 241
public Collection getMatchers()

Get the route matcher

Return Value

Collection

at line 252
public bool routeExists(string $route)

Check if a route exists

Parameters

string $route The route to test

Return Value

bool

at line 317
public string generateUrl(mixed $route_infos, string $base_uri = null, string $hash = null, string $separator = '&')

Build a new route URL

The class will pass arguments values to any $this->toUrlParam($value) method for the parameter named param.

Parameters

mixed $route_infos The information about the route to analyze, can be a string route or an array of arguments like param => value
string $base_uri The URI to add the new route to
string $hash A hash tag to add to the generated URL
string $separator The argument/value separator (default is escaped ampersand : '&')

Return Value

string The application valid URL for the route

at line 354
public false|mixed matchUrl(mixed $pathinfo)

Test if an URL has a corresponding route

Parameters

mixed $pathinfo

Return Value

false|mixed

at line 369
public Router distribute()

Actually dispatch the current route

Return Value

Router

Exceptions

RuntimeException if no route has been found

at line 392
public void forward(mixed $pathinfo, string $hash = null)

Forward the application to a new route (no HTTP redirect)

Parameters

mixed $pathinfo The path information to forward to
string $hash A hash tag to add to the generated URL

Return Value

void

at line 403
public void redirect(mixed $pathinfo, string $hash = null)

Make a redirection to a new route (HTTP redirect)

Parameters

mixed $pathinfo The path information to redirect to
string $hash A hash tag to add to the generated URL

Return Value

void

at line 430
static public string urlEncode(string $str = null, bool $keep_mask = true)

Special 'urlencode' function to only encode strings and let any "%s" mask not encoded

Parameters

string $str The URL or argument to encode
bool $keep_mask

Return Value

string The encoded URL if so