From a4642d17e0e1ea018b128efdcc3db281461458b1 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Wed, 4 Apr 2018 15:21:13 -0700 Subject: Move custom libs to the source tree --- libs/SimpleValidator/Validator.php | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 libs/SimpleValidator/Validator.php (limited to 'libs/SimpleValidator/Validator.php') diff --git a/libs/SimpleValidator/Validator.php b/libs/SimpleValidator/Validator.php new file mode 100644 index 00000000..30015dc6 --- /dev/null +++ b/libs/SimpleValidator/Validator.php @@ -0,0 +1,44 @@ +data = $data; + $this->validators = $validators; + } + + public function execute() + { + $result = true; + + foreach ($this->validators as $validator) { + if (! $validator->execute($this->data)) { + $this->addError($validator->getField(), $validator->getErrorMessage()); + $result = false; + } + } + + return $result; + } + + public function addError($field, $message) + { + if (! isset($this->errors[$field])) { + $this->errors[$field] = array(); + } + + $this->errors[$field][] = $message; + } + + public function getErrors() + { + return $this->errors; + } +} -- cgit v1.2.3