ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DeriveTransformFromApplyTo.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Refinery;
22
24use Exception;
25
27{
31 abstract public function applyTo(Result $result): Result;
32
36 public function transform($from)
37 {
39 $result = $this->applyTo(new Result\Ok($from));
40 if (true === $result->isError()) {
41 $error = $result->error();
42
43 if ($error instanceof Exception) {
44 throw $error;
45 }
46
47 throw new Exception($error);
48 }
49 return $result->value();
50 }
51}
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
ilErrorHandling $error
Definition: class.ilias.php:69
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:29
isError()
Get to know if the result is an error.
value()
Get the encapsulated value.
error()
Get the encapsulated error.
applyTo(Result $result)
@inheritDoc