mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-05 21:57:26 +02:00
[3.1.0] Create decorator validator/adapter for Interchange.
- Output flush output git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1587 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -125,6 +125,7 @@ require 'HTMLPurifier/ConfigDef/DirectiveAlias.php';
|
||||
require 'HTMLPurifier/ConfigDef/Namespace.php';
|
||||
require 'HTMLPurifier/ConfigSchema/Exception.php';
|
||||
require 'HTMLPurifier/ConfigSchema/Interchange.php';
|
||||
require 'HTMLPurifier/ConfigSchema/InterchangeValidator.php';
|
||||
require 'HTMLPurifier/ConfigSchema/StringHash.php';
|
||||
require 'HTMLPurifier/ConfigSchema/StringHashAdapter.php';
|
||||
require 'HTMLPurifier/ConfigSchema/StringHashParser.php';
|
||||
|
@@ -11,7 +11,7 @@ class HTMLPurifier_ConfigSchema_Interchange
|
||||
/**
|
||||
* Hash table of allowed types.
|
||||
*/
|
||||
private $types = array(
|
||||
public $types = array(
|
||||
'string' => 'String',
|
||||
'istring' => 'Case-insensitive string',
|
||||
'text' => 'Text',
|
||||
@@ -28,29 +28,12 @@ class HTMLPurifier_ConfigSchema_Interchange
|
||||
/**
|
||||
* Array of Namespace ID => array(namespace info)
|
||||
*/
|
||||
private $namespaces;
|
||||
public $namespaces;
|
||||
|
||||
/**
|
||||
* Array of Directive ID => array(directive info)
|
||||
*/
|
||||
private $directives;
|
||||
|
||||
/** Get all namespaces */
|
||||
public function getNamespaces() {return $this->namespaces;}
|
||||
/** Get a namespace */
|
||||
public function getNamespace($id) {return $this->namespaces[$id];}
|
||||
/** Check if a namespace exists */
|
||||
public function namespaceExists($id) {return isset($this->namespaces[$id]);}
|
||||
|
||||
/** Get all directives */
|
||||
public function getDirectives() {return $this->directives;}
|
||||
/** Get a directive */
|
||||
public function getDirective($id) {return $this->directives[$id];}
|
||||
/** Check if a directive exists */
|
||||
public function directiveExists($id) {return isset($this->directives[$id]);}
|
||||
|
||||
/** Get all types */
|
||||
public function getTypes() {return $this->types;}
|
||||
public $directives;
|
||||
|
||||
/**
|
||||
* Adds a namespace array to $namespaces
|
||||
@@ -71,7 +54,9 @@ class HTMLPurifier_ConfigSchema_Interchange
|
||||
* to be used for data-input.
|
||||
*/
|
||||
public function getValidatorAdapter() {
|
||||
|
||||
$validator = new HTMLPurifier_ConfigSchema_InterchangeValidator($this);
|
||||
$validator->addValidator(new HTMLPurifier_ConfigSchema_Validator_IdExists());
|
||||
return $validator;
|
||||
}
|
||||
|
||||
}
|
||||
|
45
library/HTMLPurifier/ConfigSchema/InterchangeValidator.php
Normal file
45
library/HTMLPurifier/ConfigSchema/InterchangeValidator.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Decorator for interchange that performs validations
|
||||
*/
|
||||
class HTMLPurifier_ConfigSchema_InterchangeValidator
|
||||
{
|
||||
protected $interchange;
|
||||
protected $validators = 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->validators[] = $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and adds a namespace hash
|
||||
*/
|
||||
public function addNamespace($hash) {
|
||||
foreach ($this->validators as $validator) {
|
||||
$validator->validateNamespace($hash, $this->interchange);
|
||||
}
|
||||
$this->interchange->addNamespace($hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and adds a directive hash
|
||||
*/
|
||||
public function addDirective($hash) {
|
||||
foreach ($this->validators as $validator) {
|
||||
$validator->validateDirective($hash, $this->interchange);
|
||||
}
|
||||
$this->interchange->addDirective($hash);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user