diff --git a/nur_src/b/ValueException.php b/nur_src/b/ValueException.php index 5dc47df..4cba1cb 100644 --- a/nur_src/b/ValueException.php +++ b/nur_src/b/ValueException.php @@ -9,22 +9,22 @@ use nur\A; */ class ValueException extends UserException { /** Retourner $value si elle n'est pas false. sinon lancer une exception */ - static final function check_nf($value, $message=null) { - if ($value !== false) return $value; + static final function check_nf($value, $message=null, bool $required=true) { + if ($value !== false || !$required) return $value; if ($message === null) $message = "value must not be false"; throw new self($message); } /** Retourner $value si elle n'est pas null. sinon lancer une exception */ - static final function check_nn($value, $message=null) { - if ($value !== null) return $value; + static final function check_nn($value, $message=null, bool $required=true) { + if ($value !== null || !$required) return $value; if ($message === null) $message = "value must not be null"; throw new self($message); } /** Retourner $value si elle n'est ni null ni false. sinon lancer une exception */ - static final function check_nz($value, $message=null) { - if ($value !== false && $value !== null) return $value; + static final function check_nz($value, $message=null, bool $required=true) { + if (($value !== false && $value !== null) || !$required) return $value; if ($message === null) $message = "value must not be false nor null"; throw new ValueException($message); }