1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-07-31 19:30:21 +02:00

Refactor validators so that they can be reused between directives and namespaces.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1589 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2008-03-02 04:39:14 +00:00
parent 18320d59a4
commit d8cb360f3b
12 changed files with 131 additions and 71 deletions

View File

@@ -0,0 +1,22 @@
<?php
/**
* Validates that a field is alphanumeric in the array (does not check
* existence!)
*/
class HTMLPurifier_ConfigSchema_Validator_Alnum extends HTMLPurifier_ConfigSchema_Validator
{
protected $index;
public function __construct($index) {
$this->index = $index;
}
public function validate(&$arr, $interchange) {
if (!ctype_alnum($arr[$this->index])) {
throw new HTMLPurifier_ConfigSchema_Exception($arr[$this->index] . ' in '. $this->index .' must be alphanumeric');
}
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* Validates that an field exists in the array
*/
class HTMLPurifier_ConfigSchema_Validator_Exists extends HTMLPurifier_ConfigSchema_Validator
{
protected $index;
public function __construct($index) {
$this->index = $index;
}
public function validate(&$arr, $interchange) {
if (empty($arr[$this->index])) {
throw new HTMLPurifier_ConfigSchema_Exception($this->index . ' must exist');
}
}
}

View File

@@ -1,15 +0,0 @@
<?php
/**
* Validates that an ID field exists in the array
*/
class HTMLPurifier_ConfigSchema_Validator_IdExists extends HTMLPurifier_ConfigSchema_Validator
{
public function validate(&$arr, $interchange, $type) {
if (!isset($arr['ID'])) {
throw new HTMLPurifier_ConfigSchema_Exception('ID must exist in ' . $type);
}
}
}