Class BaseErrorHandler
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.
Method Summary
- 
          _displayError() abstract protectedDisplay an error message in an environment specific way. 
- 
          _displayException() abstract protectedDisplay an exception in an environment specific way. 
- 
          _getMessage() protectedGenerates a formatted error message 
- 
          _logError() protectedLog an error. 
- 
          _logException() protectedHandles exception logging 
- 
          _requestContext() protectedGet the request context for an error/exception trace. 
- 
          _stop() protectedStop the process. 
- 
          handleError() publicSet as the default error handler by CakePHP. 
- 
          handleException() publicHandle uncaught exceptions. 
- 
          handleFatalError() publicDisplay/Log a fatal error. 
- 
          increaseMemoryLimit() publicIncreases the PHP "memory_limit" ini setting by the specified amount in kilobytes 
- 
          mapErrorCode() public staticMap an error code into an Error word, and log location. 
- 
          register() publicRegister the error and exception handlers. 
- 
          wrapAndHandleException() publicChecks the passed exception type. If it is an instance of Errorthen, it wraps the passed object inside another Exception object for backwards compatibility purposes.
Method Detail
_displayError() ¶ abstract protected
_displayError(array $error, bool $debug): voidDisplay 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.
Parameters
- 
                array$error
- An array of error data. 
- 
                bool$debug
- Whether or not the app is in debug mode. 
Returns
void_displayException() ¶ abstract protected
_displayException(Exception $exception): voidDisplay 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.
Parameters
- 
                Exception$exception
- The uncaught exception. 
Returns
void_getMessage() ¶ protected
_getMessage(Exception $exception): stringGenerates a formatted error message
Parameters
- 
                Exception$exception
- Exception instance 
Returns
stringFormatted message
_logError() ¶ protected
_logError(string $level, array $data): boolLog an error.
Parameters
- 
                string$level
- The level name of the log. 
- 
                array$data
- Array of error data. 
Returns
bool_logException() ¶ protected
_logException(Exception $exception): boolHandles exception logging
Parameters
- 
                Exception$exception
- Exception instance. 
Returns
bool_requestContext() ¶ protected
_requestContext(Cake\Network\Request $request): stringGet the request context for an error/exception trace.
Parameters
- 
                Cake\Network\Request$request
- The request to read from. 
Returns
string_stop() ¶ protected
_stop(int $code): voidStop the process.
Implemented in subclasses that need it.
Parameters
- 
                int$code
- Exit code. 
Returns
voidhandleError() ¶ public
handleError(int $code, string $description, string|null $file = null, int|null $line = null, array|null $context = null): boolSet 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 > 0. And will log errors to Log, when debug == 0.
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
- 
                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|null$context optional
- Context 
Returns
boolTrue if error was handled
handleException() ¶ public
handleException(Exception $exception): voidHandle uncaught exceptions.
Uses a template method provided by subclasses to display errors in an environment appropriate way.
Parameters
- 
                Exception$exception
- Exception instance. 
Returns
voidThrows
ExceptionWhen renderer class not found
See Also
handleFatalError() ¶ public
handleFatalError(int $code, string $description, string $file, int $line): boolDisplay/Log a fatal error.
Parameters
- 
                int$code
- Code of error 
- 
                string$description
- Error description 
- 
                string$file
- File on which error occurred 
- 
                int$line
- Line that triggered the error 
Returns
boolincreaseMemoryLimit() ¶ public
increaseMemoryLimit(string $additionalKb): voidIncreases the PHP "memory_limit" ini setting by the specified amount in kilobytes
Parameters
- 
                string$additionalKb
- Number in kilobytes 
Returns
voidmapErrorCode() ¶ public static
mapErrorCode(int $code): arrayMap an error code into an Error word, and log location.
Parameters
- 
                int$code
- Error code to map 
Returns
arrayArray of error word, and log location.
wrapAndHandleException() ¶ public
wrapAndHandleException(Exception|Error $exception): voidChecks 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.
Parameters
- 
                Exception|Error$exception
- The exception to handle 
Returns
void