Base error handler that provides logic common to the CLI + web error/exception handlers.
Subclasses are required to implement the template methods to handle displaying the errors in their environment.
array<string, mixed>Runtime config
boolWhether the config property has already been configured with defaults
array<string, mixed>Options to use for the Error handling.
boolCake\Error\ErrorLoggerInterface|nullException logger instance.
Deletes a single config key.
Reads a config key.
Writes a config key.
Display an error message in an environment specific way.
Display an exception in an environment specific way.
Log an error.
Stop the process.
Merge provided config with existing config. Unlike config() which does a recursive merge for nested keys, this method does a simple merge.
Returns the config.
Returns the config for this specific key.
Get exception logger.
Set as the default error handler by CakePHP.
Handle uncaught exceptions.
Display/Log a fatal error.
Increases the PHP "memory_limit" ini setting by the specified amount in kilobytes
Log an error for the exception if applicable.
Map an error code into an Error word, and log location.
Register the error and exception handlers.
Sets the config.
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(string $key): void
Deletes a single config key.
string $key Key to delete.
voidCake\Core\Exception\CakeException_configRead(string|null $key): mixed
Reads a config key.
string|null $key Key to read.
mixed_configWrite(array<string, mixed>|string $key, mixed $value, string|bool $merge = false): void
Writes a config key.
array<string, mixed>|string $key Key to write to.
mixed $value Value to write.
string|bool $merge optional True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.
voidCake\Core\Exception\CakeException_displayError(array $error, bool $debug): void
Display an error message in an environment specific way.
Subclasses should implement this method to display the error as desired for the runtime they operate in.
array $error An array of error data.
bool $debug Whether the app is in debug mode.
void_displayException(Throwable $exception): void
Display an exception in an environment specific way.
Subclasses should implement this method to display an uncaught exception as desired for the runtime they operate in.
Throwable $exception The uncaught exception.
void_logError(string|int $level, array $data): bool
Log an error.
string|int $level The level name of the log.
array $data Array of error data.
bool_stop(int $code): void
Stop the process.
Implemented in subclasses that need it.
int $code Exit code.
voidconfigShallow(array<string, mixed>|string $key, mixed|null $value = null): $this
Merge provided config with existing config. Unlike config() which does a recursive merge for nested keys, this method does a simple merge.
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']);
array<string, mixed>|string $key The key to set, or a complete array of configs.
mixed|null $value optional The value to set.
$thisgetConfig(string|null $key = null, mixed $default = null): mixed
Returns the config.
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'); string|null $key optional The key to get or null for the whole config.
mixed $default optional The return value when the key does not exist.
mixedgetConfigOrFail(string $key): mixed
Returns the config for this specific key.
The config value for this key must exist, it can never be null.
string $key The key to get.
mixedInvalidArgumentExceptiongetLogger(): Cake\Error\ErrorLoggerInterface
Get exception logger.
Cake\Error\ErrorLoggerInterfacehandleError(int $code, string $description, string|null $file = null, int|null $line = null, array<string, mixed>|null $context = null): bool
Set as the default error handler by CakePHP.
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.
int $code Code of error
string $description Error description
string|null $file optional File on which error occurred
int|null $line optional Line that triggered the error
array<string, mixed>|null $context optional Context
boolhandleException(Throwable $exception): void
Handle uncaught exceptions.
Uses a template method provided by subclasses to display errors in an environment appropriate way.
Throwable $exception Exception instance.
voidExceptionhandleFatalError(int $code, string $description, string $file, int $line): bool
Display/Log a fatal error.
int $code Code of error
string $description Error description
string $file File on which error occurred
int $line Line that triggered the error
boolincreaseMemoryLimit(int $additionalKb): void
Increases the PHP "memory_limit" ini setting by the specified amount in kilobytes
int $additionalKb Number in kilobytes
voidlogException(Throwable $exception, Psr\Http\Message\ServerRequestInterface|null $request = null): bool
Log an error for the exception if applicable.
Throwable $exception The exception to log a message for.
Psr\Http\Message\ServerRequestInterface|null $request optional The current request.
boolmapErrorCode(int $code): array
Map an error code into an Error word, and log location.
int $code Error code to map
arrayregister(): void
Register the error and exception handlers.
voidsetConfig(array<string, mixed>|string $key, mixed|null $value = null, bool $merge = true): $this
Sets the config.
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']);
array<string, mixed>|string $key The key to set, or a complete array of configs.
mixed|null $value optional The value to set.
bool $merge optional Whether to recursively merge or overwrite existing config, defaults to true.
$thisCake\Core\Exception\CakeExceptionwrapAndHandleException(Throwable $exception): 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.
Throwable $exception The exception to handle
voidRuntime config
array<string, mixed>Whether the config property has already been configured with defaults
boolOptions to use for the Error handling.
array<string, mixed>boolException logger instance.
Cake\Error\ErrorLoggerInterface|null
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/class-Cake.Error.BaseErrorHandler.html