]> git.immae.eu Git - github/wallabag/wallabag.git/blame - inc/3rdparty/htmlpurifier/HTMLPurifier/PropertyList.php
remove autoload section in composer.json
[github/wallabag/wallabag.git] / inc / 3rdparty / htmlpurifier / HTMLPurifier / PropertyList.php
CommitLineData
d4949327
NL
1<?php\r
2\r
3/**\r
4 * Generic property list implementation\r
5 */\r
6class HTMLPurifier_PropertyList\r
7{\r
8 /**\r
9 * Internal data-structure for properties.\r
10 * @type array\r
11 */\r
12 protected $data = array();\r
13\r
14 /**\r
15 * Parent plist.\r
16 * @type HTMLPurifier_PropertyList\r
17 */\r
18 protected $parent;\r
19\r
20 /**\r
21 * Cache.\r
22 * @type array\r
23 */\r
24 protected $cache;\r
25\r
26 /**\r
27 * @param HTMLPurifier_PropertyList $parent Parent plist\r
28 */\r
29 public function __construct($parent = null)\r
30 {\r
31 $this->parent = $parent;\r
32 }\r
33\r
34 /**\r
35 * Recursively retrieves the value for a key\r
36 * @param string $name\r
37 * @throws HTMLPurifier_Exception\r
38 */\r
39 public function get($name)\r
40 {\r
41 if ($this->has($name)) {\r
42 return $this->data[$name];\r
43 }\r
44 // possible performance bottleneck, convert to iterative if necessary\r
45 if ($this->parent) {\r
46 return $this->parent->get($name);\r
47 }\r
48 throw new HTMLPurifier_Exception("Key '$name' not found");\r
49 }\r
50\r
51 /**\r
52 * Sets the value of a key, for this plist\r
53 * @param string $name\r
54 * @param mixed $value\r
55 */\r
56 public function set($name, $value)\r
57 {\r
58 $this->data[$name] = $value;\r
59 }\r
60\r
61 /**\r
62 * Returns true if a given key exists\r
63 * @param string $name\r
64 * @return bool\r
65 */\r
66 public function has($name)\r
67 {\r
68 return array_key_exists($name, $this->data);\r
69 }\r
70\r
71 /**\r
72 * Resets a value to the value of it's parent, usually the default. If\r
73 * no value is specified, the entire plist is reset.\r
74 * @param string $name\r
75 */\r
76 public function reset($name = null)\r
77 {\r
78 if ($name == null) {\r
79 $this->data = array();\r
80 } else {\r
81 unset($this->data[$name]);\r
82 }\r
83 }\r
84\r
85 /**\r
86 * Squashes this property list and all of its property lists into a single\r
87 * array, and returns the array. This value is cached by default.\r
88 * @param bool $force If true, ignores the cache and regenerates the array.\r
89 * @return array\r
90 */\r
91 public function squash($force = false)\r
92 {\r
93 if ($this->cache !== null && !$force) {\r
94 return $this->cache;\r
95 }\r
96 if ($this->parent) {\r
97 return $this->cache = array_merge($this->parent->squash($force), $this->data);\r
98 } else {\r
99 return $this->cache = $this->data;\r
100 }\r
101 }\r
102\r
103 /**\r
104 * Returns the parent plist.\r
105 * @return HTMLPurifier_PropertyList\r
106 */\r
107 public function getParent()\r
108 {\r
109 return $this->parent;\r
110 }\r
111\r
112 /**\r
113 * Sets the parent plist.\r
114 * @param HTMLPurifier_PropertyList $plist Parent plist\r
115 */\r
116 public function setParent($plist)\r
117 {\r
118 $this->parent = $plist;\r
119 }\r
120}\r
121\r
122// vim: et sw=4 sts=4\r