class Dispatcher

Route dispatcher.

Traits

Function parser trait.

Constants

MIDDLEWARE_DEFAULT_PRIORITY

Default middleware priority.

Properties

protected Request $request Request.
protected Response $response Response.
protected Container $container Container.
protected array $middleware Route middleware.
protected array $globalMiddleware Global middleware.
protected array $middlewarePriority Middleware priority.

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(Request $request, Response $response, Container|null $container = null)

Constructor.

setMiddlewarePriority(array $priority)

Sets the middleware priority.

resetMiddlewarePriority()

Resets middleware priority.

registerMiddleware(string $name, string $middleware, int|null $priority = null)

Registers middleware.

setMiddlewareAsGlobal(array $middleware)

Sets the chosen middleware as global.

array
resolveMiddleware(string $middleware)

Resolves the middleware.

array
orderMiddlewareByPriority(array $middleware)

Orders resolved middleware by priority.

addMiddlewareToStack(Onion $onion, array $middleware)

Adds route middleware to the stack.

executeClosure(Closure $closure, array $parameters)

Executes a closure action.

executeController(string $controller, array $parameters)

Executes a controller action.

executeAction(Route $route)

Executes the route action.

dispatch(Route $route)

Dispatches the route and returns the response.

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 93
__construct(Request $request, Response $response, Container|null $container = null)

Constructor.

Parameters

Request $request Request instance
Response $response Response instance
Container|null $container Container

at line 108
Dispatcher setMiddlewarePriority(array $priority)

Sets the middleware priority.

Parameters

array $priority Middleware priority

Return Value

Dispatcher

at line 120
Dispatcher resetMiddlewarePriority()

Resets middleware priority.

Return Value

Dispatcher

at line 135
Dispatcher registerMiddleware(string $name, string $middleware, int|null $priority = null)

Registers middleware.

Parameters

string $name Middleware name
string $middleware Middleware class name
int|null $priority Middleware priority

Return Value

Dispatcher

at line 153
Dispatcher setMiddlewareAsGlobal(array $middleware)

Sets the chosen middleware as global.

Parameters

array $middleware Array of middleware names

Return Value

Dispatcher

at line 166
protected array resolveMiddleware(string $middleware)

Resolves the middleware.

Parameters

string $middleware middleware

Return Value

array

at line 184
protected array orderMiddlewareByPriority(array $middleware)

Orders resolved middleware by priority.

Parameters

array $middleware Array of middleware

Return Value

array

at line 223
protected addMiddlewareToStack(Onion $onion, array $middleware)

Adds route middleware to the stack.

Parameters

Onion $onion Middleware stack
array $middleware Array of middleware

at line 257
protected Response executeClosure(Closure $closure, array $parameters)

Executes a closure action.

Parameters

Closure $closure Closure
array $parameters Parameters

Return Value

Response

at line 269
protected Response executeController(string $controller, array $parameters)

Executes a controller action.

Parameters

string $controller Controller
array $parameters Parameters

Return Value

Response

at line 319
protected Response executeAction(Route $route)

Executes the route action.

Parameters

Route $route Route

Return Value

Response

at line 339
Response dispatch(Route $route)

Dispatches the route and returns the response.

Parameters

Route $route Route

Return Value

Response