ILIAS  release_8 Revision v8.23
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, ilLanguage $lng)
 If $error is a callable it needs to take two parameters: More...
 
 check ($value)
 
 accepts ($value)
 
 problemWith ($value)
 
 applyTo (Result $result)
 
- Public Member Functions inherited from ILIAS\Refinery\Constraint
 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...
 
 __invoke ($from)
 Transformations should be callable. More...
 

Protected Member Functions

 getError ()
 

Protected Attributes

Data Factory $data_factory
 
ilLanguage $lng
 
 $is_ok
 
 $error
 

Detailed Description

Definition at line 31 of file Constraint.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Refinery\Custom\Constraint::__construct ( callable  $is_ok,
  $error,
Data\Factory  $data_factory,
ilLanguage  $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
ilLanguage$lng

Definition at line 56 of file Constraint.php.

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

57  {
58  $this->is_ok = $is_ok;
59  $this->error = $error;
60  $this->data_factory = $data_factory;
61  $this->lng = $lng;
62  }
+ Here is the call graph for this function:

Member Function Documentation

◆ accepts()

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

Implements ILIAS\Refinery\Constraint.

Definition at line 87 of file Constraint.php.

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

87  : bool
88  {
89  return call_user_func($this->is_ok, $value);
90  }
+ Here is the caller graph for this function:

◆ applyTo()

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

Implements ILIAS\Refinery\Constraint.

Definition at line 107 of file Constraint.php.

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

107  : Result
108  {
109  if ($result->isError()) {
110  return $result;
111  }
112 
113  $problem = $this->problemWith($result->value());
114  if ($problem !== null) {
115  $error = $this->data_factory->error($problem);
116  return $error;
117  }
118 
119  return $result;
120  }
+ Here is the call graph for this function:

◆ check()

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

Implements ILIAS\Refinery\Constraint.

Definition at line 75 of file Constraint.php.

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

76  {
77  if (!$this->accepts($value)) {
78  throw new \UnexpectedValueException($this->getErrorMessage($value));
79  }
80 
81  return null;
82  }
getErrorMessage($value)
Get the problem message.
+ Here is the call graph for this function:

◆ getError()

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

Definition at line 67 of file Constraint.php.

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

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

◆ problemWith()

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

Implements ILIAS\Refinery\Constraint.

Definition at line 95 of file Constraint.php.

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

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

95  : ?string
96  {
97  if (!$this->accepts($value)) {
98  return $this->getErrorMessage($value);
99  }
100 
101  return null;
102  }
getErrorMessage($value)
Get the problem message.
+ 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

◆ $error

◆ $is_ok

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

◆ $lng


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