Cleaned up Validation::validate() a little and added comments

This commit is contained in:
Woody Gilk 2009-06-11 14:28:37 -05:00
parent 675706a8b9
commit 9467fdc2bd

View file

@ -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