diff options
Diffstat (limited to 'src/Validators/RequiredValidator.php')
| -rw-r--r-- | src/Validators/RequiredValidator.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/Validators/RequiredValidator.php b/src/Validators/RequiredValidator.php new file mode 100644 index 0000000..4cf6bfc --- /dev/null +++ b/src/Validators/RequiredValidator.php @@ -0,0 +1,37 @@ +<?php + +namespace Askonomm\Bouncer\Validators; + +/** + * Implements a length validator that has a job of validating + * that a given string is of correct length. + * + * @author Asko Nomm <asko@bien.ee> + */ +class RequiredValidator implements Validator +{ + /** + * Returns a boolean `true` when given `$value` is present + * and not empty. Returns `false` otherwise. + * + * @param string $value + * @param mixed $modifier + * @return boolean + */ + public static function validate(string $value, mixed $modifier = null): bool + { + return isset($value) && $value !== ''; + } + + /** + * Composes the error message in case the validation fails. + * + * @param string $field + * @param mixed $modifier + * @return string + */ + public static function composeError(string $field, mixed $modifier = null): string + { + return "${field} is required."; + } +} |
