ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ByTrying.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 
3 /* Copyright (c) 2020 Nils Haagen <nils.haagen@concepts-and-training.de>, Extended GPL, see docs/LICENSE */
4 
5 namespace ILIAS\Refinery;
6 
11 use ILIAS\Data;
13 
14 class ByTrying implements Transformation
15 {
18  use ProblemBuilder;
19 
23  protected $transformations;
24 
28  protected $data_factory;
29 
33  protected $error;
34 
36  {
37  $this->transformations = $transformations;
38  $this->data_factory = $data_factory;
39  $this->error = function () {
41  'no valid constraints',
42  'no_valid_constraints'
43  );
44  };
45  }
46 
50  protected function getError()
51  {
52  return $this->error;
53  }
54 
58  public function transform($from)
59  {
60  foreach ($this->transformations as $transformation) {
61  $result = $this->data_factory->ok($from);
62  $result = $transformation->applyTo($result);
63  if ($result->isOK()) {
64  return $result->value();
65  }
66  }
67  throw new \Exception($this->getErrorMessage($from));
68  }
69 }
$result
transform($from)
Perform the transformation.Please use this for transformations. It&#39;s more performant than calling inv...
Definition: ByTrying.php:58
__construct(array $transformations, Data\Factory $data_factory, \ilLanguage $lng)
Definition: ByTrying.php:35
$lng
Builds data types.
Definition: Factory.php:19
getErrorMessage($value)
Get the problem message.
A transformation is a function from one datatype to another.