aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2014-02-21 15:43:14 +0100
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2014-02-21 15:43:14 +0100
commitd4949327efa15b492cab1bef3fe074290a328a17 (patch)
treee89e0322bb1f1b06d663fd10fdded21bac867e5d /inc/3rdparty/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php
parentc9bd17a1007bb78e5de0775efca01df0fb515031 (diff)
downloadwallabag-d4949327efa15b492cab1bef3fe074290a328a17.tar.gz
wallabag-d4949327efa15b492cab1bef3fe074290a328a17.tar.zst
wallabag-d4949327efa15b492cab1bef3fe074290a328a17.zip
[add] HTML Purifier added to clean code
Diffstat (limited to 'inc/3rdparty/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php')
-rw-r--r--inc/3rdparty/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php130
1 files changed, 130 insertions, 0 deletions
diff --git a/inc/3rdparty/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php b/inc/3rdparty/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php
new file mode 100644
index 00000000..a2e0b4a1
--- /dev/null
+++ b/inc/3rdparty/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php
@@ -0,0 +1,130 @@
1<?php
2
3/**
4 * Fluent interface for validating the contents of member variables.
5 * This should be immutable. See HTMLPurifier_ConfigSchema_Validator for
6 * use-cases. We name this an 'atom' because it's ONLY for validations that
7 * are independent and usually scalar.
8 */
9class HTMLPurifier_ConfigSchema_ValidatorAtom
10{
11 /**
12 * @type string
13 */
14 protected $context;
15
16 /**
17 * @type object
18 */
19 protected $obj;
20
21 /**
22 * @type string
23 */
24 protected $member;
25
26 /**
27 * @type mixed
28 */
29 protected $contents;
30
31 public function __construct($context, $obj, $member)
32 {
33 $this->context = $context;
34 $this->obj = $obj;
35 $this->member = $member;
36 $this->contents =& $obj->$member;
37 }
38
39 /**
40 * @return HTMLPurifier_ConfigSchema_ValidatorAtom
41 */
42 public function assertIsString()
43 {
44 if (!is_string($this->contents)) {
45 $this->error('must be a string');
46 }
47 return $this;
48 }
49
50 /**
51 * @return HTMLPurifier_ConfigSchema_ValidatorAtom
52 */
53 public function assertIsBool()
54 {
55 if (!is_bool($this->contents)) {
56 $this->error('must be a boolean');
57 }
58 return $this;
59 }
60
61 /**
62 * @return HTMLPurifier_ConfigSchema_ValidatorAtom
63 */
64 public function assertIsArray()
65 {
66 if (!is_array($this->contents)) {
67 $this->error('must be an array');
68 }
69 return $this;
70 }
71
72 /**
73 * @return HTMLPurifier_ConfigSchema_ValidatorAtom
74 */
75 public function assertNotNull()
76 {
77 if ($this->contents === null) {
78 $this->error('must not be null');
79 }
80 return $this;
81 }
82
83 /**
84 * @return HTMLPurifier_ConfigSchema_ValidatorAtom
85 */
86 public function assertAlnum()
87 {
88 $this->assertIsString();
89 if (!ctype_alnum($this->contents)) {
90 $this->error('must be alphanumeric');
91 }
92 return $this;
93 }
94
95 /**
96 * @return HTMLPurifier_ConfigSchema_ValidatorAtom
97 */
98 public function assertNotEmpty()
99 {
100 if (empty($this->contents)) {
101 $this->error('must not be empty');
102 }
103 return $this;
104 }
105
106 /**
107 * @return HTMLPurifier_ConfigSchema_ValidatorAtom
108 */
109 public function assertIsLookup()
110 {
111 $this->assertIsArray();
112 foreach ($this->contents as $v) {
113 if ($v !== true) {
114 $this->error('must be a lookup array');
115 }
116 }
117 return $this;
118 }
119
120 /**
121 * @param string $msg
122 * @throws HTMLPurifier_ConfigSchema_Exception
123 */
124 protected function error($msg)
125 {
126 throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($this->member) . ' in ' . $this->context . ' ' . $msg);
127 }
128}
129
130// vim: et sw=4 sts=4