Oihana PHP

ThrowableTrait

Provides a configurable "throwable" behavior to models.

Mix this trait in when a model should let callers choose between fail-fast and silent error handling. Methods of the host class read the public $throwable flag to decide whether to raise an exception or degrade gracefully (e.g. return null/false). The flag can be set directly or hydrated from an initialization array via initializeThrowable().

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

THROWABLE  : string = 'throwable'
The `throwable` key used in initialization arrays.

Properties

$throwable  : bool
Whether the host methods should throw exceptions instead of failing silently.

Methods

initializeThrowable()  : static
Initializes the `$throwable` flag from an initialization array.

Constants

THROWABLE

The `throwable` key used in initialization arrays.

public string THROWABLE = 'throwable'

Properties

$throwable

Whether the host methods should throw exceptions instead of failing silently.

public bool $throwable = false

Methods

initializeThrowable()

Initializes the `$throwable` flag from an initialization array.

public initializeThrowable([array<string, mixed> $init = [] ]) : static

Read from the self::THROWABLE key when present; otherwise the current value is kept.

Parameters
$init : array<string, mixed> = []

Initialization options (key: throwable).

Return values
static

The current instance, for fluent chaining.

On this page

Search results