mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-10 07:38:41 +00:00
b65942a2c5
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1607 48356398-32a2-884e-a903-53898d9a118a
40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Groups several validators together, but as an 'or': if the first
|
|
* one passes, we abort; if it throws an exception, we try the next validator,
|
|
* and the next. If all validators fail, we throw an exception.
|
|
*
|
|
* @note If no validators are registered, this validator automatically
|
|
* "passes".
|
|
*/
|
|
class HTMLPurifier_ConfigSchema_Validator_Or extends HTMLPurifier_ConfigSchema_Validator
|
|
{
|
|
|
|
protected $validators = array();
|
|
|
|
public function addValidator($validator) {
|
|
$this->validators[] = $validator;
|
|
}
|
|
|
|
public function validate(&$arr, $interchange) {
|
|
$exceptions = array();
|
|
$pass = false;
|
|
foreach ($this->validators as $validator) {
|
|
try {
|
|
$validator->validate($arr, $interchange);
|
|
} catch (HTMLPurifier_ConfigSchema_Exception $e) {
|
|
$exceptions[] = $e;
|
|
continue;
|
|
}
|
|
$exceptions = array();
|
|
break;
|
|
}
|
|
if ($exceptions) {
|
|
// I wonder how we can make the exceptions "lossless"
|
|
throw new HTMLPurifier_ConfigSchema_Exception('All validators failed: ' . implode(";\n", $exceptions));
|
|
}
|
|
}
|
|
|
|
}
|