class ErrorControlChain (View source)

Class ErrorControlChain

Runs a set of steps, optionally suppressing uncaught errors or exceptions which would otherwise be fatal that occur in each step. If an error does occur, subsequent steps are normally skipped, but can optionally be run anyway.

Usage:

$chain = new ErrorControlChain(); $chain->then($callback1)->then($callback2)->thenIfErrored($callback3)->execute();

WARNING: This class is experimental and designed specifically for use pre-startup in main.php It will likely be heavily refactored before the release of 3.2

Properties

public static $fatal_errors
protected bool $error

Is there an error?

protected array $steps

List of steps

protected bool $suppression

True if errors should be hidden

protected $handleFatalErrors

We can't unregister_shutdown_function, so this acts as a flag to enable handling

protected $originalDisplayErrors

We overload display_errors to hide errors during execution, so we need to remember the original to restore to

protected Exception $lastException

Any exceptions passed through the chain

public static $transtable

Methods

public
bool
hasErrored()

Determine if an error has been found

public
setErrored($error)

No description

public
setSuppression(bool $suppression)

Sets whether errors are suppressed or not Notes:

  • Errors cannot be suppressed if not handling errors.

protected
setDisplayErrors(mixed $errors)

Set display_errors

protected
mixed
getDisplayErrors()

Get value of display_errors ini value

public
$this
then($callback, $onErrorState = false)

Add this callback to the chain of callbacks to call along with the state that $error must be in this point in the chain for the callback to be called

public
$this
thenWhileGood(callable $callback)

Request that the callback is invoked if not errored

public
$this
thenIfErrored(callable $callback)

Request that the callback is invoked on error

public
$this
thenAlways(callable $callback)

Request that the callback is invoked always

protected
bool
lastErrorWasFatal()

Return true if the last error was fatal

protected
lastErrorWasMemoryExhaustion()

No description

protected
translateMemstring($memString)

No description

public
handleFatalError()

No description

public
execute()

No description

protected
step()

No description

Details

bool hasErrored()

Determine if an error has been found

Return Value

bool

setErrored($error)

No description

Parameters

$error

setSuppression(bool $suppression)

Sets whether errors are suppressed or not Notes:

  • Errors cannot be suppressed if not handling errors.

  • Errors cannot be un-suppressed if original mode dis-allowed visible errors

Parameters

bool $suppression

protected setDisplayErrors(mixed $errors)

Set display_errors

Parameters

mixed $errors

protected mixed getDisplayErrors()

Get value of display_errors ini value

Return Value

mixed

$this then($callback, $onErrorState = false)

Add this callback to the chain of callbacks to call along with the state that $error must be in this point in the chain for the callback to be called

Parameters

$callback
  • The callback to call
$onErrorState
  • false if only call if no errors yet, true if only call if already errors, null for either

Return Value

$this

$this thenWhileGood(callable $callback)

Request that the callback is invoked if not errored

Parameters

callable $callback

Return Value

$this

$this thenIfErrored(callable $callback)

Request that the callback is invoked on error

Parameters

callable $callback

Return Value

$this

$this thenAlways(callable $callback)

Request that the callback is invoked always

Parameters

callable $callback

Return Value

$this

protected bool lastErrorWasFatal()

Return true if the last error was fatal

Return Value

bool

protected lastErrorWasMemoryExhaustion()

No description

protected translateMemstring($memString)

No description

Parameters

$memString

handleFatalError()

No description

execute()

No description

protected step()

No description