modifs.mineures sans commentaires
This commit is contained in:
parent
ba4a67658f
commit
a7bcfe9ce6
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue