ILIAS  release_7 Revision v7.30-3-g800a261c036
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
5namespace ILIAS\Refinery;
6
11use ILIAS\Data;
13
14class ByTrying implements Transformation
15{
19
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
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
transform($from)
Perform the transformation.Please use this for transformations. It's more performant than calling inv...
Definition: ByTrying.php:58
__construct(array $transformations, Data\Factory $data_factory, \ilLanguage $lng)
Definition: ByTrying.php:35
error($a_errmsg)
set error message @access public
language handling
A transformation is a function from one datatype to another.
getErrorMessage($value)
Get the problem message.
$lng