AbstractApp
in package
Micro PHP Application
Table of Contents
- CONFIG_BASE_URL = 'app.base_url'
- CONFIG_ENVIRONMENT = 'app.environment'
- CONFIG_ROOT_PATH = 'app.root_path'
- EVENT_INIT_FINISHED = 'app:init_finished'
- PRODUCTION_ENVIRONMENT = 'prod'
- $config : ConfigInterface|null
- $configPaths : array<string|int, mixed>
- $exitOnFinish : bool
- $logger : LoggerInterface|null
- $middlewares : array<string|int, mixed>
- Stores the middleware class names in a list
- __construct() : mixed
- addMiddleware() : void
- Adds a middleware
- finish() : void
- Finishes the application
- fullInit() : void
- Fully initializes the application
- fullProcess() : void
- Calls the `process()` method within a try/catch, handles exception with the `handleException()` method
- init() : void
- Abstract function for initialize the application
- process() : void
- Abstract function for processing the application
- handleException() : void
- Handles the exception
- loadConfigs() : void
- Loads all the configs by the `$configPaths`
- runMiddlewares() : void
- 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'
EVENT_INIT_FINISHED
public
mixed
EVENT_INIT_FINISHED
= 'app:init_finished'
PRODUCTION_ENVIRONMENT
public
mixed
PRODUCTION_ENVIRONMENT
= 'prod'
Properties
$config
protected
ConfigInterface|null
$config
= null
$configPaths
protected
array<string|int, mixed>
$configPaths
$exitOnFinish
protected
bool
$exitOnFinish
= true
$logger
protected
LoggerInterface|null
$logger
= null
$middlewares
Stores the middleware class names in a list
protected
array<string|int, mixed>
$middlewares
= []
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) : void
It adds only if not presents.
Parameters
- $interface : string
Return values
void —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() : void
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
void —fullProcess()
Calls the `process()` method within a try/catch, handles exception with the `handleException()` method
public
fullProcess() : void
Return values
void —init()
Abstract function for initialize the application
public
abstract init() : void
Return values
void —process()
Abstract function for processing the application
public
abstract process() : void
Return values
void —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
Tags
Return values
void —loadConfigs()
Loads all the configs by the `$configPaths`
protected
loadConfigs() : void
Return values
void —runMiddlewares()
Runs all the added middlewares
protected
runMiddlewares() : void