45 if (!is_callable(
$error)) {
46 $this->error =
function () use (
$error) {
60 final public function check($value)
74 return call_user_func($this->is_ok, $value);
99 if ($problem !== null) {
100 $error = $this->data_factory->error($problem);
112 $clone = clone $this;
125 return call_user_func($this->error, $lng_closure, $value);
137 $args = func_get_args();
138 if (count($args) < 1) {
139 throw new \InvalidArgumentException(
140 "Expected an id of a lang var as first parameter" 143 $error = $this->lng->txt($args[0]);
144 if (count($args) > 1) {
146 for (
$i = 0;
$i < count($args);
$i++) {
148 if ((is_array($v) || is_object($v) || is_null($v))
149 && !method_exists($v,
"__toString")) {
152 } elseif (is_null($v)) {
155 $args[
$i] = get_class($v);
159 $error = call_user_func_array(
"sprintf", $args);
value()
Get the encapsulated value.
isError()
Get to know if the result is an error.
check($value)
Checks the provided value.Should not throw if accepts($value).
A constraint encodes some resrtictions on values.
__construct(callable $is_ok, $error, Data\Factory $data_factory, \ilLanguage $lng)
If $error is a callable it needs to take two parameters:
A result encapsulates a value or an error and simplifies the handling of those.
getLngClosure()
Get the closure to be passed to the error-function that does i18n and sprintf.
accepts($value)
Tells if the provided value complies.bool
getErrorMessage($value)
Get the problem message.
problemWith($value)
Tells what the problem with the provided value is.Should return null if accepts($value).string|null
withProblemBuilder(callable $builder)
Get a constraint like this one with a builder for a custom error message.problemWith() must return an...
restrict(Result $result)
Restricts a Result.Must do nothing with the result if $result->isError(). Must replace the result wit...