Basic
Basic
Basic controller class
This controller is a basic controller for directly handling requests. Developers can extend this class to create their own flexible controllers for use in modern AJAX enabled websites that don't require HTML views.
How it works is a request is passed to the controller and the controller is responsible for processing it, creating a new response object and return that object back to the application for processing.
This controller type is typically used for handling AJAX requests as responses to these requests do not require rendering any views. This allows AJAX requests to be processed quickly without the overhead of rendering a view that will never be displayed.
Properties
name
protected string $name = 'basic'stream
protected bool $streamcachedActions
private array $cachedActionscachedResponses
private array $cachedResponsesresponseCache
public Adapter $responseCachemiddleware
private array $middlewareMethods
initialize
public initialize(Request $request): voidParameters
| Parameter | Type | Description |
|---|---|---|
$request | Request |
run
Run the controller action.
public run(?Route $route): ResponseThis is the main entry point for the controller when there is a route to run. It is called by the application to run a route and execute the controller action. The action name and arguments are taken from the route.
Parameters
| Parameter | Type | Description |
|---|---|---|
$route | Route | the route to run, or null if no route is provided |
shutdown
public shutdown(): voidrunAction
Run an action method on a controller.
public runAction(string $actionName, array $actionArgs, bool $namedActionArgs): ResponseThis is the main controller action decision code and is where the controller will decide what to actually execute and whether to cache the response on not.
Parameters
| Parameter | Type | Description |
|---|---|---|
$actionName | string | |
$actionArgs | array | The arguments to pass to the action |
$namedActionArgs | bool |
stream
Sends a stream response to the client.
public stream(string $value): boolThis method sends a stream response to the client, allowing the client to download the response as a file. It sets the necessary headers for the response and flushes the output buffer to ensure the response is sent immediately.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string | The value to be streamed. If an array is provided, it will be converted to a JSON string before streaming. |
sendEarlyHints
Send early hints to the client.
public sendEarlyHints(array $links): boolThis method sends early hints to the client using the HTTP/2 or HTTP/3 protocol. It is used to inform the client about resources that should be preloaded or prefetched. The Link class is used to create the links.
Parameters
| Parameter | Type | Description |
|---|---|---|
$links | array | an array of Link objects to send as early hints |
cacheAction
public cacheAction(string $actionName, int $timeout = 60, bool $private): boolParameters
| Parameter | Type | Description |
|---|---|---|
$actionName | string | |
$timeout | int | |
$private | bool |
middleware
Creates and returns a new Middleware instance with the specified name.
protected middleware(string $name, mixed $args): HandlerParameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the middleware to instantiate |
$args | mixed |
init
protected init(): voidgetCacheKey
Get the cache key for the current action.
private getCacheKey(string $controller, string $action, ?array $actionArgs, ?string $cacheName): stringParameters
| Parameter | Type | Description |
|---|---|---|
$controller | string | the controller name |
$action | string | the action name |
$actionArgs | array | the action arguments |
$cacheName | string | the cache name |
cacheResponse
private cacheResponse(Route $route, Response $response): boolParameters
| Parameter | Type | Description |
|---|---|---|
$route | Route | |
$response | Response |
getCachedResponse
private getCachedResponse(Route $route): ?ResponseParameters
| Parameter | Type | Description |
|---|---|---|
$route | Route |
Generated by Hazaar API Doc Generator on Mon, 27 Oct 2025 13:01:29 +0000