-
Notifications
You must be signed in to change notification settings - Fork 0
API: The Handler Class
For building composable and reusable error handling strategies.
A log of debugging messages provided to this Handler.
Constructor.
- HandlerOptions
$options: Configuration options for this Handler.- bool
$debug: Enable debug mode? Defaults tofalse. - ? Psr\Log\LoggerInterface
$logger: Optional logger instance to send log messages to. - bool
$scream: Ignore the error control operator? Defaults tofalse. - int
$throwErrorExceptions: Php error types which should be thrown as ErrorExceptions. This is a disjunction ofE_*constants; you can use-1to throw all error types or0to throw none. Defaults to0. - int
$returnErrors: Php error types which should be returned as Faults. This is a disjunction ofE_*constants; you can use-1to throw all error types or0to throw none. Defaults to0.
- bool
Binds a callback to this Handler's registered error strategies.
Bound callables are intended for use with Handler->tryPipe() (or, in php 8.5+, with the |> operator). The callback is invoked only if the input value is not a Fault; otherise, the Fault is returned.
- callable
$if: The callback to invoke if the input value is not a Fault. The callback must accept a single argument, and is expected to return a Fault on failure or any other value on success.
- Closure: The callback, as a Closure.
Specifies error cases to be collected and returned as the given Fault.
- Fault
$as: The Fault to collect error cases as. - Fault|string
...$errorCases: The Faults and/or fully qualified Throwable classnames to collect.
- Handler: a new handler instance.
Specifies a default value to be returned in place of the given error cases.
- mixed
$to: The default value to return. - Fault|string|null
...$errorCases: The Faults and/or fully qualified Throwable classnames to default from. Omit (or passnull) to specify a default for a nullable or void return.
- Handler: a new handler instance.
Specifies error cases this Handler should ignore and returned as null.
- Fault|string
...$errorCases: The Faults and/or fully qualified Throwable classnames to ignore.
- Handler: a new handler instance.
Logs a fault or exception to this handler, or any message in debug mode.
If a PSR logger instance was configured, the message will also be logged there.
- Stringable|HasMessages|array|string|null $message
- array
$context: User-provided contextual information.
- Handler: a new handler instance.
Specifies a callback for processing return values on failure.
- callable
$failure: The callback to invoke on failure. The callback must accept a single argument, the Fault. Its return value is returned by the Handler.
- Handler: a new handler instance.
Specifies a callback for processing return values on success.
- callable
$failure: The callback to invoke on failure. The callback must accept a single argument. Its return value is returned by the Handler.
- Handler: a new handler instance.
Specifies new Handler Options.
- at\exceptable\Handler\Options
$options: New options. These will be merged with existing options.
- Handler: a new handler instance.
Specifies the number of times processing should be retried on the given error cases.
- int
$attempts: Number of retries to attempt. - Fault|string
...$errorCases: The Faults and/or fully qualified Throwable classnames to retry.
- Handler: a new handler instance.
Specifies error cases this Handler should (re)throw without modification.
- Fault|string
...$errorCases: The Faults and/or fully qualified Throwable classnames to throw.
- Handler: a new handler instance.
Invokes the given callable using any registered error strategies.
- callable
$callback: The callback to invoke. - mixed
...$args: Argument(s) to pass to the callback.
- Throwable: as configured.
- mixed: The callback's return value, on success.
- Fault: On failure.
Invokes the given callable using any registered error strategies, ignoring any failures.
- callable
$callback: The callback to invoke. - mixed
...$args: Argument(s) to pass to the callback.
- Throwable: as configured.
- mixed: The callback's return value, on success.
- null: On failure.
Invokes the given callables in turn, passing the return value of each as the argument for the next.
If a Fault is encountered, the process is aborted.
If desired, individual callable steps can be bound to specific Handlers via Handler->bind(). The process as a whole is wrapped with this Handler's registered error strategies.
- mixed
$initial: The initial value to pass to the first function in the chain. - callable
...$callback: The callbacks to invoke, in order. Each must accept a single mixed argument, and is expected to return mixed on success and a Fault on failure.
- Throwable: as configured.
- mixed: The callback's return value, on success.
- Fault: On failure.