2008-03-22 20:26:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs validations on HTMLPurifier_ConfigSchema_Interchange
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_ConfigSchema_Validator
|
|
|
|
{
|
|
|
|
|
|
|
|
protected $interchange;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Volatile context variables to provide a fluent interface.
|
|
|
|
*/
|
|
|
|
protected $context, $obj, $member;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates a fully-formed interchange object. Throws an
|
|
|
|
* HTMLPurifier_ConfigSchema_Exception if there's a problem.
|
|
|
|
*/
|
|
|
|
public function validate($interchange) {
|
|
|
|
$this->interchange = $interchange;
|
|
|
|
foreach ($interchange->namespaces as $namespace) {
|
|
|
|
$this->validateNamespace($namespace);
|
|
|
|
}
|
|
|
|
foreach ($interchange->directives as $directive) {
|
|
|
|
$this->validateDirective($directive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function validateNamespace($n) {
|
|
|
|
$this->context = "namespace '{$n->namespace}'";
|
|
|
|
$this->with($n, 'namespace')
|
|
|
|
->assertNotEmpty()
|
|
|
|
->assertAlnum();
|
|
|
|
$this->with($n, 'description')
|
|
|
|
->assertIsString()
|
|
|
|
->assertNotEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function validateDirective($d) {
|
|
|
|
$this->context = "directive '{$d->id}'";
|
2008-03-22 21:06:55 +00:00
|
|
|
$this->validateId($d->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function validateId($id) {
|
|
|
|
$this->context = "id '$id'";
|
|
|
|
$this->with($id, 'namespace')
|
|
|
|
->assertNotEmpty()
|
|
|
|
->assertAlnum();
|
|
|
|
$this->with($id, 'directive')
|
|
|
|
->assertNotEmpty()
|
|
|
|
->assertAlnum();
|
2008-03-22 20:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// protected helper functions
|
|
|
|
|
|
|
|
protected function with($obj, $member) {
|
2008-03-22 21:06:55 +00:00
|
|
|
return new HTMLPurifier_ConfigSchema_ValidatorAtom($this->context, $obj, $member);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function error($msg) {
|
|
|
|
throw new HTMLPurifier_ConfigSchema_Exception($msg . ' in ' . $this->context);
|
2008-03-22 20:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|