2008-03-02 04:00:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decorator for interchange that performs validations
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_ConfigSchema_InterchangeValidator
|
|
|
|
{
|
|
|
|
protected $interchange;
|
|
|
|
protected $validators = array();
|
2008-03-02 04:39:14 +00:00
|
|
|
protected $namespaceValidators = array();
|
|
|
|
protected $directiveVaildators = array();
|
|
|
|
protected $index = 0;
|
2008-03-02 04:00:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $interchange Instance of HTMLPurifier_ConfigSchema_Interchange
|
|
|
|
* to save changes to.
|
|
|
|
*/
|
|
|
|
public function __construct($interchange) {
|
|
|
|
$this->interchange = $interchange;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a HTMLPurifier_ConfigSchema_Validator to run when adding.
|
|
|
|
*/
|
|
|
|
public function addValidator($validator) {
|
2008-03-02 04:39:14 +00:00
|
|
|
$this->validators[$this->index++] = $validator;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register validators to be used only on directives
|
|
|
|
*/
|
|
|
|
public function addDirectiveValidator($validator) {
|
|
|
|
$this->directiveValidators[$this->index++] = $validator;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register validators to be used only on namespaces
|
|
|
|
*/
|
|
|
|
public function addNamespaceValidator($validator) {
|
|
|
|
$this->namespaceValidators[$this->index++] = $validator;
|
2008-03-02 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates and adds a namespace hash
|
|
|
|
*/
|
|
|
|
public function addNamespace($hash) {
|
2008-03-02 04:39:14 +00:00
|
|
|
for ($i = 0; $i < $this->index; $i++) {
|
|
|
|
if (isset($this->validators[$i])) $validator = $this->validators[$i];
|
|
|
|
elseif (isset($this->namespaceValidators[$i])) $validator = $this->namespaceValidators[$i];
|
|
|
|
else continue;
|
|
|
|
$validator->validate($hash, $this->interchange);
|
2008-03-02 04:00:43 +00:00
|
|
|
}
|
|
|
|
$this->interchange->addNamespace($hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates and adds a directive hash
|
|
|
|
*/
|
|
|
|
public function addDirective($hash) {
|
2008-03-02 04:39:14 +00:00
|
|
|
for ($i = 0; $i < $this->index; $i++) {
|
|
|
|
if (isset($this->validators[$i])) $validator = $this->validators[$i];
|
|
|
|
elseif (isset($this->directiveValidators[$i])) $validator = $this->directiveValidators[$i];
|
|
|
|
else continue;
|
|
|
|
$validator->validate($hash, $this->interchange);
|
2008-03-02 04:00:43 +00:00
|
|
|
}
|
|
|
|
$this->interchange->addDirective($hash);
|
|
|
|
}
|
|
|
|
}
|