ILIAS  trunk Revision v11.0_alpha-1846-g895b5f47236
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
DeriveTransformFromApplyTo.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Refinery;
22 
24 use 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 }
value()
Get the encapsulated value.
isError()
Get to know if the result is an error.
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:30
error()
Get the encapsulated error.
ilErrorHandling $error
Definition: class.ilias.php:69