CliApp
extends App
in package
Handles CLI commands
Table of Contents
- CONFIG_BASE_URL = 'app.base_url'
- CONFIG_ENVIRONMENT = 'app.environment'
- CONFIG_ROOT_PATH = 'app.root_path'
- PRODUCTION_ENVIRONMENT = 'prod'
- $commands : CliCommands
- $config : Config
- $configPaths : array<string|int, string>
- $exitOnFinish : bool
- $logger : Logger
- $middlewares : array<string|int, Middleware>
- Stores the middleware class names in a list
- $output : CliOutput
- __construct() : mixed
- addMiddleware() : mixed
- Adds a middleware
- finish() : void
- Finishes the application
- fullInit() : mixed
- Fully initializes the application
- fullProcess() : mixed
- Calls the `process()` method within a try/catch, handles exception with the `handleException()` method
- init() : mixed
- Abstract function for initialize the application
- process() : mixed
- Abstract function for processing the application
- handleException() : void
- Handles the exception
- loadConfigs() : mixed
- Loads all the configs by the `$configPaths`
- runMiddlewares() : mixed
- Runs all the added middlewares
Constants
CONFIG_BASE_URL
public
mixed
CONFIG_BASE_URL
= 'app.base_url'
CONFIG_ENVIRONMENT
public
mixed
CONFIG_ENVIRONMENT
= 'app.environment'
CONFIG_ROOT_PATH
public
mixed
CONFIG_ROOT_PATH
= 'app.root_path'
PRODUCTION_ENVIRONMENT
public
mixed
PRODUCTION_ENVIRONMENT
= 'prod'
Properties
$commands
protected
CliCommands
$commands
$config
protected
Config
$config
$configPaths
protected
array<string|int, string>
$configPaths
$exitOnFinish
protected
bool
$exitOnFinish
= true
$logger
protected
Logger
$logger
$middlewares
Stores the middleware class names in a list
protected
array<string|int, Middleware>
$middlewares
= []
$output
protected
CliOutput
$output
Methods
__construct()
public
__construct(array<string|int, mixed> $configPaths) : mixed
Parameters
- $configPaths : array<string|int, mixed>
Return values
mixed —addMiddleware()
Adds a middleware
public
addMiddleware(string $interface) : mixed
It adds only if not presents.
Parameters
- $interface : string
Return values
mixed —finish()
Finishes the application
public
finish(string|int $content) : void
If the $exitOnFinish true (default) calls the exit, otherwise just prints out the content.
Parameters
- $content : string|int
-
Content for the output. If it's an int, it is the return code of the process.
Return values
void —fullInit()
Fully initializes the application
public
fullInit() : mixed
Creates the Config, loads the configs, creates the Logger, calls the init() method
then runs all the middlewares. If an exception happens, handles it with the handleException() method.
Return values
mixed —fullProcess()
Calls the `process()` method within a try/catch, handles exception with the `handleException()` method
public
fullProcess() : mixed
Return values
mixed —init()
Abstract function for initialize the application
public
init() : mixed
Return values
mixed —process()
Abstract function for processing the application
public
process() : mixed
Return values
mixed —handleException()
Handles the exception
protected
handleException(Exception $e) : void
Sends the type, the line, the exception message and the stacktrace to the standard error output.
If the Config or the Logger wasn't initialised throws a MicroException.
Parameters
- $e : Exception
-
The exception
Return values
void —loadConfigs()
Loads all the configs by the `$configPaths`
protected
loadConfigs() : mixed
Return values
mixed —runMiddlewares()
Runs all the added middlewares
protected
runMiddlewares() : mixed