Change required valitator to not allow empty values and add exists.

The exists validator do the same as the old required.
This commit is contained in:
KJ 2024-09-18 14:33:33 -04:00
parent 7baad428ec
commit 73b7b8f72a
1 changed files with 16 additions and 3 deletions

View File

@ -11,7 +11,8 @@
* | Regla | Descripción | * | Regla | Descripción |
* |----------+--------------------------------------------------------| * |----------+--------------------------------------------------------|
* | not | Niega la siguiente regla. Ej: not:float | * | not | Niega la siguiente regla. Ej: not:float |
* | required | Es requerido | * | exists | Es requerido; debe estar definido y puede estar vacío |
* | required | Es requerido; debe estar definido y no vacío |
* | number | Es numérico | * | number | Es numérico |
* | int | Es entero | * | int | Es entero |
* | float | Es un float | * | float | Es un float |
@ -90,7 +91,19 @@ class Validator {
} }
/** /**
* required * Comprueba que que esté definido/exista.
*
* @param mixed $subject
*
* @return bool
*/
public static function exists(mixed $subject): bool
{
return isset($subject);
}
/**
* Comprueba que que esté definido y no esté vacío.
* *
* @param mixed $subject * @param mixed $subject
* *
@ -98,7 +111,7 @@ class Validator {
*/ */
public static function required(mixed $subject): bool public static function required(mixed $subject): bool
{ {
return isset($subject); return isset($subject) && !empty($subject);
} }
/** /**