modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-06-04 23:19:58 +04:00
parent ba4a67658f
commit a7bcfe9ce6
1 changed files with 6 additions and 6 deletions

View File

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