-
Notifications
You must be signed in to change notification settings - Fork 0
4.0: The Handler Class
Manages a registry of callback functions ("handlers") for errors, uncaught exceptions, and shutdown.
public mixed during( callable $callback [, mixed ...$arguments] )
Registers this handler to invoke a callback, and then restores the previous handler(s).
parameters:
- callable
$callback
The callback to invoke. - mixed
...$arguments
Argument(s) to pass to the callback.
returns the value returned from the callback.
public Handler onError( callable $handler [, int $types] )
Adds an error handler.
parameters:
- callable
$handler
The handler to add. Must be suitable for use withset_error_handler
. If the handler returnstrue
, then handling will stop (subsequently registered handlers will not be invoked). - int
$types
The error types the handler should be invoked for (a bitmask ofE_*
constants). Defaults to "any error type."
returns the Handler instance.
public Handler onException( callable $handler [, int $types] )
Adds a handler for uncaught exceptions.
parameters:
- callable
$handler
The handler to add. Must be suitable for use withset_exception_handler
. If the handler returnstrue
, then handling will stop (subsequently registered handlers will not be invoked). - int
$severity
The exception severities the handler should be invoked for (a bitmask ofExceptable
severity constants). Defaults to "any severity."
returns the Handler instance.
public Handler onShutdown( callable $handler [, ...$arguments] )
Adds a shutdown handler.
Note, shutdown handlers should not be registered to handle fatal errors. If the shutdown is due to a fatal error, the appropriate registered error handlers will be invoked.
parameters:
- callable
$handler
The handler to add. Must be suitable for use withregister_shutdown_function
. - mixed
$arguments
Argument(s) to pass to the handler on shutdown.
returns the Handler instance.
public Handler register( void )
Starts the Handler (makes its registered handlers "active").
returns the Handler instance.
public Handler throw( [int $types] )
Sets error types which should be intercepted and thrown as ErrorExceptions.
parameters:
- int
$types
The error types to be thrown. Defaults toE_ERROR|E_WARNING
; use0
to stop throwing.
returns the Handler instance.
public Handler unregister( void )
Stops the Handler (makes its registered handlers "inactive").
returns the Handler instance.
public mixed try( callable $callback [, mixed ...$arguments] )
Tries invoking a callback, using the registered exception handler(s) to handle any uncaught exceptions.
parameters:
- callable
$callback
The callback to invoke. - mixed
...$arguments
Argument(s) to pass to the callback.
returns the value returned from the callback.