ILIAS  release_7 Revision v7.30-3-g800a261c036
ILIAS\Refinery Namespace Reference

Namespaces

namespace  Container
 
namespace  Custom
 
namespace  DateTime
 
namespace  In
 
namespace  Integer
 
namespace  KindlyTo
 
namespace  Logical
 
namespace  Numeric
 
namespace  Password
 
namespace  String
 
namespace  To
 
namespace  URI
 

Data Structures

class  ByTrying
 
interface  Constraint
 A constraint encodes some resrtictions on values. More...
 
class  ConstraintViolationException
 
class  Factory
 
class  IsNull
 
interface  Transformation
 A transformation is a function from one datatype to another. More...
 

Functions

 applyTo (Result $result)
 
 __invoke ($from)
 
 withProblemBuilder (callable $builder)
 
 getErrorMessage ($value)
 Get the problem message. More...
 
 getLngClosure ()
 Get the closure to be passed to the error-function that does i18n and sprintf. More...
 

Variables

trait DeriveApplyToFromTransform
 
trait DeriveInvokeFromTransform
 
trait DeriveTransformFromApplyTo
 
trait ProblemBuilder
 

Detailed Description

Function Documentation

◆ __invoke()

ILIAS\Refinery\__invoke (   $from)
Exceptions

InvalidArgumentException if the argument could not be transformed

Parameters
mixed$from
Returns
mixed

Definition at line 26 of file DeriveInvokeFromTransform.php.

27 {
28 return $this->transform($from);
29 }

◆ applyTo()

ILIAS\Refinery\applyTo ( Result  $result)
Parameters
Result$result
Returns
Result

Definition at line 25 of file DeriveApplyToFromTransform.php.

25 : Result
26 {
27 try {
28 $value = $this->transform($result->value());
29 } catch (\Exception $exception) {
30 return new Result\Error($exception);
31 }
32
33 return new Result\Ok($value);
34 }
$result
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:12

References $result.

◆ getErrorMessage()

ILIAS\Refinery\getErrorMessage (   $value)
final

Get the problem message.

Returns
string

Definition at line 31 of file ProblemBuilder.php.

32 {
33 $error = $this->getError();
34 if (!is_callable($error)) {
35 return (string) $error;
36 }
37 $lng_closure = $this->getLngClosure();
38 return call_user_func($this->error, $lng_closure, $value);
39 }
getError()
returns error @access public
error($a_errmsg)
set error message @access public
getLngClosure()
Get the closure to be passed to the error-function that does i18n and sprintf.

References error(), getError(), and ILIAS\Refinery\getLngClosure().

Referenced by ILIAS\Refinery\Custom\Constraint\check(), ILIAS\Refinery\Custom\Constraint\problemWith(), and ILIAS\Refinery\ByTrying\transform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLngClosure()

ILIAS\Refinery\getLngClosure ( )
finalprotected

Get the closure to be passed to the error-function that does i18n and sprintf.

Returns
\Closure

Definition at line 47 of file ProblemBuilder.php.

48 {
49 return function () {
50 $args = func_get_args();
51 if (count($args) < 1) {
52 throw new \InvalidArgumentException(
53 "Expected an id of a lang var as first parameter"
54 );
55 }
56 $error = $this->lng->txt($args[0]);
57 if (count($args) > 1) {
58 $args[0] = $error;
59 for ($i = 0; $i < count($args); $i++) {
60 $v = $args[$i];
61 if ((is_array($v) || is_object($v) || is_null($v))
62 && !method_exists($v, "__toString")) {
63 if (is_array($v)) {
64 $args[$i] = "array";
65 } elseif (is_null($v)) {
66 $args[$i] = "null";
67 } else {
68 $args[$i] = get_class($v);
69 }
70 }
71 }
72 $error = call_user_func_array("sprintf", $args);
73 }
74 return $error;
75 };
76 }
$i
Definition: metadata.php:24

References $i.

Referenced by MyValidationConstraintsConstraint\_getLngClosure(), and ILIAS\Refinery\getErrorMessage().

+ Here is the caller graph for this function:

◆ withProblemBuilder()

ILIAS\Refinery\withProblemBuilder ( callable  $builder)
final

Definition at line 19 of file ProblemBuilder.php.

20 {
21 $clone = clone $this;
22 $clone->error = $builder;
23 return $clone;
24 }
$builder
Definition: parser.php:5

References $builder.

Variable Documentation

◆ DeriveApplyToFromTransform

trait ILIAS::Refinery\DeriveApplyToFromTransform
Initial value:
{
abstract public function transform($from)

Definition at line 12 of file DeriveApplyToFromTransform.php.

◆ DeriveInvokeFromTransform

trait ILIAS::Refinery\DeriveInvokeFromTransform
Initial value:
{
abstract public function transform($from)

Definition at line 12 of file DeriveInvokeFromTransform.php.

◆ DeriveTransformFromApplyTo

trait ILIAS::Refinery\DeriveTransformFromApplyTo
Initial value:
{
abstract public function applyTo(Result $result) : Result

Definition at line 12 of file DeriveTransformFromApplyTo.php.

◆ ProblemBuilder

trait ILIAS::Refinery\ProblemBuilder
Initial value:
{
abstract protected function getError()

Definition at line 9 of file ProblemBuilder.php.