4 * Generic property list implementation
6 class HTMLPurifier_PropertyList
9 * Internal data-structure for properties.
12 protected $data = array();
16 * @type HTMLPurifier_PropertyList
27 * @param HTMLPurifier_PropertyList $parent Parent plist
29 public function __construct($parent = null)
31 $this->parent
= $parent;
35 * Recursively retrieves the value for a key
37 * @throws HTMLPurifier_Exception
39 public function get($name)
41 if ($this->has($name)) {
42 return $this->data
[$name];
44 // possible performance bottleneck, convert to iterative if necessary
46 return $this->parent
->get($name);
48 throw new HTMLPurifier_Exception("Key '$name' not found");
52 * Sets the value of a key, for this plist
56 public function set($name, $value)
58 $this->data
[$name] = $value;
62 * Returns true if a given key exists
66 public function has($name)
68 return array_key_exists($name, $this->data
);
72 * Resets a value to the value of it's parent, usually the default. If
73 * no value is specified, the entire plist is reset.
76 public function reset($name = null)
79 $this->data
= array();
81 unset($this->data
[$name]);
86 * Squashes this property list and all of its property lists into a single
87 * array, and returns the array. This value is cached by default.
88 * @param bool $force If true, ignores the cache and regenerates the array.
91 public function squash($force = false)
93 if ($this->cache
!== null && !$force) {
97 return $this->cache
= array_merge($this->parent
->squash($force), $this->data
);
99 return $this->cache
= $this->data
;
104 * Returns the parent plist.
105 * @return HTMLPurifier_PropertyList
107 public function getParent()
109 return $this->parent
;
113 * Sets the parent plist.
114 * @param HTMLPurifier_PropertyList $plist Parent plist
116 public function setParent($plist)
118 $this->parent
= $plist;
122 // vim: et sw=4 sts=4