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();
|
2008-03-04 04:13:07 +00:00
|
|
|
protected $directiveValidators = array();
|
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-04 04:13:07 +00:00
|
|
|
$this->addNamespaceValidator($validator);
|
|
|
|
$this->addDirectiveValidator($validator);
|
2008-03-02 04:39:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register validators to be used only on directives
|
|
|
|
*/
|
|
|
|
public function addDirectiveValidator($validator) {
|
2008-03-04 04:13:07 +00:00
|
|
|
$this->directiveValidators[] = $validator;
|
2008-03-02 04:39:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register validators to be used only on namespaces
|
|
|
|
*/
|
|
|
|
public function addNamespaceValidator($validator) {
|
2008-03-04 04:13:07 +00:00
|
|
|
$this->namespaceValidators[] = $validator;
|
2008-03-02 04:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates and adds a namespace hash
|
|
|
|
*/
|
|
|
|
public function addNamespace($hash) {
|
2008-03-04 04:13:07 +00:00
|
|
|
foreach ($this->namespaceValidators as $validator) {
|
2008-03-02 04:39:14 +00:00
|
|
|
$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-04 04:13:07 +00:00
|
|
|
foreach ($this->directiveValidators as $validator) {
|
2008-03-02 04:39:14 +00:00
|
|
|
$validator->validate($hash, $this->interchange);
|
2008-03-02 04:00:43 +00:00
|
|
|
}
|
|
|
|
$this->interchange->addDirective($hash);
|
|
|
|
}
|
|
|
|
}
|