summaryrefslogtreecommitdiff
path: root/README.md
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 /README.md
parent8ebb9ca9fbce0982e27296d5016d17d8b20962d6 (diff)
Implement `$fieldNames`, a way to overwrite field names to be more human friendly in error messages.
Diffstat (limited to 'README.md')
-rw-r--r--README.md11
1 files changed, 10 insertions, 1 deletions
diff --git a/README.md b/README.md
index 0eec3d4..1e39400 100644
--- a/README.md
+++ b/README.md
@@ -34,8 +34,9 @@ An example usage of Hird looks like this:
use Askonomm\Hird\Hird;
$fields = ['email' => 'asko@asko.dev'];
+$fieldNames = ['email' => 'E-mail'];
$rules = ['email' => 'required|email|len:5'];
-$hird = new Hird($fields, $rules);
+$hird = new Hird($fields, $rules, $fieldNames);
if ($hird->fails()) {
return $hird->errors();
@@ -48,6 +49,8 @@ You can also get the first error rather than all errors by using the method `$hi
If you wish to run the validation without needing to call `$hird->fails()`, you can instead call `$hird->validate()`.
+Another thing you may notice is the presence of `$fieldNames`, which is a way overwriting the field names for use within the error messages, so that `email` could become `E-mail` when shown to the user. If you don't care about this then you can entirely skip this as only the `$fields` and `$rules` are required for Hird to work.
+
## Built-in validators
There are a number of built-in validators available for use by default. If you want to remove a built-in validator, you can remove one using the `$hird->removeValidator('rule-name')` method.
@@ -113,6 +116,12 @@ use Asko\Hird\Validators\Validator;
class EmailValidator implements Validator
{
+ public function __construct(
+ private array $fields, // all fields data
+ private array $fieldNames, // names of fields
+ ){
+ }
+
/**
* Returns a boolean `true` when given `$value` is a valid e-mail
* address. Returns `false` otherwise.