ILIAS  release_8 Revision v8.23
ILIAS\Refinery\ByTrying Class Reference
+ Inheritance diagram for ILIAS\Refinery\ByTrying:
+ Collaboration diagram for ILIAS\Refinery\ByTrying:

Public Member Functions

 __construct (array $transformations, Data\Factory $data_factory)
 
 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

array $transformations
 
Data Factory $data_factory
 
 $error
 

Detailed Description

Definition at line 26 of file ByTrying.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Refinery\ByTrying::__construct ( array  $transformations,
Data\Factory  $data_factory 
)
Parameters
Transformation[]$transformations
Data\Factory$data_factory

Definition at line 42 of file ByTrying.php.

References ILIAS\Refinery\ByTrying\$data_factory, and ILIAS\Refinery\ByTrying\$transformations.

43  {
44  $this->transformations = $transformations;
45  $this->data_factory = $data_factory;
46  $this->error = static function (): void {
47  throw new ConstraintViolationException(
48  'no valid constraints',
49  'no_valid_constraints'
50  );
51  };
52  }
Data Factory $data_factory
Definition: ByTrying.php:34

Member Function Documentation

◆ getError()

ILIAS\Refinery\ByTrying::getError ( )
protected

Definition at line 57 of file ByTrying.php.

References ILIAS\Refinery\ByTrying\$error.

57  : callable
58  {
59  return $this->error;
60  }

◆ transform()

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

Implements ILIAS\Refinery\Transformation.

Definition at line 65 of file ByTrying.php.

References ILIAS\Refinery\getErrorMessage().

66  {
67  foreach ($this->transformations as $transformation) {
68  $result = $this->data_factory->ok($from);
69  $result = $transformation->applyTo($result);
70  if ($result->isOK()) {
71  return $result->value();
72  }
73  }
74  throw new Exception($this->getErrorMessage($from));
75  }
getErrorMessage($value)
Get the problem message.
+ Here is the call graph for this function:

Field Documentation

◆ $data_factory

Data Factory ILIAS\Refinery\ByTrying::$data_factory
private

Definition at line 34 of file ByTrying.php.

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

◆ $error

ILIAS\Refinery\ByTrying::$error
private

Definition at line 36 of file ByTrying.php.

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

◆ $transformations

array ILIAS\Refinery\ByTrying::$transformations
private

Definition at line 33 of file ByTrying.php.

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


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