Internal
Internal
Class Internal.
This class extends the base Controller class and provides methods to execute actions associated with routes and handle internal controller actions.
- Full name:
\Hazaar\Controller\Internal
- Parent class:
\Hazaar\Controller
Methods
run
Executes the action associated with the given route and returns the response.
public run(null|\Hazaar\Application\Route $route = null): \Hazaar\Controller\Response
Parameters:
Parameter | Type | Description |
---|---|---|
$route | null|\Hazaar\Application\Route | the route containing the action and its arguments |
Return Value:
the response generated by the action or a file response if the action does not return a Response instance
Throws:
if the support file specified by the route is not found
runAction
Executes an internal controller action based on the provided action name.
public runAction(string $actionName, array $actionArgs = [], bool $namedActionArgs = false): false|\Hazaar\Controller\Response
Parameters:
Parameter | Type | Description |
---|---|---|
$actionName | string | the name of the action to execute, in the format 'route/action' |
$actionArgs | array | Optional. An array of arguments to pass to the action. Default is an empty array. |
$namedActionArgs | bool | Optional. Whether the action arguments are named. Default is false. |
Return Value:
returns a Response object if the action is successfully executed, or false if the action or controller is not found
Throws:
if the internal controller action is not found, an exception is thrown with a 404 status code
Inherited methods
__construct
Base controller constructor.
public __construct(string $name = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$name | string | The name of the controller. This is the name used when generating URLs. |
__toString
Convert the controller object into a string.
public __toString(): string
__get
Get the specified helper object.
public __get(string $helper): ?\Hazaar\Controller\Helper
Parameters:
Parameter | Type | Description |
---|---|---|
$helper | string | the name of the helper |
initialize
Controller initialisation method.
public initialize(\Hazaar\Application\Request $request): ?\Hazaar\Controller\Response
This should be called by all extending controllers and is simply responsible for storing the calling request.
Parameters:
Parameter | Type | Description |
---|---|---|
$request | \Hazaar\Application\Request | the application request object |
run
public run(?\Hazaar\Application\Route $route = null): \Hazaar\Controller\Response
Parameters:
Parameter | Type | Description |
---|---|---|
$route | ?\Hazaar\Application\Route |
runAction
public runAction(string $actionName, array $actionArgs = []): false|\Hazaar\Controller\Response
Parameters:
Parameter | Type | Description |
---|---|---|
$actionName | string | |
$actionArgs | array |
shutdown
final public shutdown(\Hazaar\Controller\Response $response): void
- This method is final.
Parameters:
Parameter | Type | Description |
---|---|---|
$response | \Hazaar\Controller\Response |
getName
Get the name of the controller.
public getName(): string
setStatus
Set the default return status code.
public setStatus(?int $code = null): void
Parameters:
Parameter | Type | Description |
---|---|---|
$code | ?int |
getStatus
Get the status code of the controller.
public getStatus(): int
getBasePath
Get the base path of the controller.
public getBasePath(): string
setBasePath
Set the base path for the controller.
public setBasePath(string $path): void
Parameters:
Parameter | Type | Description |
---|---|---|
$path | string |
redirect
Generate a redirect response to redirect the browser.
public redirect(string $location, bool $saveURI = false): \Hazaar\Controller\Response\HTTP\Redirect
It's quite common to redirect the user to an alternative URL. This may be to forward the request to another website, forward them to an authentication page or even just remove processed request parameters from the URL to neaten the URL up.
Parameters:
Parameter | Type | Description |
---|---|---|
$location | string | The URI you want to redirect to |
$saveURI | bool | Optionally save the URI so we can redirect back. See: Hazaar\Application::redirectBack() |
redirectBack
Redirect back to a URI saved during redirection.
public redirectBack(?string $altURL = null): false|\Hazaar\Controller\Response\HTTP\Redirect
This mechanism is used with the $saveURI parameter of Hazaar\Application::redirect()
so save the current URI into the session so that once we're done processing the request somewhere else we can come back to where we were. This is useful for when a user requests a page but isn't authenticated, we can redirect them to a login page and then that page can call this Hazaar\Application::redirectBack()
method to redirect the user back to the page they were originally looking for.
Parameters:
Parameter | Type | Description |
---|---|---|
$altURL | ?string |
getURL
Generate a URL relative to the controller.
public getURL(): \Hazaar\Application\URL
This is the controller relative method for generating URLs in your application. URLs generated from here are relative to the controller. For URLs that are relative to the current application see Hazaar\Application::url()
.
Parameters are dynamic and depend on what you are trying to generate.
For examples see: Generating URLs
addHelper
Add a helper to the controller.
public addHelper((\Hazaar\Controller\Helper|string)[]|\Hazaar\Controller\Helper|string $helper, array $args = [], string $alias = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$helper | (\Hazaar\Controller\Helper|string)[]|\Hazaar\Controller\Helper|string | The helper to add to the controller. This can be a helper object, a helper class name or an array of helpers. |
$args | array | an array of arguments to pass to the helper constructor |
$alias | string | The alias to use for the helper. If not provided, the helper name will be used. |
hasHelper
Checks if a helper exists.
public hasHelper(string $helper): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$helper | string | the name of the helper to check |
cacheAction
public cacheAction(string $actionName, int $timeout = 60, bool $private = false): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$actionName | string | |
$timeout | int | |
$private | bool |
findHelper
Find a helper class by name.
private findHelper(string $name): ?string
This method searches for view helper classes based on the given name. The search order is important because it allows apps to override built-in helpers.
Parameters:
Parameter | Type | Description |
---|---|---|
$name | string | the name of the helper class to find |
getCacheKey
Get the cache key for the current action.
private getCacheKey(string $controller, string $action, array $actionArgs = null, null|string& $cacheName = null): false|string
Parameters:
Parameter | Type | Description |
---|---|---|
$controller | string | the controller name |
$action | string | the action name |
$actionArgs | array | the action arguments |
$cacheName | null|string | the cache name |
cacheResponse
private cacheResponse(\Hazaar\Application\Route $route, \Hazaar\Controller\Response $response): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$route | \Hazaar\Application\Route | |
$response | \Hazaar\Controller\Response |
getCachedResponse
private getCachedResponse(\Hazaar\Application\Route $route): ?\Hazaar\Controller\Response
Parameters:
Parameter | Type | Description |
---|---|---|
$route | \Hazaar\Application\Route |
Automatically generated on 2024-11-14