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 29
protected array splitFunctionAndParameters(string $function)

Splits function name and parameters into an array.

Parameters

string $function Function

Return Value

array

in FunctionParserTrait at line 48
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

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

Constructor.

Parameters

Routes $routes Routes
Container|null $container Container

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

Registers constraint.

Parameters

string $name Constraint name
string $constraint Constraint class name

Return Value

Router

at line 99
Router setConstraintAsGlobal(array $constraint)

Sets the chosen constraint as global.

Parameters

array $constraint Array of constraint names

Return Value

Router

at line 113
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 141
protected ConstraintInterface constraintFactory(string $constraint)

Constraint factory.

Parameters

string $constraint Constraint

Return Value

ConstraintInterface

at line 161
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 180
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 203
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 224
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 240
Route route(Request $request)

Matches and returns the appropriate route along with its parameters.

Parameters

Request $request Request

Return Value

Route