ErrorHandler implements ErrorHandlerInterface, LoggerAwareInterface uses LoggerAwareTrait
Global error handler for TYPO3
This file is a backport from TYPO3 Flow
Table of Contents
Interfaces
- ErrorHandlerInterface
- Error handler interface for TYPO3
- LoggerAwareInterface
Constants
- ERROR_LEVEL_LABELS = [ E_WARNING => 'PHP Warning', E_NOTICE => 'PHP Notice', E_USER_ERROR => 'PHP User Error', E_USER_WARNING => 'PHP User Warning', E_USER_NOTICE => 'PHP User Notice', E_RECOVERABLE_ERROR => 'PHP Catchable Fatal Error', E_USER_DEPRECATED => 'TYPO3 Deprecation Notice', E_DEPRECATED => 'PHP Runtime Deprecation Notice', // @todo: Remove 2048 (deprecated E_STRICT) in v14, as this value is no longer used by PHP itself // and only kept here here because possible custom PHP extensions may still use it. // See https://wiki.php.net/rfc/deprecations_php_8_4#remove_e_strict_error_level_and_deprecate_e_strict_constant 2048 => 'PHP Runtime Notice', ]
Properties
- $debugMode : bool
- Whether to write a flash message in case of an error
- $errorHandlerErrors : int
- Error levels which should be handled.
- $exceptionalErrors : int
- Error levels which should result in an exception thrown.
Methods
- __construct() : mixed
- Registers this class as default error handler
- handleError() : bool
- Handles an error.
- registerErrorHandler() : mixed
- setDebugMode() : mixed
- setExceptionalErrors() : mixed
- Defines which error levels should result in an exception thrown.
- createAndEnqueueFlashMessage() : void
- getBackendUser() : BackendUserAuthentication|null
- getFormattedLogMessage() : string
- getTimeTracker() : TimeTracker
- writeLog() : mixed
- Writes an error in the sys_log table
Constants
ERROR_LEVEL_LABELS
protected
mixed
ERROR_LEVEL_LABELS
= [
E_WARNING => 'PHP Warning',
E_NOTICE => 'PHP Notice',
E_USER_ERROR => 'PHP User Error',
E_USER_WARNING => 'PHP User Warning',
E_USER_NOTICE => 'PHP User Notice',
E_RECOVERABLE_ERROR => 'PHP Catchable Fatal Error',
E_USER_DEPRECATED => 'TYPO3 Deprecation Notice',
E_DEPRECATED => 'PHP Runtime Deprecation Notice',
// @todo: Remove 2048 (deprecated E_STRICT) in v14, as this value is no longer used by PHP itself
// and only kept here here because possible custom PHP extensions may still use it.
// See https://wiki.php.net/rfc/deprecations_php_8_4#remove_e_strict_error_level_and_deprecate_e_strict_constant
2048 => 'PHP Runtime Notice',
]
Properties
$debugMode
Whether to write a flash message in case of an error
protected
bool
$debugMode
= false
$errorHandlerErrors
Error levels which should be handled.
protected
int
$errorHandlerErrors
= 0
$exceptionalErrors
Error levels which should result in an exception thrown.
protected
int
$exceptionalErrors
= 0
Methods
__construct()
Registers this class as default error handler
public
__construct(int $errorHandlerErrors) : mixed
Parameters
- $errorHandlerErrors : int
-
The integer representing the E_* error level which should be
handleError()
Handles an error.
public
handleError(int $errorLevel, string $errorMessage, string $errorFile, int $errorLine) : bool
If the error is registered as exceptionalError it will by converted into an exception, to be handled by the configured exceptionhandler. Additionally the error message is written to the configured logs. If application is backend, the error message is also added to the flashMessageQueue, in frontend the error message is displayed in the admin panel (as TsLog message).
Parameters
- $errorLevel : int
-
The error level - one of the E_* constants
- $errorMessage : string
-
The error message
- $errorFile : string
-
Name of the file the error occurred in
- $errorLine : int
-
Line number where the error occurred
Tags
Return values
boolregisterErrorHandler()
public
registerErrorHandler() : mixed
setDebugMode()
public
setDebugMode(bool $debugMode) : mixed
Parameters
- $debugMode : bool
setExceptionalErrors()
Defines which error levels should result in an exception thrown.
public
setExceptionalErrors(int $exceptionalErrors) : mixed
Parameters
- $exceptionalErrors : int
-
The integer representing the E_* error level to handle as exceptions
createAndEnqueueFlashMessage()
protected
createAndEnqueueFlashMessage(string $message, int $errorLevel) : void
Parameters
- $message : string
- $errorLevel : int
getBackendUser()
protected
getBackendUser() : BackendUserAuthentication|null
Return values
BackendUserAuthentication|nullgetFormattedLogMessage()
protected
getFormattedLogMessage(string $message) : string
Parameters
- $message : string
Return values
stringgetTimeTracker()
protected
getTimeTracker() : TimeTracker
Return values
TimeTrackerwriteLog()
Writes an error in the sys_log table
protected
writeLog(string $logMessage, string $logLevel) : mixed
Parameters
- $logMessage : string
-
Default text that follows the message (in english!).
- $logLevel : string
-
The error level, see LogLevel::* constants