interface CallSilencerInterface

Interface for calling closure in error-silenced environment.

Constants

ERROR_ARRAY

Optional constant parameter for {see getError()} to get error as original array.

ERROR_MESSAGE

Optional constant parameter for {see getError()} to get error message.

ERROR_TYPE

Optional constant parameter for {see getError()} to get error type.

ERROR_FILE

Optional constant parameter for {see getError()} to get error file.

ERROR_LINE

Optional constant parameter for {see getError()} to get error line.

Methods

create( Closure $closure = null, Closure $validator = null)

Static method to create class instance with optional closure and validator parameters.

$this
setClosure( Closure $invokable)

Sets the closure to invoke.

$this
setValidator( Closure $validator)

Sets the closure used to test validity of return value. When called, this closure is provided the return value of the invoked closure, as well the last raised error array (as first and second parameters).

$this
invoke( bool $restore = true)

Invoke closure in silenced environment.

bool
hasResult()

Returns true if a non-null value was returned from invoked closure.

mixed
getResult()

Get the return value invoked closure.

bool
isResultValid()

Returns type hinted value from validation closure.

bool
isResultTrue()

Returns true if the invoked closure return value is true (strict check).

bool
isResultFalse()

Returns true if the invoked closure return value is false (strict check).

bool
hasError()

Return true if an error was raised by invoking closure.

string[]|string
getError( string|null $index = self::ERROR_MESSAGE)

Returns the error raised by invoking closure.

Details

at line line 52
static CallSilencerInterface create( Closure $closure = null, Closure $validator = null)

Static method to create class instance with optional closure and validator parameters.

Parameters

Closure $closure A closure to call in silenced environment
Closure $validator A closure to call during return value validation

Return Value

CallSilencerInterface

at line line 61
$this setClosure( Closure $invokable)

Sets the closure to invoke.

Parameters

Closure $invokable A closure to call in silenced environment

Return Value

$this

at line line 71
$this setValidator( Closure $validator)

Sets the closure used to test validity of return value. When called, this closure is provided the return value of the invoked closure, as well the last raised error array (as first and second parameters).

Parameters

Closure $validator A closure to call during return value validation using {see isReturnValid()}

Return Value

$this

at line line 80
$this invoke( bool $restore = true)

Invoke closure in silenced environment.

Parameters

bool $restore Calls {see Silencer::restore()} to restore error level after calling closure if true

Return Value

$this

at line line 87
bool hasResult()

Returns true if a non-null value was returned from invoked closure.

Return Value

bool

at line line 94
mixed getResult()

Get the return value invoked closure.

Return Value

mixed

at line line 101
bool isResultValid()

Returns type hinted value from validation closure.

Return Value

bool

at line line 108
bool isResultTrue()

Returns true if the invoked closure return value is true (strict check).

Return Value

bool

at line line 115
bool isResultFalse()

Returns true if the invoked closure return value is false (strict check).

Return Value

bool

at line line 122
bool hasError()

Return true if an error was raised by invoking closure.

Return Value

bool

at line line 131
string[]|string getError( string|null $index = self::ERROR_MESSAGE)

Returns the error raised by invoking closure.

Parameters

string|null $index The index string to get from last error array, or return original error array

Return Value

string[]|string