Handler
Handler
Properties
name
Name of the middleware.
public string $name
args
Arguments passed to the middleware.
public array $args
methods
Array of methods this middleware applies to.
private array $methods
exceptMethods
Array of methods this middleware does not apply to.
private array $exceptMethods
middlewareInstances
Static array to hold middleware instances.
private array $middlewareInstances
This 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): void
Parameters
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): void
Stores 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): Response
then 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): self
Parameters
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): self
Parameters
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): bool
Checks 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 Tue, 29 Jul 2025 08:01:32 +0000