4 * Configuration definition, defines directives and their defaults.
5 * @todo Build documentation generation capabilities.
7 class HTMLPurifier_ConfigDef
{
10 * Currently defined directives (and namespaces).
11 * @note This shares the exact same structure as HTMLPurifier_Config::$conf
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.');
25 * Retrieves an instance of the application-wide configuration definition.
27 function &instance($prototype = null) {
29 if ($prototype !== null) {
30 $instance = $prototype;
31 } elseif ($instance === null ||
$prototype === true) {
32 $instance = new HTMLPurifier_ConfigDef();
33 $instance->initialize();
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',
56 if (isset($def->info
[$namespace][$name])) {
57 // this behavior is at risk of change
58 trigger_error('Cannot redefine directive', E_USER_ERROR
);
61 $def->info
[$namespace][$name] = $default;
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
);
75 $def->info
[$namespace] = array();