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