4 * Registry object that contains information about the current context.
5 * @warning Is a bit buggy when variables are set to null: it thinks
6 * they don't exist! So use false instead, please.
7 * @note Since the variables Context deals with may not be objects,
8 * references are very important here! Do not remove!
10 class HTMLPurifier_Context
14 * Private array that stores the references.
16 private $_storage = array();
19 * Registers a variable into the context.
20 * @param $name String name
21 * @param $ref Reference to variable to be registered
23 public function register($name, &$ref) {
24 if (isset($this->_storage[$name])) {
25 trigger_error("Name $name produces collision, cannot re-register",
29 $this->_storage[$name] =& $ref;
33 * Retrieves a variable reference from the context.
34 * @param $name String name
35 * @param $ignore_error Boolean whether or not to ignore error
37 public function &get($name, $ignore_error = false) {
38 if (!isset($this->_storage[$name])) {
40 trigger_error("Attempted to retrieve non-existent variable $name",
43 $var = null; // so we can return by reference
46 return $this->_storage[$name];
50 * Destorys a variable in the context.
51 * @param $name String name
53 public function destroy($name) {
54 if (!isset($this->_storage[$name])) {
55 trigger_error("Attempted to destroy non-existent variable $name",
59 unset($this->_storage[$name]);
63 * Checks whether or not the variable exists.
64 * @param $name String name
66 public function exists($name) {
67 return isset($this->_storage[$name]);
71 * Loads a series of variables from an associative array
72 * @param $context_array Assoc array of variables to load
74 public function loadArray($context_array) {
75 foreach ($context_array as $key => $discard) {
76 $this->register($key, $context_array[$key]);