class Router implements HasRoutesInterface (View source)

Provide routing for site requests (i.e. all non-api requests)

Traits

Allow objects to have routes

Methods

getRoutes()

Get registered routes

addRoute(RouteInterface $route)

Add a route

route(string[] $methods, mixed $condition, string|Closure|null $handler = null)

Create and add a new route

group(string|Closure|ConditionInterface $condition, Closure|null $routes = null)

Create and add a route group

get(mixed $condition, string|Closure|null $handler = null)

Create and add a route for the GET and HEAD methods

post(mixed $condition, string|Closure|null $handler = null)

Create and add a route for the POST method

put(mixed $condition, string|Closure|null $handler = null)

Create and add a route for the PUT method

patch(mixed $condition, string|Closure|null $handler = null)

Create and add a route for the PATCH method

delete(mixed $condition, string|Closure|null $handler = null)

Create and add a route for the DELETE method

options(mixed $condition, string|Closure|null $handler = null)

Create and add a route for the OPTIONS method

any(mixed $condition, string|Closure|null $handler = null)

Create and add a route for all supported methods

__construct(Request $request, array $middleware, array $middleware_priority, integer $default_middleware_priority, ErrorHandlerInterface $error_handler)

Constructor.

void
boot()

Hook into WordPress actions.

integer
getMiddlewarePriority(mixed $middleware)

Get middleware priority.

array
sortMiddleware(array $middleware)

Sort middleware by priority in ascending order.

string
execute(string $view)

Execute the first satisfied route, if any.

getCurrentRoute()

Get the current route.

void
setCurrentRoute(RouteInterface $current_route)

Set the current route.

handleAll(string|Closure|null $handler = null)

Handle ALL requests.

Details

RouteInterface[] getRoutes()

Get registered routes

Return Value

RouteInterface[]

RouteInterface addRoute(RouteInterface $route)

Add a route

Parameters

RouteInterface $route

Return Value

RouteInterface

RouteInterface route(string[] $methods, mixed $condition, string|Closure|null $handler = null)

Create and add a new route

Parameters

string[] $methods
mixed $condition
string|Closure|null $handler

Return Value

RouteInterface

Exceptions

Exception

RouteInterface group(string|Closure|ConditionInterface $condition, Closure|null $routes = null)

Create and add a route group

Parameters

string|Closure|ConditionInterface $condition
Closure|null $routes

Return Value

RouteInterface

RouteInterface get(mixed $condition, string|Closure|null $handler = null)

Create and add a route for the GET and HEAD methods

Parameters

mixed $condition
string|Closure|null $handler

Return Value

RouteInterface

RouteInterface post(mixed $condition, string|Closure|null $handler = null)

Create and add a route for the POST method

Parameters

mixed $condition
string|Closure|null $handler

Return Value

RouteInterface

RouteInterface put(mixed $condition, string|Closure|null $handler = null)

Create and add a route for the PUT method

Parameters

mixed $condition
string|Closure|null $handler

Return Value

RouteInterface

RouteInterface patch(mixed $condition, string|Closure|null $handler = null)

Create and add a route for the PATCH method

Parameters

mixed $condition
string|Closure|null $handler

Return Value

RouteInterface

RouteInterface delete(mixed $condition, string|Closure|null $handler = null)

Create and add a route for the DELETE method

Parameters

mixed $condition
string|Closure|null $handler

Return Value

RouteInterface

RouteInterface options(mixed $condition, string|Closure|null $handler = null)

Create and add a route for the OPTIONS method

Parameters

mixed $condition
string|Closure|null $handler

Return Value

RouteInterface

RouteInterface any(mixed $condition, string|Closure|null $handler = null)

Create and add a route for all supported methods

Parameters

mixed $condition
string|Closure|null $handler

Return Value

RouteInterface

__construct(Request $request, array $middleware, array $middleware_priority, integer $default_middleware_priority, ErrorHandlerInterface $error_handler)

Constructor.

Parameters

Request $request
array $middleware
array $middleware_priority
integer $default_middleware_priority
ErrorHandlerInterface $error_handler

void boot()

Hook into WordPress actions.

Return Value

void

integer getMiddlewarePriority(mixed $middleware)

Get middleware priority.

Parameters

mixed $middleware

Return Value

integer

array sortMiddleware(array $middleware)

Sort middleware by priority in ascending order.

Parameters

array $middleware

Return Value

array

string execute(string $view)

Execute the first satisfied route, if any.

Parameters

string $view

Return Value

string

Exceptions

Exception

RouteInterface getCurrentRoute()

Get the current route.

Return Value

RouteInterface

void setCurrentRoute(RouteInterface $current_route)

Set the current route.

Parameters

RouteInterface $current_route

Return Value

void

RouteInterface handleAll(string|Closure|null $handler = null)

Handle ALL requests.

Parameters

string|Closure|null $handler

Return Value

RouteInterface