From 57518b03cbf19b8a714d6fcb573f71cb921005e3 Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Mon, 25 Sep 2023 17:29:52 +0300 Subject: Implement `$fieldNames`, a way to overwrite field names to be more human friendly in error messages. --- src/Validators/LenValidator.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/Validators/LenValidator.php') diff --git a/src/Validators/LenValidator.php b/src/Validators/LenValidator.php index ca4e486..3fa6fbf 100644 --- a/src/Validators/LenValidator.php +++ b/src/Validators/LenValidator.php @@ -12,6 +12,12 @@ namespace Asko\Hird\Validators; */ class LenValidator implements Validator { + public function __construct( + private array $fields, + private array $fieldNames, + ) { + } + /** * Returns a boolean `true` when given `$value` is as long as * required. Returns `false` otherwise. @@ -43,6 +49,6 @@ class LenValidator implements Validator */ public function composeError(string $field, mixed $modifier = null): string { - return "{$field} is shorter than the required {$modifier} characters."; + return "{$this->fieldNames[$field]} is shorter than the required {$modifier} characters."; } } -- cgit v1.2.3