Router

Implements RouterInterface, Serializable

A path router.

since

1.0

package

Joomla Framework

Methods

__construct

Constructor.

__construct(\Joomla\Router\Route[]|array[] routes = []) : mixed
since

1.0

Arguments

routes

\Joomla\Router\Route[]|array[]A list of route maps or Route objects to add to the router.

Response

mixed

__serialize

Serialize the router.

__serialize() : array
since

2.0.0

Response

arrayThe data to be serialized

__unserialize

Unserialize the router.

__unserialize(array data) : void
since

2.0.0

Arguments

data

arrayThe serialized router.

addRoute

Add a route to the router.

addRoute(\Joomla\Router\Route route) : $this
since

2.0.0

Arguments

route

\Joomla\Router\RouteThe route definition

Response

$this

addRoutes

Add an array of route maps or objects to the router.

addRoutes(\Joomla\Router\Route[]|array[] routes) : $this
since

2.0.0

throws

\UnexpectedValueExceptionIf missing the pattern or controller keys from the mapping array.

Arguments

routes

\Joomla\Router\Route[]|array[]A list of route maps or Route objects to add to the router.

Response

$this

all

Add a route to the router that accepts all request methods.

all(string pattern, mixed controller, array rules = [], array defaults = []) : $this
since

2.0.0

Arguments

pattern

stringThe route pattern to use for matching.

controller

mixedThe controller to map to the given pattern.

rules

arrayAn array of regex rules keyed using the route variables.

defaults

arrayAn array of default values that are used when the URL is matched.

Response

$this

delete

Add a DELETE route to the router.

delete(string pattern, mixed controller, array rules = [], array defaults = []) : $this
since

2.0.0

Arguments

pattern

stringThe route pattern to use for matching.

controller

mixedThe controller to map to the given pattern.

rules

arrayAn array of regex rules keyed using the route variables.

defaults

arrayAn array of default values that are used when the URL is matched.

Response

$this

get

Add a GET route to the router.

get(string pattern, mixed controller, array rules = [], array defaults = []) : $this
since

2.0.0

Arguments

pattern

stringThe route pattern to use for matching.

controller

mixedThe controller to map to the given pattern.

rules

arrayAn array of regex rules keyed using the route variables.

defaults

arrayAn array of default values that are used when the URL is matched.

Response

$this

getRoutes

Get the routes registered with this router.

getRoutes() : \Joomla\Router\Route[]
since

2.0.0

Response

\Joomla\Router\Route[]

head

Add a HEAD route to the router.

head(string pattern, mixed controller, array rules = [], array defaults = []) : $this
since

2.0.0

Arguments

pattern

stringThe route pattern to use for matching.

controller

mixedThe controller to map to the given pattern.

rules

arrayAn array of regex rules keyed using the route variables.

defaults

arrayAn array of default values that are used when the URL is matched.

Response

$this

options

Add a OPTIONS route to the router.

options(string pattern, mixed controller, array rules = [], array defaults = []) : $this
since

2.0.0

Arguments

pattern

stringThe route pattern to use for matching.

controller

mixedThe controller to map to the given pattern.

rules

arrayAn array of regex rules keyed using the route variables.

defaults

arrayAn array of default values that are used when the URL is matched.

Response

$this

parseRoute

Parse the given route and return the information about the route, including the controller assigned to the route.

parseRoute(string route, string method = 'GET') : \Joomla\Router\ResolvedRoute
since

1.0

throws

\Joomla\Router\Exception\MethodNotAllowedExceptionif the route was found but does not support the request method

\Joomla\Router\Exception\RouteNotFoundExceptionif the route was not found

Arguments

route

stringThe route string for which to find and execute a controller.

method

stringRequest method to match, should be a valid HTTP request method.

Response

\Joomla\Router\ResolvedRoute

patch

Add a PATCH route to the router.

patch(string pattern, mixed controller, array rules = [], array defaults = []) : $this
since

2.0.0

Arguments

pattern

stringThe route pattern to use for matching.

controller

mixedThe controller to map to the given pattern.

rules

arrayAn array of regex rules keyed using the route variables.

defaults

arrayAn array of default values that are used when the URL is matched.

Response

$this

post

Add a POST route to the router.

post(string pattern, mixed controller, array rules = [], array defaults = []) : $this
since

2.0.0

Arguments

pattern

stringThe route pattern to use for matching.

controller

mixedThe controller to map to the given pattern.

rules

arrayAn array of regex rules keyed using the route variables.

defaults

arrayAn array of default values that are used when the URL is matched.

Response

$this

put

Add a PUT route to the router.

put(string pattern, mixed controller, array rules = [], array defaults = []) : $this
since

2.0.0

Arguments

pattern

stringThe route pattern to use for matching.

controller

mixedThe controller to map to the given pattern.

rules

arrayAn array of regex rules keyed using the route variables.

defaults

arrayAn array of default values that are used when the URL is matched.

Response

$this

serialize

Serialize the router.

serialize() : string
since

2.0.0

Response

stringThe serialized router.

trace

Add a TRACE route to the router.

trace(string pattern, mixed controller, array rules = [], array defaults = []) : $this
since

2.0.0

Arguments

pattern

stringThe route pattern to use for matching.

controller

mixedThe controller to map to the given pattern.

rules

arrayAn array of regex rules keyed using the route variables.

defaults

arrayAn array of default values that are used when the URL is matched.

Response

$this

unserialize

Unserialize the router.

unserialize(string serialized) : void
since

2.0.0

Arguments

serialized

stringThe serialized router.

Properties

routes

An array of Route objects defining the supported paths.

since

2.0.0

Type(s)

\Joomla\Router\Route[]