Cleaned up Validation::validate() a little and added comments
This commit is contained in:
parent
675706a8b9
commit
9467fdc2bd
|
@ -86,17 +86,23 @@ class Validation extends ArrayObject {
|
||||||
return $this;
|
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 to validate
|
||||||
$data = array();
|
$data = array();
|
||||||
|
|
||||||
// Get the expected fields
|
|
||||||
$expected = array_keys($this->_rules);
|
|
||||||
|
|
||||||
// Assume nothing has been submitted
|
// Assume nothing has been submitted
|
||||||
$submitted = FALSE;
|
$submitted = FALSE;
|
||||||
|
|
||||||
|
// Get the expected fields
|
||||||
|
$expected = array_keys($this->_rules);
|
||||||
|
|
||||||
foreach ($expected as $field)
|
foreach ($expected as $field)
|
||||||
{
|
{
|
||||||
if (isset($this[$field]))
|
if (isset($this[$field]))
|
||||||
|
@ -117,6 +123,9 @@ class Validation extends ArrayObject {
|
||||||
// Overload the current array with the new one
|
// Overload the current array with the new one
|
||||||
$this->exchangeArray($data);
|
$this->exchangeArray($data);
|
||||||
|
|
||||||
|
// Make sure that the errors are an array
|
||||||
|
$errors = (array) $errors;
|
||||||
|
|
||||||
if ($submitted === FALSE)
|
if ($submitted === FALSE)
|
||||||
{
|
{
|
||||||
// Because no data was submitted, validation will not be forced
|
// Because no data was submitted, validation will not be forced
|
||||||
|
|
Loading…
Reference in a new issue