2006-10-01 18:14:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registry object that contains information about the current context.
|
2007-06-24 04:22:28 +00:00
|
|
|
* @warning Is a bit buggy when variables are set to null: it thinks
|
|
|
|
* they don't exist! So use false instead, please.
|
2006-10-01 18:14:08 +00:00
|
|
|
*/
|
|
|
|
class HTMLPurifier_Context
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private array that stores the references.
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
private $_storage = array();
|
2006-10-01 18:14:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a variable into the context.
|
|
|
|
* @param $name String name
|
|
|
|
* @param $ref Variable to be registered
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public function register($name, &$ref) {
|
2006-10-01 18:14:08 +00:00
|
|
|
if (isset($this->_storage[$name])) {
|
2007-06-24 04:22:28 +00:00
|
|
|
trigger_error("Name $name produces collision, cannot re-register",
|
2006-10-01 18:14:08 +00:00
|
|
|
E_USER_ERROR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->_storage[$name] =& $ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a variable reference from the context.
|
|
|
|
* @param $name String name
|
2007-06-25 01:08:57 +00:00
|
|
|
* @param $ignore_error Boolean whether or not to ignore error
|
2006-10-01 18:14:08 +00:00
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public function &get($name, $ignore_error = false) {
|
2006-10-01 18:14:08 +00:00
|
|
|
if (!isset($this->_storage[$name])) {
|
2007-06-25 01:08:57 +00:00
|
|
|
if (!$ignore_error) {
|
|
|
|
trigger_error("Attempted to retrieve non-existent variable $name",
|
|
|
|
E_USER_ERROR);
|
|
|
|
}
|
2006-11-16 23:58:33 +00:00
|
|
|
$var = null; // so we can return by reference
|
|
|
|
return $var;
|
2006-10-01 18:14:08 +00:00
|
|
|
}
|
|
|
|
return $this->_storage[$name];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destorys a variable in the context.
|
|
|
|
* @param $name String name
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public function destroy($name) {
|
2006-10-01 18:14:08 +00:00
|
|
|
if (!isset($this->_storage[$name])) {
|
2007-06-24 04:22:28 +00:00
|
|
|
trigger_error("Attempted to destroy non-existent variable $name",
|
2006-10-01 18:14:08 +00:00
|
|
|
E_USER_ERROR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unset($this->_storage[$name]);
|
|
|
|
}
|
|
|
|
|
2006-10-01 18:39:48 +00:00
|
|
|
/**
|
|
|
|
* Checks whether or not the variable exists.
|
|
|
|
* @param $name String name
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public function exists($name) {
|
2006-10-01 18:39:48 +00:00
|
|
|
return isset($this->_storage[$name]);
|
|
|
|
}
|
|
|
|
|
2006-10-21 18:18:36 +00:00
|
|
|
/**
|
|
|
|
* Loads a series of variables from an associative array
|
|
|
|
* @param $context_array Assoc array of variables to load
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public function loadArray(&$context_array) {
|
2006-10-21 18:18:36 +00:00
|
|
|
foreach ($context_array as $key => $discard) {
|
|
|
|
$this->register($key, $context_array[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-01 18:14:08 +00:00
|
|
|
}
|
|
|
|
|