From 2e3271ff54a2f161c9924f926e68ec5dc15857d8 Mon Sep 17 00:00:00 2001 From: Asko Nomm Date: Sun, 27 Feb 2022 19:54:19 +0100 Subject: Make `validate` fn also be aware of the `$field`. This enables the creation of more complex validators, such as `unique:posts` where the `$field` might be used to determine a column in the `posts` table. --- src/Validators/EmailValidator.php | 2 +- src/Validators/LenValidator.php | 2 +- src/Validators/RequiredValidator.php | 2 +- src/Validators/Validator.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Validators/EmailValidator.php b/src/Validators/EmailValidator.php index d5654c0..180c22d 100644 --- a/src/Validators/EmailValidator.php +++ b/src/Validators/EmailValidator.php @@ -18,7 +18,7 @@ class EmailValidator implements Validator * @param mixed $modifier * @return boolean */ - public static function validate(mixed $value, mixed $modifier = null): bool + public static function validate(string $field, mixed $value, mixed $modifier = null): bool { return filter_var($value, FILTER_VALIDATE_EMAIL); } diff --git a/src/Validators/LenValidator.php b/src/Validators/LenValidator.php index f47168a..c5a152b 100644 --- a/src/Validators/LenValidator.php +++ b/src/Validators/LenValidator.php @@ -18,7 +18,7 @@ class LenValidator implements Validator * @param mixed $modifier * @return boolean */ - public static function validate(mixed $value, mixed $modifier = null): bool + public static function validate(string $field, mixed $value, mixed $modifier = null): bool { // If no modifier present then this validator will always validate. if (!$modifier) { diff --git a/src/Validators/RequiredValidator.php b/src/Validators/RequiredValidator.php index 82c18ec..acfcce5 100644 --- a/src/Validators/RequiredValidator.php +++ b/src/Validators/RequiredValidator.php @@ -18,7 +18,7 @@ class RequiredValidator implements Validator * @param mixed $modifier * @return boolean */ - public static function validate(mixed $value, mixed $modifier = null): bool + public static function validate(string $field, mixed $value, mixed $modifier = null): bool { return isset($value) && $value !== ''; } diff --git a/src/Validators/Validator.php b/src/Validators/Validator.php index 85aca30..8e5e994 100644 --- a/src/Validators/Validator.php +++ b/src/Validators/Validator.php @@ -4,6 +4,6 @@ namespace Askonomm\Hird\Validators; interface Validator { - public static function validate(mixed $value, mixed $modifier = null): bool; + public static function validate(string $field, mixed $value, mixed $modifier = null): bool; public static function composeError(string $field, mixed $modifier = null): string; } -- cgit v1.2.3