mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-10 07:38:41 +00:00
4c798bd17e
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1596 48356398-32a2-884e-a903-53898d9a118a
63 lines
1.7 KiB
PHP
63 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Decorator for interchange that performs validations
|
|
*/
|
|
class HTMLPurifier_ConfigSchema_InterchangeValidator
|
|
{
|
|
protected $interchange;
|
|
protected $validators = array();
|
|
protected $namespaceValidators = array();
|
|
protected $directiveValidators = array();
|
|
|
|
/**
|
|
* @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) {
|
|
$this->addNamespaceValidator($validator);
|
|
$this->addDirectiveValidator($validator);
|
|
}
|
|
|
|
/**
|
|
* Register validators to be used only on directives
|
|
*/
|
|
public function addDirectiveValidator($validator) {
|
|
$this->directiveValidators[] = $validator;
|
|
}
|
|
|
|
/**
|
|
* Register validators to be used only on namespaces
|
|
*/
|
|
public function addNamespaceValidator($validator) {
|
|
$this->namespaceValidators[] = $validator;
|
|
}
|
|
|
|
/**
|
|
* Validates and adds a namespace hash
|
|
*/
|
|
public function addNamespace($hash) {
|
|
foreach ($this->namespaceValidators as $validator) {
|
|
$validator->validate($hash, $this->interchange);
|
|
}
|
|
$this->interchange->addNamespace($hash);
|
|
}
|
|
|
|
/**
|
|
* Validates and adds a directive hash
|
|
*/
|
|
public function addDirective($hash) {
|
|
foreach ($this->directiveValidators as $validator) {
|
|
$validator->validate($hash, $this->interchange);
|
|
}
|
|
$this->interchange->addDirective($hash);
|
|
}
|
|
}
|