@@ -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($data, $msg = null) |
|
| 142 | - { |
|
| 141 | + public function unique($data, $msg = null) |
|
| 142 | + { |
|
| 143 | 143 | $value = $this->value($this->input); |
| 144 | 144 | |
| 145 | 145 | $table = null; |
@@ -162,50 +162,50 @@ discard block |
||
| 162 | 162 | |
| 163 | 163 | if ($result) { |
| 164 | 164 | |
| 165 | - $msg = $msg ?: sprintf('%s is already exist', ucfirst($this->input)); |
|
| 165 | + $msg = $msg ?: sprintf('%s is already exist', ucfirst($this->input)); |
|
| 166 | 166 | |
| 167 | - $this->addError($this->input, $msg); |
|
| 167 | + $this->addError($this->input, $msg); |
|
| 168 | 168 | } |
| 169 | 169 | return $this; |
| 170 | - } |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - public function message($msg = null) |
|
| 173 | - { |
|
| 172 | + public function message($msg = null) |
|
| 173 | + { |
|
| 174 | 174 | $this->errors[] = $msg; |
| 175 | 175 | |
| 176 | 176 | return $this; |
| 177 | - } |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - public function passes() |
|
| 180 | - { |
|
| 179 | + public function passes() |
|
| 180 | + { |
|
| 181 | 181 | return empty($this->errors); |
| 182 | - } |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - public function fails() |
|
| 185 | - { |
|
| 184 | + public function fails() |
|
| 185 | + { |
|
| 186 | 186 | return ! empty($this->errors); |
| 187 | - } |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - public function getMsgs() |
|
| 190 | - { |
|
| 189 | + public function getMsgs() |
|
| 190 | + { |
|
| 191 | 191 | return $this->errors; |
| 192 | - } |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - private function value($input) |
|
| 195 | - { |
|
| 194 | + private function value($input) |
|
| 195 | + { |
|
| 196 | 196 | return $this->app->request->post($input); |
| 197 | - } |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - public function addError($input, $msg) |
|
| 200 | - { |
|
| 199 | + public function addError($input, $msg) |
|
| 200 | + { |
|
| 201 | 201 | if (! $this->checkError($input)) { |
| 202 | 202 | |
| 203 | - $this->errors[$input] = $msg; |
|
| 203 | + $this->errors[$input] = $msg; |
|
| 204 | + } |
|
| 204 | 205 | } |
| 205 | - } |
|
| 206 | 206 | |
| 207 | - private function checkError($input) |
|
| 208 | - { |
|
| 207 | + private function checkError($input) |
|
| 208 | + { |
|
| 209 | 209 | return array_key_exists($input, $this->errors); |
| 210 | - } |
|
| 210 | + } |
|
| 211 | 211 | } |
| 212 | 212 | \ No newline at end of file |