]>
Commit | Line | Data |
---|---|---|
f45a286b AD |
1 | <?php |
2 | ||
3 | /** | |
4 | * Generic schema interchange format that can be converted to a runtime | |
5 | * representation (HTMLPurifier_ConfigSchema) or HTML documentation. Members | |
6 | * are completely validated. | |
7 | */ | |
8 | class HTMLPurifier_ConfigSchema_Interchange | |
9 | { | |
10 | ||
11 | /** | |
12 | * Name of the application this schema is describing. | |
13 | */ | |
14 | public $name; | |
15 | ||
16 | /** | |
17 | * Array of Namespace ID => array(namespace info) | |
18 | */ | |
19 | public $namespaces = array(); | |
20 | ||
21 | /** | |
22 | * Array of Directive ID => array(directive info) | |
23 | */ | |
24 | public $directives = array(); | |
25 | ||
26 | /** | |
27 | * Adds a namespace array to $namespaces | |
28 | */ | |
29 | public function addNamespace($namespace) { | |
30 | if (isset($this->namespaces[$i = $namespace->namespace])) { | |
31 | throw new HTMLPurifier_ConfigSchema_Exception("Cannot redefine namespace '$i'"); | |
32 | } | |
33 | $this->namespaces[$i] = $namespace; | |
34 | } | |
35 | ||
36 | /** | |
37 | * Adds a directive array to $directives | |
38 | */ | |
39 | public function addDirective($directive) { | |
40 | if (isset($this->directives[$i = $directive->id->toString()])) { | |
41 | throw new HTMLPurifier_ConfigSchema_Exception("Cannot redefine directive '$i'"); | |
42 | } | |
43 | $this->directives[$i] = $directive; | |
44 | } | |
45 | ||
46 | /** | |
47 | * Convenience function to perform standard validation. Throws exception | |
48 | * on failed validation. | |
49 | */ | |
50 | public function validate() { | |
51 | $validator = new HTMLPurifier_ConfigSchema_Validator(); | |
52 | return $validator->validate($this); | |
53 | } | |
54 | ||
55 | } | |
56 | ||
57 | // vim: et sw=4 sts=4 |