Application
Application
Console application bootstrap and command dispatcher.
class ApplicationCoordinates module registration, command discovery, CLI argument parsing, runtime environment initialization, and centralized error/exception output for Hazaar console commands.
Properties
modules
public array $modulesType: array
commands
A list of commands registered with the application by modules.
public array $commandsType: array
globalOptions
A list of global options available to all commands.
public array $globalOptionsType: array
name
Human-readable application name displayed in CLI output.
private string $nameType: string
version
Application version displayed in CLI output.
private string $versionType: string
input
Parsed command-line input accessor.
private Input $inputType: Hazaar\Console\Input
output
Console output writer used for formatted terminal responses.
private Output $outputType: Hazaar\Console\Output
methods
A list of methods registered with the application.
private array $methodsType: array
exitCode
The exit code to return when the application finishes execution.
private int $exitCodeType: int
Methods
__construct
Creates a console application instance and wires core handlers.
public __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN'): voidRegisters default modules, installs exception/error/shutdown handlers, and initializes the runtime root path.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | application display name |
$version | string | application display version |
add
Registers a console module with the application.
public add(Module $module): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$module | Hazaar\Console\Module | module instance that can expose commands |
addGlobalOption
Adds a global option available to all commands.
public addGlobalOption(string $long, ?string $short, ?string $description, ?bool $takesValue, mixed $default, ?string $valueType): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$long | string | long option name |
$short | string | optional short option alias |
$description | string | optional option description |
$takesValue | bool | whether the option accepts a value |
$default | mixed | default value for the option |
$valueType | string | optional expected value type |
loadModule
public loadModule(string $moduleClass): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$moduleClass | string |
run
Initializes modules, resolves the requested command, and executes it.
public run(): intReturns: int
Returns the command exit status code.
registerMethod
Registers a new console method.
public registerMethod(array $method): voidReturns: void
Adds the provided method to the list of available console methods to be executed before command execution.
Parameters
| Parameter | Type | Description |
|---|---|---|
$method | array | the method definition to register |
handleException
Global exception handler for uncaught console exceptions.
public handleException(\Throwable $e): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$e | Throwable | uncaught exception/error |
handleError
Global PHP error handler used during console command execution.
public handleError(int $errno, string $errstr, string $errfile, int $errline): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$errno | int | PHP error level |
$errstr | string | PHP error message |
$errfile | string | file where the error occurred |
$errline | int | line number where the error occurred |
shutdownHandler
Shutdown handler function.
public shutdownHandler(): voidReturns: void
This function is responsible for executing the shutdown tasks registered in the global variable $__shutdownTasks. It checks if the script is running in CLI mode or if headers have already been sent before executing the tasks.
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:18 +0000