PSR-2 reformatting PHPDoc corrections
[htmlpurifier.git] / library / HTMLPurifier / Context.php
blob8cc443f04ab4dd4e39aee931b36c6d904cd8894b
1 <?php
3 /**
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!
9 */
10 class HTMLPurifier_Context
13 /**
14 * Private array that stores the references.
15 * @type array
17 private $_storage = array();
19 /**
20 * Registers a variable into the context.
21 * @param string $name String name
22 * @param mixed $ref Reference to variable to be registered
24 public function register($name, &$ref)
26 if (isset($this->_storage[$name])) {
27 trigger_error(
28 "Name $name produces collision, cannot re-register",
29 E_USER_ERROR
31 return;
33 $this->_storage[$name] =& $ref;
36 /**
37 * Retrieves a variable reference from the context.
38 * @param string $name String name
39 * @param bool $ignore_error Boolean whether or not to ignore error
40 * @return mixed
42 public function &get($name, $ignore_error = false)
44 if (!isset($this->_storage[$name])) {
45 if (!$ignore_error) {
46 trigger_error(
47 "Attempted to retrieve non-existent variable $name",
48 E_USER_ERROR
51 $var = null; // so we can return by reference
52 return $var;
54 return $this->_storage[$name];
57 /**
58 * Destroys a variable in the context.
59 * @param string $name String name
61 public function destroy($name)
63 if (!isset($this->_storage[$name])) {
64 trigger_error(
65 "Attempted to destroy non-existent variable $name",
66 E_USER_ERROR
68 return;
70 unset($this->_storage[$name]);
73 /**
74 * Checks whether or not the variable exists.
75 * @param string $name String name
76 * @return bool
78 public function exists($name)
80 return isset($this->_storage[$name]);
83 /**
84 * Loads a series of variables from an associative array
85 * @param array $context_array Assoc array of variables to load
87 public function loadArray($context_array)
89 foreach ($context_array as $key => $discard) {
90 $this->register($key, $context_array[$key]);
95 // vim: et sw=4 sts=4