ILIAS  release_8 Revision v8.24
ByTrying.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
23use Exception;
24use ILIAS\Data;
25
26class ByTrying implements Transformation
27{
31
33 private array $transformations;
36 private $error;
37
43 {
44 $this->transformations = $transformations;
45 $this->data_factory = $data_factory;
46 $this->error = static function (): void {
48 'no valid constraints',
49 'no_valid_constraints'
50 );
51 };
52 }
53
57 protected function getError(): callable
58 {
59 return $this->error;
60 }
61
65 public function transform($from)
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 }
76}
Builds data types.
Definition: Factory.php:21
getError()
@inheritDoc
Definition: ByTrying.php:57
transform($from)
@inheritDoc
Definition: ByTrying.php:65
Data Factory $data_factory
Definition: ByTrying.php:34
__construct(array $transformations, Data\Factory $data_factory)
Definition: ByTrying.php:42
error(string $a_errmsg)
A transformation is a function from one datatype to another.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: ByTrying.php:21
getErrorMessage($value)
Get the problem message.