From d81bcbd2080a5590b2e0b9f81f748616150a5aa2 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 2 Mar 2008 02:57:31 +0000 Subject: [PATCH] Remove decorator pattern from validator; we'll only have one decorator which invokes the subsystem. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1586 48356398-32a2-884e-a903-53898d9a118a --- library/HTMLPurifier.includes.php | 4 +- library/HTMLPurifier/ConfigSchema/Interchange.php | 10 ++--- .../ConfigSchema/Interchange/Validator.php | 43 ---------------------- .../Interchange/Validator/IdExists.php | 20 ---------- library/HTMLPurifier/ConfigSchema/Validator.php | 39 ++++++++++++++++++++ .../ConfigSchema/Validator/IdExists.php | 15 ++++++++ maintenance/flush.php | 2 +- .../Interchange/Validator/IdExistsTest.php | 23 ------------ .../ConfigSchema/Validator/IdExistsTest.php | 23 ++++++++++++ .../{Interchange => }/ValidatorHarness.php | 7 ++-- 10 files changed, 87 insertions(+), 99 deletions(-) delete mode 100644 library/HTMLPurifier/ConfigSchema/Interchange/Validator.php delete mode 100644 library/HTMLPurifier/ConfigSchema/Interchange/Validator/IdExists.php create mode 100644 library/HTMLPurifier/ConfigSchema/Validator.php create mode 100644 library/HTMLPurifier/ConfigSchema/Validator/IdExists.php delete mode 100644 tests/HTMLPurifier/ConfigSchema/Interchange/Validator/IdExistsTest.php create mode 100644 tests/HTMLPurifier/ConfigSchema/Validator/IdExistsTest.php rename tests/HTMLPurifier/ConfigSchema/{Interchange => }/ValidatorHarness.php (57%) diff --git a/library/HTMLPurifier.includes.php b/library/HTMLPurifier.includes.php index 7f78c017..27094120 100644 --- a/library/HTMLPurifier.includes.php +++ b/library/HTMLPurifier.includes.php @@ -129,8 +129,8 @@ require 'HTMLPurifier/ConfigSchema/StringHash.php'; require 'HTMLPurifier/ConfigSchema/StringHashAdapter.php'; require 'HTMLPurifier/ConfigSchema/StringHashParser.php'; require 'HTMLPurifier/ConfigSchema/StringHashReverseAdapter.php'; -require 'HTMLPurifier/ConfigSchema/Interchange/Validator.php'; -require 'HTMLPurifier/ConfigSchema/Interchange/Validator/IdExists.php'; +require 'HTMLPurifier/ConfigSchema/Validator.php'; +require 'HTMLPurifier/ConfigSchema/Validator/IdExists.php'; require 'HTMLPurifier/DefinitionCache/Decorator.php'; require 'HTMLPurifier/DefinitionCache/Null.php'; require 'HTMLPurifier/DefinitionCache/Serializer.php'; diff --git a/library/HTMLPurifier/ConfigSchema/Interchange.php b/library/HTMLPurifier/ConfigSchema/Interchange.php index 5bfe1128..47c1ce5a 100644 --- a/library/HTMLPurifier/ConfigSchema/Interchange.php +++ b/library/HTMLPurifier/ConfigSchema/Interchange.php @@ -11,7 +11,7 @@ class HTMLPurifier_ConfigSchema_Interchange /** * Hash table of allowed types. */ - protected $types = array( + private $types = array( 'string' => 'String', 'istring' => 'Case-insensitive string', 'text' => 'Text', @@ -28,12 +28,12 @@ class HTMLPurifier_ConfigSchema_Interchange /** * Array of Namespace ID => array(namespace info) */ - protected $namespaces; + private $namespaces; /** * Array of Directive ID => array(directive info) */ - protected $directives; + private $directives; /** Get all namespaces */ public function getNamespaces() {return $this->namespaces;} @@ -71,9 +71,7 @@ class HTMLPurifier_ConfigSchema_Interchange * to be used for data-input. */ public function getValidatorAdapter() { - return - new HTMLPurifier_ConfigSchema_Interchange_Validator_IdExists( - $this); + } } diff --git a/library/HTMLPurifier/ConfigSchema/Interchange/Validator.php b/library/HTMLPurifier/ConfigSchema/Interchange/Validator.php deleted file mode 100644 index fae8557d..00000000 --- a/library/HTMLPurifier/ConfigSchema/Interchange/Validator.php +++ /dev/null @@ -1,43 +0,0 @@ -decorate($i); - } - - /** Wrap this decorator around an object. */ - public function decorate($i) { - $this->interchange = $i; - } - - public function getNamespaces() { - return $this->interchange->getNamespaces(); - } - - public function getDirectives() { - return $this->interchange->getDirectives(); - } - - public function getTypes() { - return $this->interchange->getTypes(); - } - - public function addNamespace($arr) { - $this->interchange->addNamespace($arr); - } - - public function addDirective($arr) { - $this->interchange->addNamespace($arr); - } - -} diff --git a/library/HTMLPurifier/ConfigSchema/Interchange/Validator/IdExists.php b/library/HTMLPurifier/ConfigSchema/Interchange/Validator/IdExists.php deleted file mode 100644 index 23153242..00000000 --- a/library/HTMLPurifier/ConfigSchema/Interchange/Validator/IdExists.php +++ /dev/null @@ -1,20 +0,0 @@ -validate($arr, $interchange, 'namespace'); + } + + /** + * Validates and filters a directive. + */ + public function validateDirective(&$arr, $interchange) { + $this->validate($arr, $interchange, 'directive'); + } + + /** + * Common validator, throwing an exception on error. It can + * also performing filtering or evaluation functions. + * + * @note This is strictly for convenience reasons when subclasing. + * + * @param $arr Array to validate. + * @param $interchange HTMLPurifier_ConfigSchema_Interchange object + * that is being processed. + * @param $type Type of object being validated, this saves a little work + * if only cosmetic changes are being made between namespaces + * and directives. + */ + protected function validate(&$arr, $interchange, $type) {} + + +} diff --git a/library/HTMLPurifier/ConfigSchema/Validator/IdExists.php b/library/HTMLPurifier/ConfigSchema/Validator/IdExists.php new file mode 100644 index 00000000..2b12d2de --- /dev/null +++ b/library/HTMLPurifier/ConfigSchema/Validator/IdExists.php @@ -0,0 +1,15 @@ +validator = new HTMLPurifier_ConfigSchema_Interchange_Validator_IdExists($this->mock); - } - - public function testNamespace() { - $this->mock->expectNever('addNamespace'); - $this->expectSchemaException('Namespace must have ID'); - $this->validator->addNamespace(); - } - - public function testDirective() { - $this->mock->expectNever('addDirective'); - $this->expectSchemaException('Directive must have ID'); - $this->validator->addDirective(); - } - -} diff --git a/tests/HTMLPurifier/ConfigSchema/Validator/IdExistsTest.php b/tests/HTMLPurifier/ConfigSchema/Validator/IdExistsTest.php new file mode 100644 index 00000000..6a42e1ed --- /dev/null +++ b/tests/HTMLPurifier/ConfigSchema/Validator/IdExistsTest.php @@ -0,0 +1,23 @@ +validator = new HTMLPurifier_ConfigSchema_Validator_IdExists(); + } + + public function testValidateNamespace() { + $this->expectSchemaException('ID must exist in namespace'); + $arr = array(); + $this->validator->validateNamespace($arr, $this->interchange); + } + + public function testValidateDirective() { + $this->expectSchemaException('ID must exist in directive'); + $arr = array(); + $this->validator->validateDirective($arr, $this->interchange); + } + +} diff --git a/tests/HTMLPurifier/ConfigSchema/Interchange/ValidatorHarness.php b/tests/HTMLPurifier/ConfigSchema/ValidatorHarness.php similarity index 57% rename from tests/HTMLPurifier/ConfigSchema/Interchange/ValidatorHarness.php rename to tests/HTMLPurifier/ConfigSchema/ValidatorHarness.php index 204a8c0a..9230e20a 100644 --- a/tests/HTMLPurifier/ConfigSchema/Interchange/ValidatorHarness.php +++ b/tests/HTMLPurifier/ConfigSchema/ValidatorHarness.php @@ -1,14 +1,13 @@ mock = new HTMLPurifier_ConfigSchema_InterchangeMock(); + $this->interchange = new HTMLPurifier_ConfigSchema_InterchangeMock(); } protected function expectSchemaException($msg) { -- 2.11.4.GIT