ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Refinery\Custom\Constraint Class Reference
+ Inheritance diagram for ILIAS\Refinery\Custom\Constraint:
+ Collaboration diagram for ILIAS\Refinery\Custom\Constraint:

Public Member Functions

 __construct (callable $is_ok, $error, Data\Factory $data_factory, \ILIAS\Language\Language $lng)
 If $error is a callable it needs to take two parameters: More...
 
 check ($value)
 @inheritDoc More...
 
 accepts ($value)
 @inheritDoc More...
 
 problemWith ($value)
 @inheritDoc More...
 
 applyTo (Result $result)
 @inheritDoc More...
 
- Public Member Functions inherited from ILIAS\Refinery\Constraint
 check ($value)
 Checks the provided value. More...
 
 accepts ($value)
 Tells if the provided value complies. More...
 
 problemWith ($value)
 Tells what the problem with the provided value is. More...
 
 applyTo (Result $result)
 Restricts a Result. More...
 
 withProblemBuilder (callable $builder)
 Get a constraint like this one with a builder for a custom error message. More...
 
- Public Member Functions inherited from ILIAS\Refinery\Transformation
 transform ($from)
 Perform the transformation. More...
 
 applyTo (Result $result)
 Perform the transformation and reify possible failures. More...
 
 __invoke ($from)
 Transformations should be callable. More...
 

Protected Member Functions

 getError ()
 @inheritDoc More...
 

Protected Attributes

Data Factory $data_factory
 
ILIAS Language Language $lng
 
 $is_ok
 
 $error
 

Detailed Description

Definition at line 30 of file Constraint.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Refinery\Custom\Constraint::__construct ( callable  $is_ok,
  $error,
Data\Factory  $data_factory,
\ILIAS\Language\Language  $lng 
)

If $error is a callable it needs to take two parameters:

  • one callback $txt($lng_id, ($value, ...)) that retrieves the lang var with the given id and uses sprintf to replace placeholder if more values are provide.
  • the $value for which the error message should be build.
Parameters
callable$is_ok
string | callable$error
Data\Factory$data_factory
\ILIAS\Language\Language$lng

Definition at line 55 of file Constraint.php.

56 {
57 $this->is_ok = $is_ok;
58 $this->error = $error;
59 $this->data_factory = $data_factory;
60 $this->lng = $lng;
61 }
ILIAS Language Language $lng
Definition: Constraint.php:37
error(string $a_errmsg)

References ILIAS\Refinery\Custom\Constraint\$data_factory, ILIAS\Refinery\Custom\Constraint\$error, ILIAS\Refinery\Custom\Constraint\$is_ok, ILIAS\Refinery\Custom\Constraint\$lng, error(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Member Function Documentation

◆ accepts()

ILIAS\Refinery\Custom\Constraint::accepts (   $value)
final

@inheritDoc

Implements ILIAS\Refinery\Constraint.

Definition at line 86 of file Constraint.php.

86 : bool
87 {
88 return call_user_func($this->is_ok, $value);
89 }

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

+ Here is the caller graph for this function:

◆ applyTo()

ILIAS\Refinery\Custom\Constraint::applyTo ( Result  $result)
final

@inheritDoc

Implements ILIAS\Refinery\Constraint.

Definition at line 106 of file Constraint.php.

106 : Result
107 {
108 if ($result->isError()) {
109 return $result;
110 }
111
112 $problem = $this->problemWith($result->value());
113 if ($problem !== null) {
114 $error = $this->data_factory->error($problem);
115 return $error;
116 }
117
118 return $result;
119 }
problemWith($value)
@inheritDoc
Definition: Constraint.php:94
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:29
isError()
Get to know if the result is an error.
value()
Get the encapsulated value.

References ILIAS\Refinery\Custom\Constraint\$error, ILIAS\Data\Result\isError(), ILIAS\Refinery\Custom\Constraint\problemWith(), and ILIAS\Data\Result\value().

+ Here is the call graph for this function:

◆ check()

ILIAS\Refinery\Custom\Constraint::check (   $value)
final

@inheritDoc

Implements ILIAS\Refinery\Constraint.

Definition at line 74 of file Constraint.php.

75 {
76 if (!$this->accepts($value)) {
77 throw new \UnexpectedValueException($this->getErrorMessage($value));
78 }
79
80 return null;
81 }
accepts($value)
@inheritDoc
Definition: Constraint.php:86
getErrorMessage($value)

References ILIAS\Refinery\Custom\Constraint\accepts(), and ILIAS\Refinery\getErrorMessage().

+ Here is the call graph for this function:

◆ getError()

ILIAS\Refinery\Custom\Constraint::getError ( )
protected

@inheritDoc

Definition at line 66 of file Constraint.php.

67 {
68 return $this->error;
69 }

References ILIAS\Refinery\Custom\Constraint\$error.

◆ problemWith()

ILIAS\Refinery\Custom\Constraint::problemWith (   $value)
final

@inheritDoc

Implements ILIAS\Refinery\Constraint.

Definition at line 94 of file Constraint.php.

94 : ?string
95 {
96 if (!$this->accepts($value)) {
97 return $this->getErrorMessage($value);
98 }
99
100 return null;
101 }

References ILIAS\Refinery\Custom\Constraint\accepts(), and ILIAS\Refinery\getErrorMessage().

Referenced by ILIAS\Refinery\Custom\Constraint\applyTo().

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

Field Documentation

◆ $data_factory

Data Factory ILIAS\Refinery\Custom\Constraint::$data_factory
protected

Definition at line 36 of file Constraint.php.

Referenced by ILIAS\Refinery\Custom\Constraint\__construct().

◆ $error

ILIAS\Refinery\Custom\Constraint::$error
protected

◆ $is_ok

ILIAS\Refinery\Custom\Constraint::$is_ok
protected

Definition at line 39 of file Constraint.php.

Referenced by ILIAS\Refinery\Custom\Constraint\__construct().

◆ $lng

ILIAS Language Language ILIAS\Refinery\Custom\Constraint::$lng
protected

The documentation for this class was generated from the following file: