//========================= VALIDATION methods =======================
/** Main method for validating GET, POST and COOKIE data.
* To be called AFTER validateServerVars so that $this->validServerVars can be used as a context
* (like for browser specific sanitization)
* @param array $data, if magic_quotes_gpc slashes must be stripped beforehand
* @throws PntValidationException if $this->gpcValidationFatal with message about the last validation that failed
* @return array with valid data
*/
function ($data, $cookies=false, $context='') {
$result = array();
$this->error = false;
forEach($data as $key => $value) {
$errorMessage = $cookies
? $this->($key)
: $this->($key);
if ($errorMessage) {
$this->error = $cookies ? 'cookie name' : 'param name';
$this->($this->error, $context.$key, $errorMessage);
continue; //do not return the param or cookie with the invalid name
}
if (is_array($value)) {
$result[$key] = $this->($value, $cookies, $context.$key.'.');
} else {
$sanitizedValue = $this->($key, $value);
$errorMessage = $this->($key, $sanitizedValue);
if ($errorMessage) {
$this->($context.$key, $sanitizedValue, $errorMessage);
$this->error = $context.$key;
} else {
$result[$key] = $sanitizedValue;
}
}
}
if ($this->error && $this->gpcValidationFatal)
throw new PntValidationException("$this->gpcValidationFailed $this->error");
return $result;
}
|