@@ -4,26 +4,26 @@ discard block |
||
4 | 4 | |
5 | 5 | class Validation |
6 | 6 | { |
7 | - private $app; |
|
7 | + private $app; |
|
8 | 8 | |
9 | - private $input; |
|
9 | + private $input; |
|
10 | 10 | |
11 | - private $errors = []; |
|
11 | + private $errors = []; |
|
12 | 12 | |
13 | - public function __construct(Application $app) |
|
14 | - { |
|
13 | + public function __construct(Application $app) |
|
14 | + { |
|
15 | 15 | $this->app = $app; |
16 | - } |
|
16 | + } |
|
17 | 17 | |
18 | - public function input($input) |
|
19 | - { |
|
18 | + public function input($input) |
|
19 | + { |
|
20 | 20 | $this->input = $input; |
21 | 21 | |
22 | 22 | return $this; |
23 | - } |
|
23 | + } |
|
24 | 24 | |
25 | - public function require($input = null, $msg = null) |
|
26 | - { |
|
25 | + public function require($input = null, $msg = null) |
|
26 | + { |
|
27 | 27 | if (! $this->input) $this->input = $input; |
28 | 28 | |
29 | 29 | $value = $this->value($this->input); |
@@ -35,111 +35,111 @@ discard block |
||
35 | 35 | $this->addError($this->input, $msg); |
36 | 36 | } |
37 | 37 | return $this; |
38 | - } |
|
38 | + } |
|
39 | 39 | |
40 | - public function email($input = null, $msg = null) |
|
41 | - { |
|
40 | + public function email($input = null, $msg = null) |
|
41 | + { |
|
42 | 42 | if (! $this->input) $this->input = $input; |
43 | 43 | |
44 | 44 | $value = $this->value($this->input); |
45 | 45 | |
46 | 46 | if (! filter_var($value, FILTER_VALIDATE_EMAIL)) { |
47 | 47 | |
48 | - $msg = $msg ?: sprintf('%s is not valid Email', ucfirst($this->input)); |
|
48 | + $msg = $msg ?: sprintf('%s is not valid Email', ucfirst($this->input)); |
|
49 | 49 | |
50 | - $this->addError($this->input, $msg); |
|
50 | + $this->addError($this->input, $msg); |
|
51 | 51 | } |
52 | 52 | return $this; |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | - public function number($input = null, $msg = null) |
|
56 | - { |
|
55 | + public function number($input = null, $msg = null) |
|
56 | + { |
|
57 | 57 | if (! $this->input) $this->input = $input; |
58 | 58 | |
59 | 59 | $value = $this->value($this->input); |
60 | 60 | |
61 | 61 | if ($value) { |
62 | 62 | |
63 | - if (! is_numeric($value)) { |
|
63 | + if (! is_numeric($value)) { |
|
64 | 64 | |
65 | 65 | $msg = $msg ?: 'the Input must be number'; |
66 | 66 | |
67 | 67 | $this->addError($this->input, $msg); |
68 | - } |
|
68 | + } |
|
69 | 69 | } |
70 | 70 | return $this; |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - public function text($input = null, $msg = null) |
|
74 | - { |
|
73 | + public function text($input = null, $msg = null) |
|
74 | + { |
|
75 | 75 | if (! $this->input) $this->input = $input; |
76 | 76 | |
77 | 77 | $value = $this->value($this->input); |
78 | 78 | |
79 | 79 | if ($value) { |
80 | 80 | |
81 | - if (is_numeric($value)) { |
|
81 | + if (is_numeric($value)) { |
|
82 | 82 | |
83 | 83 | $msg = $msg ?: 'the Input must be Text'; |
84 | 84 | |
85 | 85 | $this->addError($this->input, $msg); |
86 | - } |
|
86 | + } |
|
87 | 87 | } |
88 | 88 | return $this; |
89 | - } |
|
89 | + } |
|
90 | 90 | |
91 | - public function minLen($length, $msg = null) |
|
92 | - { |
|
91 | + public function minLen($length, $msg = null) |
|
92 | + { |
|
93 | 93 | $value = $this->value($this->input); |
94 | 94 | |
95 | 95 | if ($value) { |
96 | 96 | |
97 | - if (strlen($value) < $length) { |
|
97 | + if (strlen($value) < $length) { |
|
98 | 98 | |
99 | 99 | $msg = $msg ?: 'This input must be at least ' . $length; |
100 | 100 | |
101 | 101 | $this->addError($this->input, $msg); |
102 | - } |
|
102 | + } |
|
103 | 103 | } |
104 | 104 | return $this; |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | - public function maxLen($length, $msg = null) |
|
108 | - { |
|
107 | + public function maxLen($length, $msg = null) |
|
108 | + { |
|
109 | 109 | $value = $this->value($this->input); |
110 | 110 | |
111 | 111 | if ($value) { |
112 | 112 | |
113 | - if (strlen($value) > $length) { |
|
113 | + if (strlen($value) > $length) { |
|
114 | 114 | |
115 | 115 | $msg = $msg ?: 'This must be ' . $length . ' or fewer'; |
116 | 116 | |
117 | 117 | $this->addError($this->input, $msg); |
118 | - } |
|
118 | + } |
|
119 | 119 | } |
120 | 120 | return $this; |
121 | - } |
|
121 | + } |
|
122 | 122 | |
123 | - public function match($input, $msg = null) |
|
124 | - { |
|
123 | + public function match($input, $msg = null) |
|
124 | + { |
|
125 | 125 | $valuePassword = $this->value($this->input); |
126 | 126 | |
127 | 127 | $valueConfirm = $this->value($input); |
128 | 128 | |
129 | 129 | if ($valuePassword && $valueConfirm ) { |
130 | 130 | |
131 | - if ($valuePassword !== $valueConfirm) { |
|
131 | + if ($valuePassword !== $valueConfirm) { |
|
132 | 132 | |
133 | 133 | $msg = $msg ?: 'Passwords does not match'; |
134 | 134 | |
135 | 135 | $this->addError('match', $msg); |
136 | - } |
|
136 | + } |
|
137 | 137 | } |
138 | 138 | return $this; |
139 | - } |
|
139 | + } |
|
140 | 140 | |
141 | - public function unique(array $data, $msg = null) |
|
142 | - { |
|
141 | + public function unique(array $data, $msg = null) |
|
142 | + { |
|
143 | 143 | $value = $this->value($this->input); |
144 | 144 | |
145 | 145 | $table = null; |
@@ -150,11 +150,11 @@ discard block |
||
150 | 150 | |
151 | 151 | if (count($data) == 2) { |
152 | 152 | |
153 | - list($table, $column) = $data; |
|
153 | + list($table, $column) = $data; |
|
154 | 154 | |
155 | 155 | } elseif (count($data) == 4) { |
156 | 156 | |
157 | - list($table, $column, $id, $userId) = $data; |
|
157 | + list($table, $column, $id, $userId) = $data; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | $sql = $userId ? $column . ' = ? AND ' . $id . ' != ? ' : $column . ' = ?'; |
@@ -165,50 +165,50 @@ discard block |
||
165 | 165 | |
166 | 166 | if ($result) { |
167 | 167 | |
168 | - $msg = $msg ?: sprintf('%s is already exist', ucfirst($this->input)); |
|
168 | + $msg = $msg ?: sprintf('%s is already exist', ucfirst($this->input)); |
|
169 | 169 | |
170 | - $this->addError($this->input, $msg); |
|
170 | + $this->addError($this->input, $msg); |
|
171 | 171 | } |
172 | 172 | return $this; |
173 | - } |
|
173 | + } |
|
174 | 174 | |
175 | - public function message($msg = null) |
|
176 | - { |
|
175 | + public function message($msg = null) |
|
176 | + { |
|
177 | 177 | $this->errors[] = $msg; |
178 | 178 | |
179 | 179 | return $this; |
180 | - } |
|
180 | + } |
|
181 | 181 | |
182 | - public function passes() |
|
183 | - { |
|
182 | + public function passes() |
|
183 | + { |
|
184 | 184 | return empty($this->errors); |
185 | - } |
|
185 | + } |
|
186 | 186 | |
187 | - public function fails() |
|
188 | - { |
|
187 | + public function fails() |
|
188 | + { |
|
189 | 189 | return ! empty($this->errors); |
190 | - } |
|
190 | + } |
|
191 | 191 | |
192 | - public function getMsgs() |
|
193 | - { |
|
192 | + public function getMsgs() |
|
193 | + { |
|
194 | 194 | return $this->errors; |
195 | - } |
|
195 | + } |
|
196 | 196 | |
197 | - private function value($input) |
|
198 | - { |
|
197 | + private function value($input) |
|
198 | + { |
|
199 | 199 | return $this->app->request->post($input); |
200 | - } |
|
200 | + } |
|
201 | 201 | |
202 | - public function addError($input, $msg) |
|
203 | - { |
|
202 | + public function addError($input, $msg) |
|
203 | + { |
|
204 | 204 | if (! $this->checkError($input)) { |
205 | 205 | |
206 | - $this->errors[$input] = $msg; |
|
206 | + $this->errors[$input] = $msg; |
|
207 | + } |
|
207 | 208 | } |
208 | - } |
|
209 | 209 | |
210 | - private function checkError($input) |
|
211 | - { |
|
210 | + private function checkError($input) |
|
211 | + { |
|
212 | 212 | return array_key_exists($input, $this->errors); |
213 | - } |
|
213 | + } |
|
214 | 214 | } |
215 | 215 | \ No newline at end of file |
@@ -24,7 +24,9 @@ discard block |
||
24 | 24 | |
25 | 25 | public function require($input = null, $msg = null) |
26 | 26 | { |
27 | - if (! $this->input) $this->input = $input; |
|
27 | + if (! $this->input) { |
|
28 | + $this->input = $input; |
|
29 | + } |
|
28 | 30 | |
29 | 31 | $value = $this->value($this->input); |
30 | 32 | |
@@ -39,7 +41,9 @@ discard block |
||
39 | 41 | |
40 | 42 | public function email($input = null, $msg = null) |
41 | 43 | { |
42 | - if (! $this->input) $this->input = $input; |
|
44 | + if (! $this->input) { |
|
45 | + $this->input = $input; |
|
46 | + } |
|
43 | 47 | |
44 | 48 | $value = $this->value($this->input); |
45 | 49 | |
@@ -54,7 +58,9 @@ discard block |
||
54 | 58 | |
55 | 59 | public function number($input = null, $msg = null) |
56 | 60 | { |
57 | - if (! $this->input) $this->input = $input; |
|
61 | + if (! $this->input) { |
|
62 | + $this->input = $input; |
|
63 | + } |
|
58 | 64 | |
59 | 65 | $value = $this->value($this->input); |
60 | 66 | |
@@ -72,7 +78,9 @@ discard block |
||
72 | 78 | |
73 | 79 | public function text($input = null, $msg = null) |
74 | 80 | { |
75 | - if (! $this->input) $this->input = $input; |
|
81 | + if (! $this->input) { |
|
82 | + $this->input = $input; |
|
83 | + } |
|
76 | 84 | |
77 | 85 | $value = $this->value($this->input); |
78 | 86 |