class Router

Router.

Traits

Function parser trait.

Properties

protected Routes $routes Route collection.
protected Container $container Container.
protected array $constraints Constraints.
protected array $globalConstraints Global constraints.

Methods

array
splitFunctionAndParameters(string $function)

Splits function name and parameters into an array.

array
parseFunction(string $function, bool|null $namedParameters = null)

Parses custom "function calls".

__construct(Routes $routes, Container|null $container = null)

Constructor.

registerConstraint(string $name, string $constraint)

Registers constraint.

setConstraintAsGlobal(array $constraint)

Sets the chosen constraint as global.

bool
matches(Route $route, string $path)

Returns TRUE if the route matches the request path and FALSE if not.

constraintFactory(string $constraint)

Constraint factory.

bool
constraintsAreSatisfied(Route $route)

Returns true if all the route constraints are satisfied and false if not.

redirectRoute(string $requestPath)

Returns a route with a closure action that redirects to the correct URL.

array
getAllowedMethodsForMatchingRoutes(string $requestPath)

Returns an array of all allowed request methods for the requested route.

optionsRoute(string $requestPath)

Returns a route with a closure action that sets the allow header.

route(Request $request)

Matches and returns the appropriate route along with its parameters.

Details

in FunctionParserTrait at line 32
protected array splitFunctionAndParameters(string $function)

Splits function name and parameters into an array.

Parameters

string $function Function

Return Value

array

Exceptions

RuntimeException

in FunctionParserTrait at line 52
protected array parseFunction(string $function, bool|null $namedParameters = null)

Parses custom "function calls".

The return value is an array consisting of the function name and parameters.

Parameters

string $function Function
bool|null $namedParameters Are we expecting named parameters?

Return Value

array

Exceptions

RuntimeException

at line 73
__construct(Routes $routes, Container|null $container = null)

Constructor.

Parameters

Routes $routes Routes
Container|null $container Container

at line 87
Router registerConstraint(string $name, string $constraint)

Registers constraint.

Parameters

string $name Constraint name
string $constraint Constraint class name

Return Value

Router

at line 100
Router setConstraintAsGlobal(array $constraint)

Sets the chosen constraint as global.

Parameters

array $constraint Array of constraint names

Return Value

Router

at line 114
protected bool matches(Route $route, string $path)

Returns TRUE if the route matches the request path and FALSE if not.

Parameters

Route $route Route
string $path Request path

Return Value

bool

at line 143
protected ConstraintInterface constraintFactory(string $constraint)

Constraint factory.

Parameters

string $constraint Constraint

Return Value

ConstraintInterface

Exceptions

RuntimeException

at line 163
protected bool constraintsAreSatisfied(Route $route)

Returns true if all the route constraints are satisfied and false if not.

Parameters

Route $route Route

Return Value

bool

at line 182
protected Route redirectRoute(string $requestPath)

Returns a route with a closure action that redirects to the correct URL.

Parameters

string $requestPath The requested path

Return Value

Route

at line 205
protected array getAllowedMethodsForMatchingRoutes(string $requestPath)

Returns an array of all allowed request methods for the requested route.

Parameters

string $requestPath The requested path

Return Value

array

at line 226
protected Route optionsRoute(string $requestPath)

Returns a route with a closure action that sets the allow header.

Parameters

string $requestPath The requested path

Return Value

Route

at line 244
Route route(Request $request)

Matches and returns the appropriate route along with its parameters.

Parameters

Request $request Request

Return Value

Route

Exceptions

MethodNotAllowedException
NotFoundException