]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - inc/3rdparty/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php
[add] HTML Purifier added to clean code
[github/wallabag/wallabag.git] / inc / 3rdparty / htmlpurifier / HTMLPurifier / ConfigSchema / ValidatorAtom.php
diff --git a/inc/3rdparty/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php b/inc/3rdparty/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php
new file mode 100644 (file)
index 0000000..a2e0b4a
--- /dev/null
@@ -0,0 +1,130 @@
+<?php\r
+\r
+/**\r
+ * Fluent interface for validating the contents of member variables.\r
+ * This should be immutable. See HTMLPurifier_ConfigSchema_Validator for\r
+ * use-cases. We name this an 'atom' because it's ONLY for validations that\r
+ * are independent and usually scalar.\r
+ */\r
+class HTMLPurifier_ConfigSchema_ValidatorAtom\r
+{\r
+    /**\r
+     * @type string\r
+     */\r
+    protected $context;\r
+\r
+    /**\r
+     * @type object\r
+     */\r
+    protected $obj;\r
+\r
+    /**\r
+     * @type string\r
+     */\r
+    protected $member;\r
+\r
+    /**\r
+     * @type mixed\r
+     */\r
+    protected $contents;\r
+\r
+    public function __construct($context, $obj, $member)\r
+    {\r
+        $this->context = $context;\r
+        $this->obj = $obj;\r
+        $this->member = $member;\r
+        $this->contents =& $obj->$member;\r
+    }\r
+\r
+    /**\r
+     * @return HTMLPurifier_ConfigSchema_ValidatorAtom\r
+     */\r
+    public function assertIsString()\r
+    {\r
+        if (!is_string($this->contents)) {\r
+            $this->error('must be a string');\r
+        }\r
+        return $this;\r
+    }\r
+\r
+    /**\r
+     * @return HTMLPurifier_ConfigSchema_ValidatorAtom\r
+     */\r
+    public function assertIsBool()\r
+    {\r
+        if (!is_bool($this->contents)) {\r
+            $this->error('must be a boolean');\r
+        }\r
+        return $this;\r
+    }\r
+\r
+    /**\r
+     * @return HTMLPurifier_ConfigSchema_ValidatorAtom\r
+     */\r
+    public function assertIsArray()\r
+    {\r
+        if (!is_array($this->contents)) {\r
+            $this->error('must be an array');\r
+        }\r
+        return $this;\r
+    }\r
+\r
+    /**\r
+     * @return HTMLPurifier_ConfigSchema_ValidatorAtom\r
+     */\r
+    public function assertNotNull()\r
+    {\r
+        if ($this->contents === null) {\r
+            $this->error('must not be null');\r
+        }\r
+        return $this;\r
+    }\r
+\r
+    /**\r
+     * @return HTMLPurifier_ConfigSchema_ValidatorAtom\r
+     */\r
+    public function assertAlnum()\r
+    {\r
+        $this->assertIsString();\r
+        if (!ctype_alnum($this->contents)) {\r
+            $this->error('must be alphanumeric');\r
+        }\r
+        return $this;\r
+    }\r
+\r
+    /**\r
+     * @return HTMLPurifier_ConfigSchema_ValidatorAtom\r
+     */\r
+    public function assertNotEmpty()\r
+    {\r
+        if (empty($this->contents)) {\r
+            $this->error('must not be empty');\r
+        }\r
+        return $this;\r
+    }\r
+\r
+    /**\r
+     * @return HTMLPurifier_ConfigSchema_ValidatorAtom\r
+     */\r
+    public function assertIsLookup()\r
+    {\r
+        $this->assertIsArray();\r
+        foreach ($this->contents as $v) {\r
+            if ($v !== true) {\r
+                $this->error('must be a lookup array');\r
+            }\r
+        }\r
+        return $this;\r
+    }\r
+\r
+    /**\r
+     * @param string $msg\r
+     * @throws HTMLPurifier_ConfigSchema_Exception\r
+     */\r
+    protected function error($msg)\r
+    {\r
+        throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($this->member) . ' in ' . $this->context . ' ' . $msg);\r
+    }\r
+}\r
+\r
+// vim: et sw=4 sts=4\r