ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Refinery\ByTrying Class Reference
+ Inheritance diagram for ILIAS\Refinery\ByTrying:
+ Collaboration diagram for ILIAS\Refinery\ByTrying:

Public Member Functions

 __construct (private array $transformations, private Data\Factory $data_factory, protected ?Language\Language $lng=null)
 
 transform ($from)
 @inheritDoc More...
 
- Public Member Functions inherited from ILIAS\Refinery\Transformation
 transform ($from)
 Perform the transformation. More...
 
 applyTo (Result $result)
 Perform the transformation and reify possible failures. More...
 
 __invoke ($from)
 Transformations should be callable. More...
 

Protected Member Functions

 getError ()
 @inheritDoc More...
 

Private Attributes

 $error
 

Detailed Description

Definition at line 27 of file ByTrying.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Refinery\ByTrying::__construct ( private array  $transformations,
private Data\Factory  $data_factory,
protected ?Language\Language  $lng = null 
)
Parameters
Transformation[]$transformations
Data\Factory$data_factory

Definition at line 40 of file ByTrying.php.

46 {
47 $this->transformations = $transformations;
48 $this->data_factory = $data_factory;
49 $this->error = static function (): void {
50 throw new ConstraintViolationException(
51 'no valid constraints',
52 'no_valid_constraints'
53 );
54 };
55 }
error(string $a_errmsg)

References error().

+ Here is the call graph for this function:

Member Function Documentation

◆ getError()

ILIAS\Refinery\ByTrying::getError ( )
protected

@inheritDoc

Definition at line 60 of file ByTrying.php.

60 : callable
61 {
62 return $this->error;
63 }

References ILIAS\Refinery\ByTrying\$error.

◆ transform()

ILIAS\Refinery\ByTrying::transform (   $from)

@inheritDoc

Implements ILIAS\Refinery\Transformation.

Definition at line 68 of file ByTrying.php.

69 {
70 foreach ($this->transformations as $transformation) {
71 $result = $this->data_factory->ok($from);
72 $result = $transformation->applyTo($result);
73 if ($result->isOK()) {
74 return $result->value();
75 }
76 }
77 throw new Exception($this->getErrorMessage($from));
78 }
getErrorMessage($value)

References ILIAS\Refinery\getErrorMessage().

+ Here is the call graph for this function:

Field Documentation

◆ $error

ILIAS\Refinery\ByTrying::$error
private

Definition at line 34 of file ByTrying.php.

Referenced by ILIAS\Refinery\ByTrying\getError().


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