ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
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)
 
- Public Member Functions inherited from ILIAS\Refinery\Transformation
 applyTo (Result $result)
 Perform the transformation and reify possible failures. More...
 
 __invoke ($from)
 Transformations should be callable. More...
 

Protected Member Functions

 getError ()
 

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  }

Member Function Documentation

◆ getError()

ILIAS\Refinery\ByTrying::getError ( )
protected

Definition at line 60 of file ByTrying.php.

References ILIAS\Refinery\ByTrying\$error.

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

◆ transform()

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

Implements ILIAS\Refinery\Transformation.

Definition at line 68 of file ByTrying.php.

References ILIAS\Refinery\getErrorMessage().

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)
+ 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: