ILIAS  release_8 Revision v8.23
DeriveTransformFromApplyTo.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: ByTrying.php:21
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: Result.php:14
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:16
error()
Get the encapsulated error.
ilErrorHandling $error
Definition: class.ilias.php:55