From f355e93f363eabd6ba05fe870632d13ffc224123 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Fri, 19 Jul 2024 14:00:28 -0400 Subject: [PATCH] Feat: Adding multiple from version 0.33 --- src/Http/Validator/Multiple.php | 115 ++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/Http/Validator/Multiple.php diff --git a/src/Http/Validator/Multiple.php b/src/Http/Validator/Multiple.php new file mode 100644 index 00000000..4c919377 --- /dev/null +++ b/src/Http/Validator/Multiple.php @@ -0,0 +1,115 @@ +addRule($rule); + } + + $this->type = $type; + } + /** + * Add rule + * + * Add a new rule to the end of the rules containing array + * + * @param Validator $rule + * @return $this + */ + public function addRule(Validator $rule) + { + $this->rules[] = $rule; + + return $this; + } + + /** + * Get Description + * + * Returns validator description + * + * @return string + */ + public function getDescription(): string + { + $description = ''; + foreach ($this->rules as $key => $rule) { + $description .= ++$key . '. ' . $rule->getDescription() . " \n"; + } + + return $description; + } + + /** + * Is valid + * + * Validation will pass when all rules are valid if only one of the rules is invalid validation will fail. + * + * @param mixed $value + * @return bool + */ + public function isValid(mixed $value): bool + { + foreach ($this->rules as $rule) { /* @var $rule Validator */ + if (false === $rule->isValid($value)) { + return false; + } + } + + return true; + } + + /** + * Get Type + * + * Returns validator type. + * + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * Is array + * + * Function will return true if object is array. + * + * @return bool + */ + public function isArray(): bool + { + return true; + } +}