Document core classes up to EntityLookup.php
[htmlpurifier.git] / library / HTMLPurifier / ConfigDef.php
blobd1f253f705118f269137dc4caff1c9088c9f270e
1 <?php
3 /**
4 * Configuration definition, defines directives and their defaults.
5 * @todo Build documentation generation capabilities.
6 */
7 class HTMLPurifier_ConfigDef {
9 /**
10 * Currently defined directives (and namespaces).
11 * @note This shares the exact same structure as HTMLPurifier_Config::$conf
13 var $info = array();
15 /**
16 * Initializes the default namespaces.
18 function initialize() {
19 $this->defineNamespace('Core', 'Core features that are always available.');
20 $this->defineNamespace('Attr', 'Features regarding attribute validation.');
21 $this->defineNamespace('URI', 'Features regarding Uniform Resource Identifiers.');
24 /**
25 * Retrieves an instance of the application-wide configuration definition.
27 function &instance($prototype = null) {
28 static $instance;
29 if ($prototype !== null) {
30 $instance = $prototype;
31 } elseif ($instance === null || $prototype === true) {
32 $instance = new HTMLPurifier_ConfigDef();
33 $instance->initialize();
35 return $instance;
38 /**
39 * Defines a directive for configuration
40 * @warning Will fail of directive's namespace is defined
41 * @todo Collect information on description and allow redefinition
42 * so that multiple files can register a dependency on a
43 * configuration directive.
44 * @param $namespace Namespace the directive is in
45 * @param $name Key of directive
46 * @param $default Default value of directive
47 * @param $description Description of directive for documentation
49 function define($namespace, $name, $default, $description) {
50 $def =& HTMLPurifier_ConfigDef::instance();
51 if (!isset($def->info[$namespace])) {
52 trigger_error('Cannot define directive for undefined namespace',
53 E_USER_ERROR);
54 return;
56 if (isset($def->info[$namespace][$name])) {
57 // this behavior is at risk of change
58 trigger_error('Cannot redefine directive', E_USER_ERROR);
59 return;
61 $def->info[$namespace][$name] = $default;
64 /**
65 * Defines a namespace for directives to be put into.
66 * @param $namespace Namespace's name
67 * @param $description Description of the namespace
69 function defineNamespace($namespace, $description) {
70 $def =& HTMLPurifier_ConfigDef::instance();
71 if (isset($def->info[$namespace])) {
72 trigger_error('Cannot redefine namespace', E_USER_ERROR);
73 return;
75 $def->info[$namespace] = array();