Fix two minor bugs, updating Phorum and removing unused $dir variable.
[htmlpurifier/darkodev.git] / library / HTMLPurifier / PropertyList.php
blob2b99fb7bc3caffe0a8c8439199e05ae1930aea21
1 <?php
3 /**
4 * Generic property list implementation
5 */
6 class HTMLPurifier_PropertyList
8 /**
9 * Internal data-structure for properties
11 protected $data = array();
13 /**
14 * Parent plist
16 protected $parent;
18 protected $cache;
20 public function __construct($parent = null) {
21 $this->parent = $parent;
24 /**
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");
34 /**
35 * Sets the value of a key, for this plist
37 public function set($name, $value) {
38 $this->data[$name] = $value;
41 /**
42 * Returns true if a given key exists
44 public function has($name) {
45 return array_key_exists($name, $this->data);
48 /**
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]);
57 /**
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;
64 if ($this->parent) {
65 return $this->cache = array_merge($this->parent->squash($force), $this->data);
66 } else {
67 return $this->cache = $this->data;
71 /**
72 * Returns the parent plist.
74 public function getParent() {
75 return $this->parent;
78 /**
79 * Sets the parent plist.
81 public function setParent($plist) {
82 $this->parent = $plist;
86 // vim: et sw=4 sts=4