summaryrefslogtreecommitdiff
path: root/src/Validators/RequiredValidator.php
diff options
context:
space:
mode:
authorAsko Nõmm <asko@repl.ee>2023-09-25 17:29:52 +0300
committerAsko Nõmm <asko@repl.ee>2023-09-25 17:29:52 +0300
commit57518b03cbf19b8a714d6fcb573f71cb921005e3 (patch)
tree240509fd84f023f289a83577a735fa82fac879f4 /src/Validators/RequiredValidator.php
parent8ebb9ca9fbce0982e27296d5016d17d8b20962d6 (diff)
Implement `$fieldNames`, a way to overwrite field names to be more human friendly in error messages.
Diffstat (limited to 'src/Validators/RequiredValidator.php')
-rw-r--r--src/Validators/RequiredValidator.php8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/Validators/RequiredValidator.php b/src/Validators/RequiredValidator.php
index 48bc28b..404b189 100644
--- a/src/Validators/RequiredValidator.php
+++ b/src/Validators/RequiredValidator.php
@@ -12,6 +12,12 @@ namespace Asko\Hird\Validators;
*/
class RequiredValidator implements Validator
{
+ public function __construct(
+ private array $fields,
+ private array $fieldNames,
+ ) {
+ }
+
/**
* Returns a boolean `true` when given `$value` is present
* and not empty. Returns `false` otherwise.
@@ -34,6 +40,6 @@ class RequiredValidator implements Validator
*/
public function composeError(string $field, mixed $modifier = null): string
{
- return "{$field} is required.";
+ return "{$this->fieldNames[$field]} is required.";
}
}