class CallSilencer implements CallSilencerInterface

Implementation for calling closure in error-silenced environment.

Methods

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

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

$this
setClosure( Closure $closure)

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 50
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 72
$this setClosure( Closure $closure)

Sets the closure to invoke.

Parameters

Closure $closure A closure to call in silenced environment

Return Value

$this

at line line 87
$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 103
$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

Exceptions

InvocationException If closure throws exception

at line line 135
bool hasResult()

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

Return Value

bool

at line line 145
mixed getResult()

Get the return value invoked closure.

Return Value

mixed

at line line 157
bool isResultValid()

Returns type hinted value from validation closure.

Return Value

bool

Exceptions

ResultValidatorException If no validator closure has been assigned

at line line 171
bool isResultTrue()

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

Return Value

bool

at line line 181
bool isResultFalse()

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

Return Value

bool

at line line 191
bool hasError()

Return true if an error was raised by invoking closure.

Return Value

bool

at line line 203
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