4 * Configuration object that triggers customizable behavior.
6 * @warning This class is strongly defined: that means that the class
7 * will fail if an undefined directive is retrieved or set.
9 * @note Many classes that could (although many times don't) use the
10 * configuration object make it a mandatory parameter. This is
11 * because a configuration object should always be forwarded,
12 * otherwise, you run the risk of missing a parameter and then
13 * being stumped when a configuration directive doesn't work.
15 class HTMLPurifier_Config
19 * Two-level associative array of configuration directives
24 * Reference HTMLPurifier_ConfigSchema for value checking
29 * Instance of HTMLPurifier_HTMLDefinition
34 * Instance of HTMLPurifier_CSSDefinition
39 * @param $definition HTMLPurifier_ConfigSchema that defines what directives
42 function HTMLPurifier_Config(&$definition) {
43 $this->conf
= $definition->defaults
; // set up, copy in defaults
44 $this->def
= $definition; // keep a copy around for checking
48 * Convenience constructor that creates a default configuration object.
49 * @return Default HTMLPurifier_Config object.
51 function createDefault() {
52 $definition =& HTMLPurifier_ConfigSchema
::instance();
53 $config = new HTMLPurifier_Config($definition);
58 * Retreives a value from the configuration.
59 * @param $namespace String namespace
60 * @param $key String key
62 function get($namespace, $key) {
63 if (!isset($this->conf
[$namespace][$key])) {
64 trigger_error('Cannot retrieve value of undefined directive',
68 return $this->conf
[$namespace][$key];
72 * Sets a value to configuration.
73 * @param $namespace String namespace
74 * @param $key String key
75 * @param $value Mixed value
77 function set($namespace, $key, $value) {
78 if (!isset($this->conf
[$namespace][$key])) {
79 trigger_error('Cannot set undefined directive to value',
83 $value = $this->def
->validate($value,
84 $this->def
->info
[$namespace][$key]->type
);
85 if (is_string($value)) {
86 // resolve value alias if defined
87 if (isset($this->def
->info
[$namespace][$key]->aliases
[$value])) {
88 $value = $this->def
->info
[$namespace][$key]->aliases
[$value];
90 if ($this->def
->info
[$namespace][$key]->allowed
!== true) {
91 // check to see if the value is allowed
92 if (!isset($this->def
->info
[$namespace][$key]->allowed
[$value])) {
93 trigger_error('Value not supported', E_USER_WARNING
);
98 if ($value === null) {
99 trigger_error('Value is of invalid type', E_USER_WARNING
);
102 $this->conf
[$namespace][$key] = $value;
106 * Retrieves a copy of the HTML definition.
108 function getHTMLDefinition() {
109 if ($this->html_definition
=== null) {
110 $this->html_definition
= new HTMLPurifier_HTMLDefinition();
111 $this->html_definition
->setup($this);
113 return $this->html_definition
;
117 * Retrieves a copy of the CSS definition
119 function getCSSDefinition() {
120 if ($this->css_definition
=== null) {
121 $this->css_definition
= new HTMLPurifier_CSSDefinition();
122 $this->css_definition
->setup($this);
124 return $this->css_definition
;