|
9 | 9 | * @author zauberfisch |
10 | 10 | */ |
11 | 11 |
|
12 | | -class NetefxValidator extends Validator { |
13 | | - |
14 | | - protected $rules; |
15 | | - protected $javascriptValidationHandler = 'none'; |
| 12 | +class NetefxValidator extends Validator |
| 13 | +{ |
| 14 | + |
| 15 | + protected $rules; |
| 16 | + protected $javascriptValidationHandler = 'none'; |
16 | 17 |
|
17 | | - /** |
18 | | - * @return array |
19 | | - */ |
20 | | - public function getRules() { |
21 | | - return $this->rules; |
22 | | - } |
23 | | - |
24 | | - /** |
25 | | - * if the first parameter is not an array, or we have more than one parameter, collate all parameters to an array, otherwise use the passed array |
26 | | - * @param array|mixed $items |
27 | | - */ |
28 | | - public function setRules($items = null) { |
29 | | - $this->rules = (!is_array($items) || count(func_get_args()) > 1) ? func_get_args() : $items; |
30 | | - } |
31 | | - |
32 | | - /** |
33 | | - * if the first parameter is not an array, or we have more than one parameter, collate all parameters to an array, otherwise use the passed array |
34 | | - * @param array|mixed $items |
35 | | - */ |
36 | | - public function __construct() { |
37 | | - $this->setRules(func_get_args()); |
38 | | - parent::__construct(); |
39 | | - |
40 | | - } |
| 18 | + /** |
| 19 | + * @return array |
| 20 | + */ |
| 21 | + public function getRules() |
| 22 | + { |
| 23 | + return $this->rules; |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * if the first parameter is not an array, or we have more than one parameter, collate all parameters to an array, otherwise use the passed array |
| 28 | + * @param array|mixed $items |
| 29 | + */ |
| 30 | + public function setRules($items = null) |
| 31 | + { |
| 32 | + $this->rules = (!is_array($items) || count(func_get_args()) > 1) ? func_get_args() : $items; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * if the first parameter is not an array, or we have more than one parameter, collate all parameters to an array, otherwise use the passed array |
| 37 | + * @param array|mixed $items |
| 38 | + */ |
| 39 | + public function __construct() |
| 40 | + { |
| 41 | + $this->setRules(func_get_args()); |
| 42 | + parent::__construct(); |
| 43 | + } |
41 | 44 |
|
42 | | - |
43 | | - /** |
44 | | - * javascript not implemented yet |
45 | | - * @return string |
46 | | - */ |
47 | | - function javascript() { |
48 | | - $js = ""; |
49 | | - return $js; |
50 | | - } |
| 45 | + |
| 46 | + /** |
| 47 | + * javascript not implemented yet |
| 48 | + * @return string |
| 49 | + */ |
| 50 | + public function javascript() |
| 51 | + { |
| 52 | + $js = ""; |
| 53 | + return $js; |
| 54 | + } |
51 | 55 |
|
52 | | - /** |
53 | | - * calls validate() on all fields and rules |
54 | | - * @return boolean |
55 | | - */ |
56 | | - function php($data) { |
57 | | - $valid = true; |
| 56 | + /** |
| 57 | + * calls validate() on all fields and rules |
| 58 | + * @return boolean |
| 59 | + */ |
| 60 | + public function php($data) |
| 61 | + { |
| 62 | + $valid = true; |
58 | 63 |
|
59 | | - $fields = $this->form->Fields(); |
60 | | - foreach($fields as $field) { |
61 | | - $valid = ($field->validate($this) && $valid); |
62 | | - } |
63 | | - if($this->rules) { |
64 | | - foreach($this->rules as $rule) { |
65 | | - |
66 | | - if (!$rule->validate($data)) { |
67 | | - $errorMessage = $rule->getErrorMessage(); |
68 | | - $errorMessageType = $rule->getErrorMessageType(); |
69 | | - $fieldName = $rule->getField(); |
70 | | - |
71 | | - $this->validationError( |
72 | | - $fieldName, |
73 | | - $errorMessage, |
74 | | - $errorMessageType |
75 | | - ); |
76 | | - $valid = false; |
77 | | - } |
78 | | - } |
79 | | - } |
| 64 | + $fields = $this->form->Fields(); |
| 65 | + foreach ($fields as $field) { |
| 66 | + $valid = ($field->validate($this) && $valid); |
| 67 | + } |
| 68 | + if ($this->rules) { |
| 69 | + foreach ($this->rules as $rule) { |
| 70 | + if (!$rule->validate($data)) { |
| 71 | + $errorMessage = $rule->getErrorMessage(); |
| 72 | + $errorMessageType = $rule->getErrorMessageType(); |
| 73 | + $fieldName = $rule->getField(); |
| 74 | + |
| 75 | + $this->validationError( |
| 76 | + $fieldName, |
| 77 | + $errorMessage, |
| 78 | + $errorMessageType |
| 79 | + ); |
| 80 | + $valid = false; |
| 81 | + } |
| 82 | + } |
| 83 | + } |
80 | 84 |
|
81 | | - if (!$valid) Session::set("NetefxValidatorError",true); |
| 85 | + if (!$valid) { |
| 86 | + Session::set("NetefxValidatorError", true); |
| 87 | + } |
82 | 88 |
|
83 | | - return $valid; |
84 | | - } |
85 | | - |
| 89 | + return $valid; |
| 90 | + } |
86 | 91 | } |
0 commit comments