Dispatcher
Dispatcher
Class MiddlewareDispatcher.
Responsible for managing and dispatching middleware components within the application. Handles the execution flow of middleware stacks, allowing for request and response manipulation at various stages of the application's lifecycle.
Properties
aliases
Stores aliases for middleware classes.
public array $aliasesmiddlewareStack
Stack of middleware components to be executed in order.
private array $middlewareStackMethods
__construct
MiddlewareDispatcher constructor.
public __construct(array $middlwareAliases): voidInitializes the middleware dispatcher with an empty stack.
Optionally accepts a configuration array to load global middleware and aliases. This allows for dynamic configuration of middleware components and their aliases, enhancing the flexibility of the middleware system.
Parameters
| Parameter | Type | Description |
|---|---|---|
$middlwareAliases | array |
add
Adds a middleware instance to the middleware stack.
public add(string $middleware, mixed $args): voidParameters
| Parameter | Type | Description |
|---|---|---|
$middleware | string | the middleware to add to the stack |
$args | mixed |
addFromArray
Adds an array of global middleware classes to the dispatcher.
public addFromArray(array $middlewareClasses): voidEach class in the provided array is validated to ensure it exists and implements the Middleware interface. If a class does not exist or does not implement the required interface, an InvalidArgumentException is thrown. Valid middleware classes are instantiated and added to the dispatcher.
Parameters
| Parameter | Type | Description |
|---|---|---|
$middlewareClasses | array | array of middleware class names to add |
addHandler
Adds a middleware handler to the middleware stack.
public addHandler(Handler $handler): voidParameters
| Parameter | Type | Description |
|---|---|---|
$handler | Handler | the middleware handler to add to the stack |
addHandlers
Add multiple middleware handlers to the dispatcher.
public addHandlers(array $handlers): voidThis method allows for adding multiple middleware handlers at once.
Parameters
| Parameter | Type | Description |
|---|---|---|
$handlers | array | an array of middleware handlers to add |
handle
Handles the incoming HTTP request by passing it through the middleware stack.
public handle(Request $request, callable $finalHandler): ResponseThis method reverses the middleware stack and wraps each middleware around the next, creating a chain of responsibility. The final handler is called after all middleware have been processed.
Parameters
| Parameter | Type | Description |
|---|---|---|
$request | Request | the incoming HTTP request to handle |
$finalHandler | callable | the final handler to be called after all middleware |
Generated by Hazaar API Doc Generator on Mon, 27 Oct 2025 13:01:29 +0000