summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAsko Nomm <asko@bien.ee>2022-02-23 18:01:02 +0100
committerAsko Nomm <asko@bien.ee>2022-02-23 18:01:02 +0100
commiteedb71682cc1f62bc9789945c952194e2f5efa03 (patch)
tree573a2265f2f3aaa38eaf30fa3a5d56eea8a3b57d /src
parent6b5b238e838116560e298deff4c9bcab140ac050 (diff)
Rename Bouncer to Hird
Diffstat (limited to 'src')
-rw-r--r--src/Hird.php (renamed from src/Bouncer.php)69
-rw-r--r--src/Validators/EmailValidator.php2
-rw-r--r--src/Validators/LenValidator.php2
-rw-r--r--src/Validators/RequiredValidator.php2
-rw-r--r--src/Validators/Validator.php2
5 files changed, 17 insertions, 60 deletions
diff --git a/src/Bouncer.php b/src/Hird.php
index 517315b..c1f5e4c 100644
--- a/src/Bouncer.php
+++ b/src/Hird.php
@@ -2,15 +2,15 @@
declare(strict_types=1);
-namespace Askonomm\Bouncer;
+namespace Askonomm\Hird;
-use Askonomm\Bouncer\Validators\Validator;
-use Askonomm\Bouncer\Validators\LenValidator;
-use Askonomm\Bouncer\Validators\EmailValidator;
-use Askonomm\Bouncer\Validators\RequiredValidator;
+use Askonomm\Hird\Validators\Validator;
+use Askonomm\Hird\Validators\LenValidator;
+use Askonomm\Hird\Validators\EmailValidator;
+use Askonomm\Hird\Validators\RequiredValidator;
/**
- * The Bouncer takes in an array of `$fields` and an array of
+ * Hird takes in an array of `$fields` and an array of
* `$rules`.
*
* The key of each item in the `$fields` array must correspond to the
@@ -28,64 +28,21 @@ use Askonomm\Bouncer\Validators\RequiredValidator;
* that rule as `len:8`, which would indicate using a `len` validator and passing
* a modifier with the value `8` to it.
*
- * Example usage of Bouncer:
+ * Example usage of Hird:
*
* ```php
* $fields = ['email' => 'asko@bien.ee'];
* $rules = ['email' => 'required|email'];
- * $bouncer = new Bouncer($fields, $rules);
+ * $hird = new Hird($fields, $rules);
*
- * if ($bouncer->fails()) {
- * return $bouncer->errors();
+ * if ($hird->fails()) {
+ * return $hird->errors();
* }
* ```
*
- * If you want to implement your own validators then simply create
- * a data structure that looks like this:
- *
- * ```php
- * // Create the validator
- * $validator = [
- * 'error' => function(string $field, $modifier): string {
- * return "${field} had some sort of an error.";
- * },
- * 'validates' => function(string $value, $modifier): bool {
- * // validate your $value here and return true if
- * // the validation succeeded, or false if there was
- * // an error, in which case the rule's error will be
- * // added to the array of errors used by Bouncer.
- * }
- * ];
- *
- * // Add validator to Bouncer
- * $bouncer = new Bouncer($fields, $rules, [
- * 'rule-name' => $validator
- * ]);
- * ```
- *
- * If you want to also use the default validators, and add yours as an extra,
- * simply join the array of your validators with the array that you get from
- * `$bouncer->defaultValidators()`, for example:
- *
- * ```php
- * $validators = [
- * ...$this->defaultValidators(),
- * 'rule-name' => $validator,
- * ]);
- *
- * $bouncer = new Bouncer($fields, $rules, $validators);
- * ```
- *
- * Additionally, you can register your own validators via the
- * `$bouncer->registerValidator` function like this:
- *
- * ```php
- * $bouncer->registerValidator('rule-name', $validator]);
- * ```
- *
* @author Asko Nomm <asko@bien.ee>
*/
-class Bouncer
+class Hird
{
private array $errors = [];
private array $validators = [];
@@ -101,9 +58,9 @@ class Bouncer
/**
* Registers the default, built-in validators.
*
- * @return array
+ * @return void
*/
- public function registerDefaultValidators(): void
+ private function registerDefaultValidators(): void
{
$this->registerValidator('len', (new LenValidator));
$this->registerValidator('email', (new EmailValidator));
diff --git a/src/Validators/EmailValidator.php b/src/Validators/EmailValidator.php
index d0e87fc..d5654c0 100644
--- a/src/Validators/EmailValidator.php
+++ b/src/Validators/EmailValidator.php
@@ -1,6 +1,6 @@
<?php
-namespace Askonomm\Bouncer\Validators;
+namespace Askonomm\Hird\Validators;
/**
* Implements an e-mail validator that has a job
diff --git a/src/Validators/LenValidator.php b/src/Validators/LenValidator.php
index 54fe234..f47168a 100644
--- a/src/Validators/LenValidator.php
+++ b/src/Validators/LenValidator.php
@@ -1,6 +1,6 @@
<?php
-namespace Askonomm\Bouncer\Validators;
+namespace Askonomm\Hird\Validators;
/**
* Implements a length validator that has a job of validating
diff --git a/src/Validators/RequiredValidator.php b/src/Validators/RequiredValidator.php
index 8e205f9..82c18ec 100644
--- a/src/Validators/RequiredValidator.php
+++ b/src/Validators/RequiredValidator.php
@@ -1,6 +1,6 @@
<?php
-namespace Askonomm\Bouncer\Validators;
+namespace Askonomm\Hird\Validators;
/**
* Implements a length validator that has a job of validating
diff --git a/src/Validators/Validator.php b/src/Validators/Validator.php
index 2d3a948..85aca30 100644
--- a/src/Validators/Validator.php
+++ b/src/Validators/Validator.php
@@ -1,6 +1,6 @@
<?php
-namespace Askonomm\Bouncer\Validators;
+namespace Askonomm\Hird\Validators;
interface Validator
{