ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ILIAS\Data\Result Interface Reference

A result encapsulates a value or an error and simplifies the handling of those. More...

+ Inheritance diagram for ILIAS\Data\Result:
+ Collaboration diagram for ILIAS\Data\Result:

Public Member Functions

 isOK ()
 Get to know if the result is ok. More...
 
 value ()
 Get the encapsulated value. More...
 
 isError ()
 Get to know if the result is an error. More...
 
 error ()
 Get the encapsulated error. More...
 
 valueOr ($default)
 Get the encapsulated value or the supplied default if result is an error. More...
 
 map (callable $f)
 Create a new result where the contained value is modified with $f. More...
 
 then (callable $f)
 Get a new result from the callable or do nothing if this is an error. More...
 
 except (callable $f)
 Feed the error into a callable and replace this with the result or do nothing if this is a value. More...
 

Detailed Description

A result encapsulates a value or an error and simplifies the handling of those.

To be implemented as immutable object.

Definition at line 11 of file Result.php.

Member Function Documentation

◆ error()

ILIAS\Data\Result::error ( )

Get the encapsulated error.

Exceptions
LogicExceptionif isOK
Returns
Exception|string

Implemented in ILIAS\Data\Result\Error, and ILIAS\Data\Result\Ok.

◆ except()

ILIAS\Data\Result::except ( callable  $f)

Feed the error into a callable and replace this with the result or do nothing if this is a value.

If null is returned from $f, the error in the result is not touched.

Does nothing if !isError.

Parameters
callable$fstring| -> Result|null
Exceptions
UnexpectedValueExceptionIf callable returns no instance of Result
Returns
Result

Implemented in ILIAS\Data\Result\Ok, and ILIAS\Data\Result\Error.

◆ isError()

ILIAS\Data\Result::isError ( )

Get to know if the result is an error.

Returns
bool

Implemented in ILIAS\Data\Result\Error, and ILIAS\Data\Result\Ok.

Referenced by ILIAS\Validation\Constraints\Custom\restrict().

+ Here is the caller graph for this function:

◆ isOK()

ILIAS\Data\Result::isOK ( )

Get to know if the result is ok.

Returns
bool

Implemented in ILIAS\Data\Result\Error, and ILIAS\Data\Result\Ok.

◆ map()

ILIAS\Data\Result::map ( callable  $f)

Create a new result where the contained value is modified with $f.

Does nothing if !isOK.

Parameters
callable$fmixed -> mixed
Returns
Result

Implemented in ILIAS\Data\Result\Error, and ILIAS\Data\Result\Ok.

◆ then()

ILIAS\Data\Result::then ( callable  $f)

Get a new result from the callable or do nothing if this is an error.

If null is returned from $f, the result is not touched.

Does nothing if !isOK. This is monadic bind.

Parameters
callable$fmixed -> Result|null
Exceptions
UnexpectedValueExceptionIf callable returns no instance of Result
Returns
Result

Implemented in ILIAS\Data\Result\Error, and ILIAS\Data\Result\Ok.

◆ value()

ILIAS\Data\Result::value ( )

Get the encapsulated value.

Exceptions
Exceptionif !isOK, will either throw the contained exception or a NotOKException if a string is contained as error.
Returns
mixed

Implemented in ILIAS\Data\Result\Error, and ILIAS\Data\Result\Ok.

Referenced by ILIAS\Validation\Constraints\Custom\restrict().

+ Here is the caller graph for this function:

◆ valueOr()

ILIAS\Data\Result::valueOr (   $default)

Get the encapsulated value or the supplied default if result is an error.

Parameters
default
Returns
mixed

Implemented in ILIAS\Data\Result\Error, and ILIAS\Data\Result\Ok.


The documentation for this interface was generated from the following file: