4 * Generic property list implementation
6 class HTMLPurifier_PropertyList
9 * Internal data-structure for properties
11 protected $data = array();
20 public function __construct($parent = null) {
21 $this->parent
= $parent;
25 * Recursively retrieves the value for a key
27 public function get($name) {
28 if ($this->has($name)) return $this->data
[$name];
29 // possible performance bottleneck, convert to iterative if necessary
30 if ($this->parent
) return $this->parent
->get($name);
31 throw new HTMLPurifier_Exception("Key '$name' not found");
35 * Sets the value of a key, for this plist
37 public function set($name, $value) {
38 $this->data
[$name] = $value;
42 * Returns true if a given key exists
44 public function has($name) {
45 return array_key_exists($name, $this->data
);
49 * Resets a value to the value of it's parent, usually the default. If
50 * no value is specified, the entire plist is reset.
52 public function reset($name = null) {
53 if ($name == null) $this->data
= array();
54 else unset($this->data
[$name]);
58 * Squashes this property list and all of its property lists into a single
59 * array, and returns the array. This value is cached by default.
60 * @param $force If true, ignores the cache and regenerates the array.
62 public function squash($force = false) {
63 if ($this->cache
!== null && !$force) return $this->cache
;
65 return $this->cache
= array_merge($this->parent
->squash($force), $this->data
);
67 return $this->cache
= $this->data
;
72 * Returns the parent plist.
74 public function getParent() {
79 * Sets the parent plist.
81 public function setParent($plist) {
82 $this->parent
= $plist;