50 if (!is_callable(
$error)) {
65 final public function check($value)
79 return call_user_func($this->is_ok, $value);
104 if ($problem !==
null) {
105 $error = $this->data_factory->error($problem);
117 $clone = clone $this;
130 return call_user_func($this->
error, $lng_closure, $value);
142 $args = func_get_args();
143 if (count($args) < 1) {
144 throw new \InvalidArgumentException(
145 "Expected an id of a lang var as first parameter"
148 $error = $this->lng->txt($args[0]);
149 if (count($args) > 1) {
151 for (
$i = 0;
$i < count($args);
$i++) {
153 if ((is_array($v) || is_object($v) || is_null($v))
154 && !method_exists($v,
"__toString")) {
157 } elseif (is_null($v)) {
160 $args[
$i] = get_class($v);
164 $error = call_user_func_array(
"sprintf", $args);
An exception for terminatinating execution or to throw for unit testing.
check($value)
Checks the provided value.Should not throw if accepts($value).UnexpectedValueException if value does ...
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
withProblemBuilder(callable $builder)
Get a constraint like this one with a builder for a custom error message.problemWith() must return an...
getErrorMessage($value)
Get the problem message.
applyTo(Result $result)
Restricts a Result.Must do nothing with the result if $result->isError(). Must replace the result wit...
problemWith($value)
Tells what the problem with the provided value is.Should return null if accepts($value)....
__construct(callable $is_ok, $error, Data\Factory $data_factory, \ilLanguage $lng)
If $error is a callable it needs to take two parameters:
error($a_errmsg)
set error message @access public
A result encapsulates a value or an error and simplifies the handling of those.
value()
Get the encapsulated value.
A constraint encodes some resrtictions on values.
trait DeriveTransformFromApplyTo
trait DeriveInvokeFromTransform