Handler
Handler
Properties
name
Name of the middleware.
public string $nameargs
Arguments passed to the middleware.
public array $argsmethods
Array of methods this middleware applies to.
private array $methodsexceptMethods
Array of methods this middleware does not apply to.
private array $exceptMethodsmiddlewareInstances
Static array to hold middleware instances.
private array $middlewareInstancesThis is used to store instances of middleware classes to avoid creating multiple instances of the same middleware class.
Methods
__construct
Constructor to initialize the middleware handler.
public __construct(string $middleware, array $args): voidParameters
| Parameter | Type | Description |
|---|---|---|
$middleware | string | Name of the middleware |
$args | array | Arguments for the middleware |
setInstance
Sets the middleware instance for the current handler.
public setInstance(Middleware $instance): voidStores the provided Middleware instance in a static array, indexed by the handler's name.
Parameters
| Parameter | Type | Description |
|---|---|---|
$instance | Middleware | the middleware instance to associate with this handler |
run
Executes the middleware by either reusing an existing instance or creating a new one,
public run(Request $request, callable $next): Responsethen calls its 'handle' method with the provided request, next callable, and any additional arguments.
Parameters
| Parameter | Type | Description |
|---|---|---|
$request | Request | the current HTTP request object |
$next | callable | the next middleware or handler to be executed |
only
Specifies that this middleware should only apply to the given HTTP method.
public only(string $method): selfParameters
| Parameter | Type | Description |
|---|---|---|
$method | string | The HTTP method (e.g., 'GET', 'POST') to which the middleware should be restricted. |
except
Excludes the specified HTTP method from being processed by this middleware.
public except(string $method): selfParameters
| Parameter | Type | Description |
|---|---|---|
$method | string | The HTTP method to exclude (e.g., 'GET', 'POST'). |
Determines if the given action name matches the middleware's method rules.
public (string $actionName): boolChecks if the provided action name is included in the allowed methods and not in the excepted methods. If no specific methods are set, only checks against the excepted methods.
Parameters
| Parameter | Type | Description |
|---|---|---|
$actionName | string | the name of the action to check |
Generated by Hazaar API Doc Generator on Mon, 27 Oct 2025 13:01:29 +0000