Jet\Debug_ErrorHandler
Basic class for handlers - modules for error management. Its main purpose is to keep a list of registered handlers, catch PHP errors and catch uncaught exceptions (and other things - vision method list). It is the centerpiece of the ErrorHandler subsystem.
Method | Meaning |
---|---|
static registerHandler( Debug_ErrorHandler $handler ): void | Registers a handler (an instance of a class that inherits from the abstract class Jet\Debug_ErrorHandler_Handler) WARNING! This method is not used in practice during initialization. Hadler has a static register() method that takes care of the handler registration. |
static unRegisterHandler( string $name ): void |
Registers the error handler. |
static getHandler( string $name ): Debug_ErrorHandler_Handler|null |
Returns the handler instance by its name - if registered. If it is not, then it returns null. |
static getRegisteredHandlers(): Debug_ErrorHandler_Handler[] | Returns a list of all registered handlers. |
initialize(): void | Subsystem initialization. |
static handleError( int $code, string $message, string $file = '', int $line = 0 ): void |
Catches PHP errors. |
static handleException( Throwable $exception ): void |
The method takes care of catching uncaught exceptions. |
static getLastError(): Debug_ErrorHandler_Error|null | Returns the instance of the last recorded hint. |
static addIgnoreNonFatalErrorsPath( string $path ): void |
Sometimes it is necessary to suppress minor error messages like notice, warning and so on. So in general it is not a good idea, every problem should be given due care. This is also why Jet has error reporting fully enabled by default. But the world is not a perfect place :-) Sometimes you don't have any other option (e.g. when integrating a third party library/component). Then there is the fact that the silence operator (@) cannot be reliably and always detected correctly in PHP8. Therefore there is an option to set the ErrorHandler to ignore non-serious errors (warning, notice) in certain directories. What is this good for? Two situations:
That's what this static method is for, and you can register directories as you like and need. It just might not be a good idea to register the entire application directory, for example :-) |
static getIgnoreNonFatalErrorsPaths( ) : array |
See addIgnoreNonFatalErrorsPath. Returns a list of registered directories. |
static doItSilent ( callable $operation ) : array |
Again, the issue of error message suppression. It may happen that several factors will work against each other. Jet application should be set up to display/log every error - even a simple warning. On the other hand, some PHP functions may still generate warnings. Of course, we need to use them even when they do generate warnings, but we certainly don't want to log these expected warnings, much less display them. Unfortunately, the silent operator (@) cannot be detected in PHP8 as it was possible before. Thus, it is not possible to use it effectively even though it would be really useful. The solution is to do it like this:
$cached_data = Debug_ErrorHandler::doItSilent(function() use ($cached_data) {
|