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

void
addRoute(RouteInterface $route)

Add a route.

void
removeRoute(RouteInterface $route)

Remove a route.

__construct(ConditionFactory $condition_factory, HandlerFactory $handler_factory)

Constructor.

getCurrentRoute()

Get the current route.

void
setCurrentRoute(RouteInterface $current_route)

Set the current route.

string[]
mergeMethodsAttribute(string[] $old, string[] $new)

Merge the methods attribute combining values.

mergeConditionAttribute(string|array|Closure|ConditionInterface|null $old, string|array|Closure|ConditionInterface|null $new)

Merge the condition attribute.

string[]
mergeMiddlewareAttribute(string[] $old, string[] $new)

Merge the middleware attribute combining values.

string
mergeNamespaceAttribute(string $old, string $new)

Merge the namespace attribute taking the latest value.

string|Closure
mergeHandlerAttribute(string|Closure $old, string|Closure $new)

Merge the handler attribute taking the latest value.

string|Closure
mergeQueryAttribute(callable|null $old, callable|null $new)

Merge the handler attribute taking the latest value.

string
mergeNameAttribute(string $old, string $new)

Merge the name attribute combining values with a dot.

array
mergeAttributes(array $old, array $new)

Merge attributes into route.

void
group(array $attributes, Closure|string $routes)

Create a route group.

route(array $attributes)

Make a route.

execute(RequestInterface $request)

Assign and return the first satisfied route (if any) as the current one for the given request.

string
getRouteUrl(string $name, array $arguments = [])

Get the url for a named route.

Details

RouteInterface[] getRoutes()

Get routes.

Return Value

RouteInterface[]

void addRoute(RouteInterface $route)

Add a route.

Parameters

RouteInterface $route

Return Value

void

void removeRoute(RouteInterface $route)

Remove a route.

Parameters

RouteInterface $route

Return Value

void

__construct(ConditionFactory $condition_factory, HandlerFactory $handler_factory)

Constructor.

Parameters

ConditionFactory $condition_factory
HandlerFactory $handler_factory

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

string[] mergeMethodsAttribute(string[] $old, string[] $new)

Merge the methods attribute combining values.

Parameters

string[] $old
string[] $new

Return Value

string[]

ConditionInterface|string mergeConditionAttribute(string|array|Closure|ConditionInterface|null $old, string|array|Closure|ConditionInterface|null $new)

Merge the condition attribute.

Parameters

string|array|Closure|ConditionInterface|null $old
string|array|Closure|ConditionInterface|null $new

Return Value

ConditionInterface|string

string[] mergeMiddlewareAttribute(string[] $old, string[] $new)

Merge the middleware attribute combining values.

Parameters

string[] $old
string[] $new

Return Value

string[]

string mergeNamespaceAttribute(string $old, string $new)

Merge the namespace attribute taking the latest value.

Parameters

string $old
string $new

Return Value

string

string|Closure mergeHandlerAttribute(string|Closure $old, string|Closure $new)

Merge the handler attribute taking the latest value.

Parameters

string|Closure $old
string|Closure $new

Return Value

string|Closure

string|Closure mergeQueryAttribute(callable|null $old, callable|null $new)

Merge the handler attribute taking the latest value.

Parameters

callable|null $old
callable|null $new

Return Value

string|Closure

string mergeNameAttribute(string $old, string $new)

Merge the name attribute combining values with a dot.

Parameters

string $old
string $new

Return Value

string

array mergeAttributes(array $old, array $new)

Merge attributes into route.

Parameters

array $old mixed> $old
array $new mixed> $new

Return Value

array mixed>

void group(array $attributes, Closure|string $routes)

Create a route group.

Parameters

array $attributes mixed> $attributes
Closure|string $routes Closure or path to file.

Return Value

void

RouteInterface route(array $attributes)

Make a route.

Parameters

array $attributes mixed> $attributes

Return Value

RouteInterface

RouteInterface|null execute(RequestInterface $request)

Assign and return the first satisfied route (if any) as the current one for the given request.

Parameters

RequestInterface $request

Return Value

RouteInterface|null

string getRouteUrl(string $name, array $arguments = [])

Get the url for a named route.

Parameters

string $name
array $arguments

Return Value

string