ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ByTrying.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Refinery;
22 
23 use Exception;
24 use ILIAS\Data;
25 use ILIAS\Language;
26 
27 class ByTrying implements Transformation
28 {
31  use ProblemBuilder;
32 
34  private $error;
35 
40  public function __construct(
41  private array $transformations,
42  private Data\Factory $data_factory,
43  // $lng should not be null, however, there are circular dependencies.
44  // see ILIAS\Cache\Container\ActiveContainer::buildFinalTransformation
45  protected ?Language\Language $lng = null
46  ) {
47  $this->transformations = $transformations;
48  $this->data_factory = $data_factory;
49  $this->error = static function (): void {
51  'no valid constraints',
52  'no_valid_constraints'
53  );
54  };
55  }
56 
60  protected function getError(): callable
61  {
62  return $this->error;
63  }
64 
68  public function transform($from)
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  }
79 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(private array $transformations, private Data\Factory $data_factory, protected ?Language\Language $lng=null)
Definition: ByTrying.php:40
getErrorMessage($value)
global $lng
Definition: privfeed.php:31
A transformation is a function from one datatype to another.