Skip to content

Commit 372a312

Browse files
author
helpfulrobot
committed
Converted to PSR-2
1 parent 4f20dac commit 372a312

31 files changed

+1990
-1791
lines changed

code/NetefxValidator.php

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,78 +9,83 @@
99
* @author zauberfisch
1010
*/
1111

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';
1617

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+
}
4144

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+
}
5155

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;
5863

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+
}
8084

81-
if (!$valid) Session::set("NetefxValidatorError",true);
85+
if (!$valid) {
86+
Session::set("NetefxValidatorError", true);
87+
}
8288

83-
return $valid;
84-
}
85-
89+
return $valid;
90+
}
8691
}

0 commit comments

Comments
 (0)