commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / packages / IDS / vendors / htmlpurifier / HTMLPurifier / PropertyList.php
1 <?php
2
3 /**
4 * Generic property list implementation
5 */
6 class HTMLPurifier_PropertyList
7 {
8 /**
9 * Internal data-structure for properties
10 */
11 protected $data = array();
12
13 /**
14 * Parent plist
15 */
16 protected $parent;
17
18 protected $cache;
19
20 public function __construct($parent = null) {
21 $this->parent = $parent;
22 }
23
24 /**
25 * Recursively retrieves the value for a key
26 */
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");
32 }
33
34 /**
35 * Sets the value of a key, for this plist
36 */
37 public function set($name, $value) {
38 $this->data[$name] = $value;
39 }
40
41 /**
42 * Returns true if a given key exists
43 */
44 public function has($name) {
45 return array_key_exists($name, $this->data);
46 }
47
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.
51 */
52 public function reset($name = null) {
53 if ($name == null) $this->data = array();
54 else unset($this->data[$name]);
55 }
56
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.
61 */
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;
68 }
69 }
70
71 /**
72 * Returns the parent plist.
73 */
74 public function getParent() {
75 return $this->parent;
76 }
77
78 /**
79 * Sets the parent plist.
80 */
81 public function setParent($plist) {
82 $this->parent = $plist;
83 }
84 }
85
86 // vim: et sw=4 sts=4