ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
DeriveTransformFromApplyTo.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
8 namespace ILIAS\Refinery;
9 
11 
13 {
18  abstract public function applyTo(Result $result) : Result;
19 
25  public function transform($from)
26  {
28  $result = $this->applyTo(new Result\Ok($from));
29  if (true === $result->isError()) {
30  $error = $result->error();
31 
32  if ($error instanceof \Exception) {
33  throw $error;
34  }
35 
36  throw new \Exception($error);
37  }
38  return $result->value();
39  }
40 }
value()
Get the encapsulated value.
isError()
Get to know if the result is an error.
$result
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:11
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:13
error()
Get the encapsulated error.