ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ByTrying.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use Exception;
24use ILIAS\Data;
26
27class ByTrying implements Transformation
28{
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}
Builds data types.
Definition: Factory.php:36
getError()
@inheritDoc
Definition: ByTrying.php:60
transform($from)
@inheritDoc
Definition: ByTrying.php:68
__construct(private array $transformations, private Data\Factory $data_factory, protected ?Language\Language $lng=null)
Definition: ByTrying.php:40
error(string $a_errmsg)
A transformation is a function from one datatype to another.
getErrorMessage($value)
global $lng
Definition: privfeed.php:31