mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-31 19:30:21 +02:00
[3.1.0] Initial validator implementation for namespaces.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1622 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
51
library/HTMLPurifier/ConfigSchema/Validator.php
Normal file
51
library/HTMLPurifier/ConfigSchema/Validator.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?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')
|
||||
->assertIsString()
|
||||
->assertNotEmpty()
|
||||
->assertAlnum();
|
||||
$this->with($n, 'description')
|
||||
->assertIsString()
|
||||
->assertNotEmpty();
|
||||
}
|
||||
|
||||
public function validateDirective($d) {
|
||||
$this->context = "directive '{$d->id}'";
|
||||
}
|
||||
|
||||
// protected helper functions
|
||||
|
||||
protected function with($obj, $member) {
|
||||
return new HTMLPurifier_ConfigSchema_ValidatorAtom($this->interchange, $this->context, $obj, $member);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user