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 $modulescommands
A list of commands registered with the application by modules.
public array $commandsglobalOptions
A list of global options available to all commands.
public array $globalOptionsname
Human-readable application name displayed in CLI output.
private string $nameversion
Application version displayed in CLI output.
private string $versioninput
Parsed command-line input accessor.
private Input $inputoutput
Console output writer used for formatted terminal responses.
private Output $outputmethods
A list of methods registered with the application.
private array $methodsexitCode
The exit code to return when the application finishes execution.
private int $exitCodeMethods
__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): voidParameters
| Parameter | Type | Description |
|---|---|---|
$module | 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): selfParameters
| 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): voidParameters
| Parameter | Type | Description |
|---|---|---|
$moduleClass | string |
run
Initializes modules, resolves the requested command, and executes it.
public run(): intReturns the command exit status code.
registerMethod
Registers a new console method.
public registerMethod(array $method): voidAdds 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): voidParameters
| 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): boolParameters
| 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(): voidThis 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 Tue, 21 Apr 2026 04:00:25 +0000