From 9467fdc2bd28deaf1e3c6adf22935b1524b706e2 Mon Sep 17 00:00:00 2001 From: Woody Gilk Date: Thu, 11 Jun 2009 14:28:37 -0500 Subject: [PATCH] Cleaned up Validation::validate() a little and added comments --- system/classes/validation.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/system/classes/validation.php b/system/classes/validation.php index 7a67edd..cc679aa 100644 --- a/system/classes/validation.php +++ b/system/classes/validation.php @@ -86,17 +86,23 @@ class Validation extends ArrayObject { return $this; } - public function validate( array & $errors = array()) + /** + * Executes all validation rules. + * + * @param array error list + * @return boolean + */ + public function validate( & $errors) { // Data to validate $data = array(); - // Get the expected fields - $expected = array_keys($this->_rules); - // Assume nothing has been submitted $submitted = FALSE; + // Get the expected fields + $expected = array_keys($this->_rules); + foreach ($expected as $field) { if (isset($this[$field])) @@ -117,6 +123,9 @@ class Validation extends ArrayObject { // Overload the current array with the new one $this->exchangeArray($data); + // Make sure that the errors are an array + $errors = (array) $errors; + if ($submitted === FALSE) { // Because no data was submitted, validation will not be forced