2008-03-01 17:06:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic schema interchange format that can be converted to a runtime
|
|
|
|
* representation (HTMLPurifier_ConfigSchema) or HTML documentation. Members
|
|
|
|
* are completely validated.
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_ConfigSchema_Interchange
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of Namespace ID => array(namespace info)
|
|
|
|
*/
|
2008-03-02 04:00:43 +00:00
|
|
|
public $namespaces;
|
2008-03-01 17:06:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of Directive ID => array(directive info)
|
|
|
|
*/
|
2008-03-02 04:00:43 +00:00
|
|
|
public $directives;
|
2008-03-01 17:06:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a namespace array to $namespaces
|
|
|
|
*/
|
|
|
|
public function addNamespace($arr) {
|
|
|
|
$this->namespaces[$arr['ID']] = $arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a directive array to $directives
|
|
|
|
*/
|
|
|
|
public function addDirective($arr) {
|
|
|
|
$this->directives[$arr['ID']] = $arr;
|
|
|
|
}
|
|
|
|
|
2008-03-02 01:55:14 +00:00
|
|
|
/**
|
|
|
|
* Retrieves a version of this object wrapped in the validator adapter
|
|
|
|
* to be used for data-input.
|
|
|
|
*/
|
|
|
|
public function getValidatorAdapter() {
|
2008-03-02 04:00:43 +00:00
|
|
|
$validator = new HTMLPurifier_ConfigSchema_InterchangeValidator($this);
|
2008-03-04 04:13:07 +00:00
|
|
|
|
|
|
|
// Validators should be defined in the order they are to be called.
|
2008-03-05 05:20:28 +00:00
|
|
|
$namespace = $validator->namespace;
|
|
|
|
$directive = $validator->directive;
|
2008-03-04 14:33:38 +00:00
|
|
|
|
|
|
|
// ID tests
|
2008-03-04 05:21:04 +00:00
|
|
|
$validator->addValidator($this->make('Exists', 'ID'));
|
|
|
|
$validator->addValidator($this->make('Unique'));
|
2008-03-05 05:20:28 +00:00
|
|
|
|
|
|
|
// ID: Namespace test
|
|
|
|
$namespace->addValidator($this->make('Alnum', 'ID'));
|
|
|
|
|
|
|
|
// ID: Common tests
|
2008-03-04 05:21:04 +00:00
|
|
|
$validator->addValidator($this->make('ParseId'));
|
|
|
|
$validator->addValidator($this->make('Exists', '_NAMESPACE'));
|
|
|
|
$validator->addValidator($this->make('Alnum', '_NAMESPACE'));
|
2008-03-04 14:33:38 +00:00
|
|
|
|
2008-03-05 05:20:28 +00:00
|
|
|
// ID: Directive tests
|
|
|
|
$directive->addValidator($this->make('Exists', '_DIRECTIVE'));
|
|
|
|
$directive->addValidator($this->make('Alnum', '_DIRECTIVE'));
|
|
|
|
$directive->addValidator($this->make('NamespaceExists'));
|
2008-03-04 14:33:38 +00:00
|
|
|
|
2008-03-05 06:04:08 +00:00
|
|
|
// Directive: Type and Default tests
|
2008-03-05 05:20:28 +00:00
|
|
|
$directive->addValidator($this->make('Exists', 'TYPE'));
|
|
|
|
$directive->addValidator($this->make('ParseType'));
|
|
|
|
$directive->addValidator($this->make('Exists', '_TYPE'));
|
|
|
|
$directive->addValidator($this->make('Exists', '_NULL'));
|
|
|
|
$directive->addValidator($this->make('Exists', 'DEFAULT'));
|
2008-03-05 05:49:18 +00:00
|
|
|
$directive->addValidator($this->make('ParseDefault'));
|
2008-03-04 14:33:38 +00:00
|
|
|
|
|
|
|
// Common tests
|
2008-03-04 05:21:04 +00:00
|
|
|
$validator->addValidator($this->make('Exists', 'DESCRIPTION'));
|
2008-03-02 04:39:14 +00:00
|
|
|
|
2008-03-02 04:00:43 +00:00
|
|
|
return $validator;
|
2008-03-02 01:55:14 +00:00
|
|
|
}
|
|
|
|
|
2008-03-04 05:21:04 +00:00
|
|
|
/**
|
|
|
|
* Creates a validator.
|
|
|
|
* @warning
|
|
|
|
* Only *one* argument is supported; multiple args shouldn't use
|
|
|
|
* this function.
|
|
|
|
*/
|
|
|
|
protected function make($name, $arg = null) {
|
|
|
|
$class = "HTMLPurifier_ConfigSchema_Validator_$name";
|
|
|
|
if ($arg === null) return new $class();
|
|
|
|
else return new $class($arg);
|
|
|
|
}
|
|
|
|
|
2008-03-01 17:06:23 +00:00
|
|
|
}
|