]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - inc/3rdparty/htmlpurifier/HTMLPurifier/PropertyList.php
[add] HTML Purifier added to clean code
[github/wallabag/wallabag.git] / inc / 3rdparty / htmlpurifier / HTMLPurifier / PropertyList.php
diff --git a/inc/3rdparty/htmlpurifier/HTMLPurifier/PropertyList.php b/inc/3rdparty/htmlpurifier/HTMLPurifier/PropertyList.php
new file mode 100644 (file)
index 0000000..d27fd53
--- /dev/null
@@ -0,0 +1,122 @@
+<?php\r
+\r
+/**\r
+ * Generic property list implementation\r
+ */\r
+class HTMLPurifier_PropertyList\r
+{\r
+    /**\r
+     * Internal data-structure for properties.\r
+     * @type array\r
+     */\r
+    protected $data = array();\r
+\r
+    /**\r
+     * Parent plist.\r
+     * @type HTMLPurifier_PropertyList\r
+     */\r
+    protected $parent;\r
+\r
+    /**\r
+     * Cache.\r
+     * @type array\r
+     */\r
+    protected $cache;\r
+\r
+    /**\r
+     * @param HTMLPurifier_PropertyList $parent Parent plist\r
+     */\r
+    public function __construct($parent = null)\r
+    {\r
+        $this->parent = $parent;\r
+    }\r
+\r
+    /**\r
+     * Recursively retrieves the value for a key\r
+     * @param string $name\r
+     * @throws HTMLPurifier_Exception\r
+     */\r
+    public function get($name)\r
+    {\r
+        if ($this->has($name)) {\r
+            return $this->data[$name];\r
+        }\r
+        // possible performance bottleneck, convert to iterative if necessary\r
+        if ($this->parent) {\r
+            return $this->parent->get($name);\r
+        }\r
+        throw new HTMLPurifier_Exception("Key '$name' not found");\r
+    }\r
+\r
+    /**\r
+     * Sets the value of a key, for this plist\r
+     * @param string $name\r
+     * @param mixed $value\r
+     */\r
+    public function set($name, $value)\r
+    {\r
+        $this->data[$name] = $value;\r
+    }\r
+\r
+    /**\r
+     * Returns true if a given key exists\r
+     * @param string $name\r
+     * @return bool\r
+     */\r
+    public function has($name)\r
+    {\r
+        return array_key_exists($name, $this->data);\r
+    }\r
+\r
+    /**\r
+     * Resets a value to the value of it's parent, usually the default. If\r
+     * no value is specified, the entire plist is reset.\r
+     * @param string $name\r
+     */\r
+    public function reset($name = null)\r
+    {\r
+        if ($name == null) {\r
+            $this->data = array();\r
+        } else {\r
+            unset($this->data[$name]);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Squashes this property list and all of its property lists into a single\r
+     * array, and returns the array. This value is cached by default.\r
+     * @param bool $force If true, ignores the cache and regenerates the array.\r
+     * @return array\r
+     */\r
+    public function squash($force = false)\r
+    {\r
+        if ($this->cache !== null && !$force) {\r
+            return $this->cache;\r
+        }\r
+        if ($this->parent) {\r
+            return $this->cache = array_merge($this->parent->squash($force), $this->data);\r
+        } else {\r
+            return $this->cache = $this->data;\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Returns the parent plist.\r
+     * @return HTMLPurifier_PropertyList\r
+     */\r
+    public function getParent()\r
+    {\r
+        return $this->parent;\r
+    }\r
+\r
+    /**\r
+     * Sets the parent plist.\r
+     * @param HTMLPurifier_PropertyList $plist Parent plist\r
+     */\r
+    public function setParent($plist)\r
+    {\r
+        $this->parent = $plist;\r
+    }\r
+}\r
+\r
+// vim: et sw=4 sts=4\r