Route
Route
- Full name:
\Hazaar\Application\Route
Properties
router
public \Hazaar\Application\Router $router
callable
private mixed $callable
path
private ?string $path
methods
private string[] $methods
actionArgs
private array $actionArgs
callableParameters
private array<string,\ReflectionParameter> $callableParameters
Methods
__construct
public __construct(mixed $callable, ?string $path = null, string[] $methods = []): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$callable | mixed | |
$path | ?string | |
$methods | string[] |
setRouter
Sets the router instance for the application.
public setRouter(\Hazaar\Application\Router $router): void
Parameters:
Parameter | Type | Description |
---|---|---|
$router | \Hazaar\Application\Router | the router instance to be set |
getPath
Retrieves the path associated with the current route.
public getPath(): null|string
Return Value:
the path of the route, or null if no path is set
match
Matches the given HTTP method and path against the route's method and path.
public match(string $method, string $path): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$method | string | The HTTP method to match (e.g., 'GET', 'POST'). |
$path | string | the request path to match |
Return Value:
returns true if the method and path match the route, false otherwise
getController
Retrieves the controller instance based on the callable property.
public getController(): ?\Hazaar\Controller
This method checks if the callable property is a Closure or an array. If it is a Closure, it returns a new Closure instance. If it is an array, it extracts the controller class name, verifies its existence, and returns a new instance of the controller class.
Return Value:
the controller instance or null if the callable is not a Closure or an array
Throws:
if the controller class does not exist
getAction
Retrieves the action to be executed.
public getAction(): string
This method checks if the action is defined in the callable array. If it is, it returns that action. Otherwise, it falls back to the default action specified in the router configuration.
Return Value:
the action to be executed
getActionArgs
Retrieve the action arguments.
public getActionArgs(): array
This method returns an array of arguments that are passed to the action.
Return Value:
the action arguments
Automatically generated on 2024-11-14