ConsoleErrorHandler
extends BaseErrorHandler
in package
Error Handler for Cake console. Does simple printing of the exception that occurred and the stack trace of the error.
Table of Contents
Properties
- $_config : array<string, mixed>
- Runtime config
- $_configInitialized : bool
- Whether the config property has already been configured with defaults
- $_defaultConfig : array<string, mixed>
- Options to use for the Error handling.
- $_handled : bool
- $_stderr : ConsoleOutput
- Standard error stream.
- $logger : ErrorLoggerInterface|null
- Exception logger instance.
Methods
- __construct() : mixed
- Constructor
- configShallow() : $this
- Merge provided config with existing config. Unlike `config()` which does a recursive merge for nested keys, this method does a simple merge.
- getConfig() : mixed
- Returns the config.
- getConfigOrFail() : mixed
- Returns the config for this specific key.
- getLogger() : ErrorLoggerInterface
- Get exception logger.
- handleError() : bool
- Set as the default error handler by CakePHP.
- handleException() : void
- Handle errors in the console environment. Writes errors to stderr, and logs messages if Configure::read('debug') is false.
- handleFatalError() : bool
- Display/Log a fatal error.
- increaseMemoryLimit() : void
- Increases the PHP "memory_limit" ini setting by the specified amount in kilobytes
- logException() : bool
- Log an error for the exception if applicable.
- mapErrorCode() : array<string|int, mixed>
- Map an error code into an Error word, and log location.
- register() : void
- Register the error and exception handlers.
- setConfig() : $this
- Sets the config.
- wrapAndHandleException() : void
- Checks the passed exception type. If it is an instance of `Error` then, it wraps the passed object inside another Exception object for backwards compatibility purposes.
- _configDelete() : void
- Deletes a single config key.
- _configRead() : mixed
- Reads a config key.
- _configWrite() : void
- Writes a config key.
- _displayError() : void
- Prints an error to stderr.
- _displayException() : void
- Prints an exception to stderr.
- _logError() : bool
- Log an error.
- _stop() : void
- Stop the execution and set the exit code for the process.
Properties
$_config
Runtime config
protected
array<string, mixed>
$_config
= []
$_configInitialized
Whether the config property has already been configured with defaults
protected
bool
$_configInitialized
= false
$_defaultConfig
Options to use for the Error handling.
protected
array<string, mixed>
$_defaultConfig
= ['log' => true, 'trace' => false, 'skipLog' => [], 'errorLogger' => \Cake\Error\ErrorLogger::class]
$_handled
protected
bool
$_handled
= false
$_stderr
Standard error stream.
protected
ConsoleOutput
$_stderr
$logger
Exception logger instance.
protected
ErrorLoggerInterface|null
$logger
Methods
__construct()
Constructor
public
__construct([array<string, mixed> $config = [] ]) : mixed
Parameters
- $config : array<string, mixed> = []
-
Config options for the error handler.
configShallow()
Merge provided config with existing config. Unlike `config()` which does a recursive merge for nested keys, this method does a simple merge.
public
configShallow(array<string, mixed>|string $key[, mixed|null $value = null ]) : $this
Setting a specific value:
$this->configShallow('key', $value);
Setting a nested value:
$this->configShallow('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->configShallow(['one' => 'value', 'another' => 'value']);
Parameters
- $key : array<string, mixed>|string
-
The key to set, or a complete array of configs.
- $value : mixed|null = null
-
The value to set.
Return values
$thisgetConfig()
Returns the config.
public
getConfig([string|null $key = null ][, mixed $default = null ]) : mixed
Usage
Reading the whole config:
$this->getConfig();
Reading a specific value:
$this->getConfig('key');
Reading a nested value:
$this->getConfig('some.nested.key');
Reading with default value:
$this->getConfig('some-key', 'default-value');
Parameters
- $key : string|null = null
-
The key to get or null for the whole config.
- $default : mixed = null
-
The return value when the key does not exist.
Return values
mixed —Configuration data at the named key or null if the key does not exist.
getConfigOrFail()
Returns the config for this specific key.
public
getConfigOrFail(string $key) : mixed
The config value for this key must exist, it can never be null.
Parameters
- $key : string
-
The key to get.
Tags
Return values
mixed —Configuration data at the named key
getLogger()
Get exception logger.
public
getLogger() : ErrorLoggerInterface
Return values
ErrorLoggerInterfacehandleError()
Set as the default error handler by CakePHP.
public
handleError(int $code, string $description[, string|null $file = null ][, int|null $line = null ][, array<string, mixed>|null $context = null ]) : bool
Use config/error.php to customize or replace this error handler. This function will use Debugger to display errors when debug mode is on. And will log errors to Log, when debug mode is off.
You can use the 'errorLevel' option to set what type of errors will be handled. Stack traces for errors can be enabled with the 'trace' option.
Parameters
- $code : int
-
Code of error
- $description : string
-
Error description
- $file : string|null = null
-
File on which error occurred
- $line : int|null = null
-
Line that triggered the error
- $context : array<string, mixed>|null = null
-
Context
Return values
bool —True if error was handled
handleException()
Handle errors in the console environment. Writes errors to stderr, and logs messages if Configure::read('debug') is false.
public
handleException(Throwable $exception) : void
Parameters
- $exception : Throwable
-
Exception instance.
Tags
handleFatalError()
Display/Log a fatal error.
public
handleFatalError(int $code, string $description, string $file, int $line) : bool
Parameters
- $code : int
-
Code of error
- $description : string
-
Error description
- $file : string
-
File on which error occurred
- $line : int
-
Line that triggered the error
Return values
boolincreaseMemoryLimit()
Increases the PHP "memory_limit" ini setting by the specified amount in kilobytes
public
increaseMemoryLimit(int $additionalKb) : void
Parameters
- $additionalKb : int
-
Number in kilobytes
logException()
Log an error for the exception if applicable.
public
logException(Throwable $exception[, ServerRequestInterface|null $request = null ]) : bool
Parameters
- $exception : Throwable
-
The exception to log a message for.
- $request : ServerRequestInterface|null = null
-
The current request.
Return values
boolmapErrorCode()
Map an error code into an Error word, and log location.
public
static mapErrorCode(int $code) : array<string|int, mixed>
Parameters
- $code : int
-
Error code to map
Return values
array<string|int, mixed> —Array of error word, and log location.
register()
Register the error and exception handlers.
public
register() : void
setConfig()
Sets the config.
public
setConfig(array<string, mixed>|string $key[, mixed|null $value = null ][, bool $merge = true ]) : $this
Usage
Setting a specific value:
$this->setConfig('key', $value);
Setting a nested value:
$this->setConfig('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->setConfig(['one' => 'value', 'another' => 'value']);
Parameters
- $key : array<string, mixed>|string
-
The key to set, or a complete array of configs.
- $value : mixed|null = null
-
The value to set.
- $merge : bool = true
-
Whether to recursively merge or overwrite existing config, defaults to true.
Tags
Return values
$thiswrapAndHandleException()
Checks the passed exception type. If it is an instance of `Error` then, it wraps the passed object inside another Exception object for backwards compatibility purposes.
public
wrapAndHandleException(Throwable $exception) : void
Unused method will be removed in 5.0
Parameters
- $exception : Throwable
-
The exception to handle
_configDelete()
Deletes a single config key.
protected
_configDelete(string $key) : void
Parameters
- $key : string
-
Key to delete.
Tags
_configRead()
Reads a config key.
protected
_configRead(string|null $key) : mixed
Parameters
- $key : string|null
-
Key to read.
_configWrite()
Writes a config key.
protected
_configWrite(array<string, mixed>|string $key, mixed $value[, string|bool $merge = false ]) : void
Parameters
- $key : array<string, mixed>|string
-
Key to write to.
- $value : mixed
-
Value to write.
- $merge : string|bool = false
-
True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.
Tags
_displayError()
Prints an error to stderr.
protected
_displayError(array<string|int, mixed> $error, bool $debug) : void
Template method of BaseErrorHandler.
Parameters
- $error : array<string|int, mixed>
-
An array of error data.
- $debug : bool
-
Whether the app is in debug mode.
_displayException()
Prints an exception to stderr.
protected
_displayException(Throwable $exception) : void
Parameters
- $exception : Throwable
-
The exception to handle
_logError()
Log an error.
protected
_logError(string|int $level, array<string|int, mixed> $data) : bool
Parameters
- $level : string|int
-
The level name of the log.
- $data : array<string|int, mixed>
-
Array of error data.
Return values
bool_stop()
Stop the execution and set the exit code for the process.
protected
_stop(int $code) : void
Parameters
- $code : int
-
The exit code.