@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | self::getInstance()->errors[] = $er->getMessage(); |
89 | 89 | } |
90 | 90 | |
91 | - return self::errors(); |
|
91 | + return self::errors(); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | public static function errors(): bool |
@@ -100,22 +100,22 @@ discard block |
||
100 | 100 | { |
101 | 101 | foreach ( (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) as $key => $value) { |
102 | 102 | |
103 | - foreach (self::getInstance()->data as $keyy => $valuee) { |
|
103 | + foreach (self::getInstance()->data as $keyy => $valuee) { |
|
104 | 104 | |
105 | - self::getInstance()->checkExpected($keyy); |
|
105 | + self::getInstance()->checkExpected($keyy); |
|
106 | 106 | |
107 | - if($keyy===$key){ |
|
107 | + if($keyy===$key){ |
|
108 | 108 | |
109 | 109 | unset(self::getInstance()->required[$key]); |
110 | 110 | |
111 | - foreach ($value as $subkey => $subvalue) { |
|
111 | + foreach ($value as $subkey => $subvalue) { |
|
112 | 112 | |
113 | 113 | $function = strtolower($subkey); |
114 | 114 | |
115 | 115 | self::getInstance()->hasMethod($function)->$function($keyy, $subvalue); |
116 | - } |
|
117 | - } |
|
118 | - } |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | |
156 | 156 | self::getInstance()->existRole(self::getInstance()->model()); |
157 | 157 | |
158 | - foreach ( self::getInstance()->validator(self::getInstance()->model())->getRules($request['_ROLE']) as $field => $r) { |
|
158 | + foreach ( self::getInstance()->validator(self::getInstance()->model())->getRules($request['_ROLE']) as $field => $r) { |
|
159 | 159 | $r = self::getInstance()->replaceRegex($r); |
160 | 160 | $response .= ("'$field':".json_encode(array_reverse($r))).','; |
161 | 161 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | public function __construct() |
16 | 16 | { |
17 | - require __DIR__.DIRECTORY_SEPARATOR.'languages'. DIRECTORY_SEPARATOR . self::$lang .'.php'; |
|
17 | + require __DIR__.DIRECTORY_SEPARATOR.'languages'.DIRECTORY_SEPARATOR.self::$lang.'.php'; |
|
18 | 18 | self::$err = $VALIDATOR_LANG; |
19 | 19 | } |
20 | 20 | |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | private static function getClass(string $class) |
40 | 40 | { |
41 | - if(!class_exists($class)){ |
|
41 | + if (!class_exists($class)) { |
|
42 | 42 | throw new \RuntimeException("Form ID {$class} inválido"); |
43 | 43 | } |
44 | 44 | |
@@ -49,21 +49,21 @@ discard block |
||
49 | 49 | |
50 | 50 | private function existRole($getRules) |
51 | 51 | { |
52 | - if(empty(self::getInstance()->validator($getRules)->getRules(self::getInstance()->data['_ROLE']))){ |
|
52 | + if (empty(self::getInstance()->validator($getRules)->getRules(self::getInstance()->data['_ROLE']))) { |
|
53 | 53 | throw new \RuntimeException('Não existe regras para validar este formulário'); |
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
57 | 57 | public function checkDatas(array $data): void |
58 | 58 | { |
59 | - if(!isset($data['_PROVIDER']) || !isset($data['_ROLE'])){ |
|
59 | + if (!isset($data['_PROVIDER']) || !isset($data['_ROLE'])) { |
|
60 | 60 | throw new \RuntimeException('The server did not receive the information needed to retrieve the requested validator'); |
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | 64 | public static function execute(array $data): bool |
65 | 65 | { |
66 | - try{ |
|
66 | + try { |
|
67 | 67 | self::getInstance()->checkDatas($data); |
68 | 68 | |
69 | 69 | self::getInstance()->data = $data; |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | |
75 | 75 | self::getInstance()->existRole(self::getInstance()->model); |
76 | 76 | |
77 | - foreach ( (self::getInstance()->validator(self::getInstance()->model)->getRules($data['_ROLE'])) as $key => $value) { |
|
78 | - if(@$value['required'] === true){ |
|
77 | + foreach ((self::getInstance()->validator(self::getInstance()->model)->getRules($data['_ROLE'])) as $key => $value) { |
|
78 | + if (@$value['required']===true) { |
|
79 | 79 | self::getInstance()->required[$key] = $value; |
80 | 80 | } |
81 | 81 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | |
85 | 85 | self::getInstance()->validate(); |
86 | 86 | self::getInstance()->requireds(); |
87 | - }catch(\Exception $er){ |
|
87 | + }catch (\Exception $er) { |
|
88 | 88 | self::getInstance()->errors[] = $er->getMessage(); |
89 | 89 | } |
90 | 90 | |
@@ -93,18 +93,18 @@ discard block |
||
93 | 93 | |
94 | 94 | public static function errors(): bool |
95 | 95 | { |
96 | - return (count(self::getInstance()->errors) === 0); |
|
96 | + return (count(self::getInstance()->errors)===0); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | public function validate(): void |
100 | 100 | { |
101 | - foreach ( (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) as $key => $value) { |
|
101 | + foreach ((self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) as $key => $value) { |
|
102 | 102 | |
103 | 103 | foreach (self::getInstance()->data as $keyy => $valuee) { |
104 | 104 | |
105 | 105 | self::getInstance()->checkExpected($keyy); |
106 | 106 | |
107 | - if($keyy===$key){ |
|
107 | + if ($keyy===$key) { |
|
108 | 108 | |
109 | 109 | unset(self::getInstance()->required[$key]); |
110 | 110 | |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | |
122 | 122 | private function checkExpected(string $keyy): void |
123 | 123 | { |
124 | - if(!array_key_exists($keyy, (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) ) && !in_array($keyy, self::getInstance()->defaultData)){ |
|
125 | - throw new \RuntimeException($keyy . self::$err['nExpected']); |
|
124 | + if (!array_key_exists($keyy, (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE']))) && !in_array($keyy, self::getInstance()->defaultData)) { |
|
125 | + throw new \RuntimeException($keyy.self::$err['nExpected']); |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | |
134 | 134 | public function hasMethod($method): Validator |
135 | 135 | { |
136 | - if(!method_exists(static::class, $method)){ |
|
137 | - throw new \RuntimeException($method . self::$err['nMethod']); |
|
136 | + if (!method_exists(static::class, $method)) { |
|
137 | + throw new \RuntimeException($method.self::$err['nMethod']); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | return $this; |
@@ -155,17 +155,17 @@ discard block |
||
155 | 155 | |
156 | 156 | self::getInstance()->existRole(self::getInstance()->model()); |
157 | 157 | |
158 | - foreach ( self::getInstance()->validator(self::getInstance()->model())->getRules($request['_ROLE']) as $field => $r) { |
|
158 | + foreach (self::getInstance()->validator(self::getInstance()->model())->getRules($request['_ROLE']) as $field => $r) { |
|
159 | 159 | $r = self::getInstance()->replaceRegex($r); |
160 | 160 | $response .= ("'$field':".json_encode(array_reverse($r))).','; |
161 | 161 | } |
162 | 162 | |
163 | - return '{'.substr($response,0,-1).'}'; |
|
163 | + return '{'.substr($response, 0, -1).'}'; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | private function replaceRegex(array $getRules): array |
167 | 167 | { |
168 | - if(array_key_exists('regex', $getRules)){ |
|
168 | + if (array_key_exists('regex', $getRules)) { |
|
169 | 169 | $getRules['regex'] = substr($getRules['regex'], 1, -2); |
170 | 170 | } |
171 | 171 |
@@ -84,7 +84,7 @@ |
||
84 | 84 | |
85 | 85 | self::getInstance()->validate(); |
86 | 86 | self::getInstance()->requireds(); |
87 | - }catch(\Exception $er){ |
|
87 | + } catch(\Exception $er){ |
|
88 | 88 | self::getInstance()->errors[] = $er->getMessage(); |
89 | 89 | } |
90 | 90 |
@@ -8,15 +8,15 @@ discard block |
||
8 | 8 | |
9 | 9 | protected function requireds(): void |
10 | 10 | { |
11 | - if(count(self::getInstance()->required()) > 0){ |
|
12 | - self::getInstance()->error([ self::$err['needed'].implode(', ', array_keys(self::getInstance()->required())) ]); |
|
11 | + if (count(self::getInstance()->required())>0) { |
|
12 | + self::getInstance()->error([self::$err['needed'].implode(', ', array_keys(self::getInstance()->required()))]); |
|
13 | 13 | } |
14 | 14 | } |
15 | 15 | |
16 | 16 | public function validateDate($date, $format = 'Y-m-d H:i:s') |
17 | 17 | { |
18 | 18 | $d = \DateTime::createFromFormat($format, $date); |
19 | - return $d && $d->format($format) == $date; |
|
19 | + return $d && $d->format($format)==$date; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | protected function isRequired(string $param): bool |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | protected function valid(string $param, $value): bool |
29 | 29 | { |
30 | - return (self::getInstance()->isRequired($param) || strlen($value > 0)); |
|
30 | + return (self::getInstance()->isRequired($param) || strlen($value>0)); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | } |
@@ -12,29 +12,29 @@ |
||
12 | 12 | |
13 | 13 | public function __construct(object $model) |
14 | 14 | { |
15 | - $this->form['model'] = ucfirst(get_class($model)); |
|
16 | - } |
|
15 | + $this->form['model'] = ucfirst(get_class($model)); |
|
16 | + } |
|
17 | 17 | |
18 | 18 | public function action(string $action): Rules |
19 | 19 | { |
20 | - $this->action = $action; |
|
21 | - return $this; |
|
22 | - } |
|
20 | + $this->action = $action; |
|
21 | + return $this; |
|
22 | + } |
|
23 | 23 | |
24 | 24 | public function field(string $field, array $test, ?string $placeholder = null): Rules |
25 | 25 | { |
26 | - if(empty($this->action)){ |
|
26 | + if(empty($this->action)){ |
|
27 | 27 | self::$errors[] = self::$err['nFoundForm']; |
28 | 28 | return $this; |
29 | 29 | } |
30 | 30 | |
31 | 31 | $this->form[$this->action][$field] = $test; |
32 | 32 | $this->form[$this->action][$field]['placeholder'] = (null !== $placeholder) ? $placeholder : $test; |
33 | - return $this; |
|
34 | - } |
|
33 | + return $this; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | public function getRules(string $action): Array |
37 | 37 | { |
38 | - return (array_key_exists($action, $this->form)) ? $this->form[$action] : []; |
|
39 | - } |
|
38 | + return (array_key_exists($action, $this->form)) ? $this->form[$action] : []; |
|
39 | + } |
|
40 | 40 | } |
@@ -23,13 +23,13 @@ |
||
23 | 23 | |
24 | 24 | public function field(string $field, array $test, ?string $placeholder = null): Rules |
25 | 25 | { |
26 | - if(empty($this->action)){ |
|
26 | + if (empty($this->action)) { |
|
27 | 27 | self::$errors[] = self::$err['nFoundForm']; |
28 | 28 | return $this; |
29 | 29 | } |
30 | 30 | |
31 | 31 | $this->form[$this->action][$field] = $test; |
32 | - $this->form[$this->action][$field]['placeholder'] = (null !== $placeholder) ? $placeholder : $test; |
|
32 | + $this->form[$this->action][$field]['placeholder'] = (null!==$placeholder) ? $placeholder : $test; |
|
33 | 33 | return $this; |
34 | 34 | } |
35 | 35 |
@@ -16,12 +16,12 @@ discard block |
||
16 | 16 | |
17 | 17 | protected static function array($value): Array |
18 | 18 | { |
19 | - return (is_array($value)) ? $value : [ $value ]; |
|
19 | + return (is_array($value)) ? $value : [$value]; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | protected static function getInstance(?string $lang = null): Validator |
23 | 23 | { |
24 | - self::$lang = (null !== $lang) ? $lang : 'en'; |
|
24 | + self::$lang = (null!==$lang) ? $lang : 'en'; |
|
25 | 25 | self::$instance = (isset(self::$instance)) ? self::$instance : new Validator(); |
26 | 26 | return self::$instance; |
27 | 27 | } |
@@ -33,10 +33,10 @@ discard block |
||
33 | 33 | |
34 | 34 | protected function data($field = null, ?array $values = null) |
35 | 35 | { |
36 | - if(null !== $values){ |
|
36 | + if (null!==$values) { |
|
37 | 37 | $this->data[$field] = $values; |
38 | 38 | } |
39 | - if(null !== $field){ |
|
39 | + if (null!==$field) { |
|
40 | 40 | return $this->data[$field]; |
41 | 41 | } |
42 | 42 | return $this->data; |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | |
45 | 45 | protected function validator(string $model, ?object $callback = null) |
46 | 46 | { |
47 | - if(null !== $callback){ |
|
47 | + if (null!==$callback) { |
|
48 | 48 | $this->validators[$model] = $callback; |
49 | 49 | } |
50 | 50 | return $this->validators[$model]; |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | protected function model(?string $model = null): string |
54 | 54 | { |
55 | - if(null !== $model){ |
|
55 | + if (null!==$model) { |
|
56 | 56 | $this->model = $model; |
57 | 57 | } |
58 | 58 | return $this->model; |
@@ -9,19 +9,19 @@ discard block |
||
9 | 9 | |
10 | 10 | protected function minlength(string $param, int $value): void |
11 | 11 | { |
12 | - if(!self::getInstance()->valid($param, self::getInstance()->data($param))){ |
|
12 | + if (!self::getInstance()->valid($param, self::getInstance()->data($param))) { |
|
13 | 13 | return; |
14 | 14 | } |
15 | 15 | |
16 | - foreach( self::array(self::getInstance()->data($param)) as $val ){ |
|
16 | + foreach (self::array(self::getInstance()->data($param)) as $val) { |
|
17 | 17 | |
18 | - if(strlen($val) === 0) { |
|
19 | - self::getInstance()->error([ $param => self::$err['required'] ]); |
|
18 | + if (strlen($val)===0) { |
|
19 | + self::getInstance()->error([$param => self::$err['required']]); |
|
20 | 20 | continue; |
21 | 21 | } |
22 | 22 | |
23 | - if($value > strlen($val)){ |
|
24 | - self::getInstance()->error([ $param => self::$err['minlength'] ]); |
|
23 | + if ($value>strlen($val)) { |
|
24 | + self::getInstance()->error([$param => self::$err['minlength']]); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | } |
@@ -30,76 +30,76 @@ discard block |
||
30 | 30 | |
31 | 31 | protected function regex(string $param, string $value): void |
32 | 32 | { |
33 | - if(!self::getInstance()->valid($param, self::getInstance()->data($param))){ |
|
33 | + if (!self::getInstance()->valid($param, self::getInstance()->data($param))) { |
|
34 | 34 | return; |
35 | 35 | } |
36 | 36 | |
37 | - foreach(self::array(self::getInstance()->data($param)) as $val){ |
|
38 | - if(!preg_match($value, $val)){ |
|
39 | - self::getInstance()->error([ $param => self::$err['regex'] ]); |
|
37 | + foreach (self::array(self::getInstance()->data($param)) as $val) { |
|
38 | + if (!preg_match($value, $val)) { |
|
39 | + self::getInstance()->error([$param => self::$err['regex']]); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | protected function mincount(string $param, string $value): void |
45 | 45 | { |
46 | - if(!self::getInstance()->valid($param, self::getInstance()->data($param))){ |
|
46 | + if (!self::getInstance()->valid($param, self::getInstance()->data($param))) { |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | - if(count(self::array(self::getInstance()->data($param))) < intval($value)){ |
|
51 | - self::getInstance()->error([ $param => self::$err['mincount'] ]); |
|
50 | + if (count(self::array(self::getInstance()->data($param)))<intval($value)) { |
|
51 | + self::getInstance()->error([$param => self::$err['mincount']]); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | } |
55 | 55 | |
56 | 56 | protected function maxcount(string $param, string $value): void |
57 | 57 | { |
58 | - if(!self::getInstance()->valid($param, self::getInstance()->data($param))){ |
|
58 | + if (!self::getInstance()->valid($param, self::getInstance()->data($param))) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | 61 | |
62 | - if(count(self::array(self::getInstance()->data($param))) > intval($value)){ |
|
63 | - self::getInstance()->error([ $param => self::$err['maxcount'] ]); |
|
62 | + if (count(self::array(self::getInstance()->data($param)))>intval($value)) { |
|
63 | + self::getInstance()->error([$param => self::$err['maxcount']]); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | } |
67 | 67 | |
68 | 68 | protected function equals(string $param, string $value): void |
69 | 69 | { |
70 | - if(!array_key_exists($param, self::getInstance()->data())){ |
|
71 | - self::getInstance()->error([ $param => $value . self::$err['nFoundEquals'] ]); |
|
70 | + if (!array_key_exists($param, self::getInstance()->data())) { |
|
71 | + self::getInstance()->error([$param => $value.self::$err['nFoundEquals']]); |
|
72 | 72 | return; |
73 | 73 | } |
74 | 74 | |
75 | - if(self::getInstance()->data($param) != self::getInstance()->data($value)){ |
|
76 | - self::getInstance()->error([ $param => self::$err['equals'] . ucfirst($value) ]); |
|
75 | + if (self::getInstance()->data($param)!=self::getInstance()->data($value)) { |
|
76 | + self::getInstance()->error([$param => self::$err['equals'].ucfirst($value)]); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | 80 | protected function maxlength(string $param, string $value): void |
81 | 81 | { |
82 | - if(!self::getInstance()->valid($param, self::getInstance()->data($param))){ |
|
82 | + if (!self::getInstance()->valid($param, self::getInstance()->data($param))) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
86 | - foreach( self::array(self::getInstance()->data($param)) as $val ){ |
|
87 | - if(intval($value) < strlen($val)) { |
|
88 | - self::getInstance()->error([ $param => self::$err['maxlength'] ]); |
|
86 | + foreach (self::array(self::getInstance()->data($param)) as $val) { |
|
87 | + if (intval($value)<strlen($val)) { |
|
88 | + self::getInstance()->error([$param => self::$err['maxlength']]); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
93 | 93 | protected function type(string $param, string $value): void |
94 | 94 | { |
95 | - if(!self::getInstance()->valid($param, self::getInstance()->data($param))){ |
|
95 | + if (!self::getInstance()->valid($param, self::getInstance()->data($param))) { |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
99 | 99 | switch ($value) { |
100 | 100 | case 'date': |
101 | - if(!self::getInstance()->validateDate(self::getInstance()->data($param) , 'd/m/Y')){ |
|
102 | - self::getInstance()->error([ $param => self::$err['type'] ]); |
|
101 | + if (!self::getInstance()->validateDate(self::getInstance()->data($param), 'd/m/Y')) { |
|
102 | + self::getInstance()->error([$param => self::$err['type']]); |
|
103 | 103 | } |
104 | 104 | break; |
105 | 105 | } |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | |
109 | 109 | protected function filter(string $param, string $value): void |
110 | 110 | { |
111 | - if(!self::getInstance()->valid($param, self::getInstance()->data($param))){ |
|
111 | + if (!self::getInstance()->valid($param, self::getInstance()->data($param))) { |
|
112 | 112 | return; |
113 | 113 | } |
114 | 114 | |
115 | - if(!filter_var(self::getInstance()->data($param), $value)){ |
|
116 | - self::getInstance()->error([ $param => self::$err['filter'] ]); |
|
115 | + if (!filter_var(self::getInstance()->data($param), $value)) { |
|
116 | + self::getInstance()->error([$param => self::$err['filter']]); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | } |
@@ -6,7 +6,7 @@ |
||
6 | 6 | 'password' => '123456', |
7 | 7 | 'password2' => '1234567777777777777777777777777777777777777777777', |
8 | 8 | 'phones' => [ |
9 | - '949164770','949164771','949164772' |
|
9 | + '949164770', '949164771', '949164772' |
|
10 | 10 | ], |
11 | 11 | 'birth' => '28/09/1996', |
12 | 12 | '_PROVIDER' => 'user', |
@@ -4,18 +4,18 @@ discard block |
||
4 | 4 | |
5 | 5 | use HnrAzevedo\Validator\Validator; |
6 | 6 | |
7 | -try{ |
|
7 | +try { |
|
8 | 8 | |
9 | 9 | /* Checks whether the passed data is valid for the selected function */ |
10 | 10 | $valid = Validator::namespace('HnrAzevedo\\Validator\\Example\\Rules')->lang('pt_br')->execute($data); |
11 | 11 | |
12 | 12 | $errors = []; |
13 | 13 | |
14 | - if(!$valid){ |
|
15 | - foreach(Validator::getErrors() as $err => $message){ |
|
14 | + if (!$valid) { |
|
15 | + foreach (Validator::getErrors() as $err => $message) { |
|
16 | 16 | |
17 | 17 | $errors[] = [ |
18 | - 'input' => $err, // Return name input error |
|
18 | + 'input' => $err, // Return name input error |
|
19 | 19 | 'message' => $message // Return message error |
20 | 20 | ]; |
21 | 21 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /* Transforms validation to Json format to be validated on the client if desired */ |
27 | 27 | $json = Validator::namespace('HnrAzevedo\\Validator\\Example\\Rules')->toJson($data); |
28 | 28 | |
29 | -}catch(Exception $er){ |
|
29 | +}catch (Exception $er) { |
|
30 | 30 | |
31 | 31 | die("Code Error: {$er->getCode()}<br> Line: {$er->getLine()}<br> File: {$er->getFile()}<br> Message: {$er->getMessage()}"); |
32 | 32 |
@@ -11,19 +11,19 @@ |
||
11 | 11 | { |
12 | 12 | Validator::add($this, function(Rules $rules){ |
13 | 13 | $rules->action('login') |
14 | - ->field('email',[ |
|
15 | - 'minlength' => 1, |
|
16 | - 'filter' => FILTER_VALIDATE_EMAIL, |
|
17 | - 'regex' => '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', |
|
18 | - 'required' => true |
|
19 | - ], 'Email address') |
|
20 | - ->field('password',['minlength'=>6,'maxlength'=>20,'required'=>true]) |
|
21 | - ->field('password2',['minlength'=>6,'maxlength'=>20,'equals'=>'password','required'=>true]) |
|
22 | - ->field('remember',['minlength'=>2,'maxlength'=>2,'required'=>false]) |
|
23 | - ->field('birth',['type'=>'date','required'=>true]) |
|
24 | - ->field('phones',['mincount'=>2,'maxcount'=>3,'required'=>true,'minlength'=>8,'maxlength'=>9]); |
|
14 | + ->field('email',[ |
|
15 | + 'minlength' => 1, |
|
16 | + 'filter' => FILTER_VALIDATE_EMAIL, |
|
17 | + 'regex' => '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', |
|
18 | + 'required' => true |
|
19 | + ], 'Email address') |
|
20 | + ->field('password',['minlength'=>6,'maxlength'=>20,'required'=>true]) |
|
21 | + ->field('password2',['minlength'=>6,'maxlength'=>20,'equals'=>'password','required'=>true]) |
|
22 | + ->field('remember',['minlength'=>2,'maxlength'=>2,'required'=>false]) |
|
23 | + ->field('birth',['type'=>'date','required'=>true]) |
|
24 | + ->field('phones',['mincount'=>2,'maxcount'=>3,'required'=>true,'minlength'=>8,'maxlength'=>9]); |
|
25 | 25 | |
26 | - return $rules; |
|
26 | + return $rules; |
|
27 | 27 | }); |
28 | 28 | |
29 | 29 | return $this; |
@@ -5,23 +5,23 @@ |
||
5 | 5 | use HnrAzevedo\Validator\Validator; |
6 | 6 | use HnrAzevedo\Validator\Rules; |
7 | 7 | |
8 | -Class User{ |
|
8 | +Class User { |
|
9 | 9 | |
10 | 10 | public function __construct() |
11 | 11 | { |
12 | - Validator::add($this, function(Rules $rules){ |
|
12 | + Validator::add($this, function(Rules $rules) { |
|
13 | 13 | $rules->action('login') |
14 | - ->field('email',[ |
|
14 | + ->field('email', [ |
|
15 | 15 | 'minlength' => 1, |
16 | 16 | 'filter' => FILTER_VALIDATE_EMAIL, |
17 | 17 | 'regex' => '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', |
18 | 18 | 'required' => true |
19 | 19 | ], 'Email address') |
20 | - ->field('password',['minlength'=>6,'maxlength'=>20,'required'=>true]) |
|
21 | - ->field('password2',['minlength'=>6,'maxlength'=>20,'equals'=>'password','required'=>true]) |
|
22 | - ->field('remember',['minlength'=>2,'maxlength'=>2,'required'=>false]) |
|
23 | - ->field('birth',['type'=>'date','required'=>true]) |
|
24 | - ->field('phones',['mincount'=>2,'maxcount'=>3,'required'=>true,'minlength'=>8,'maxlength'=>9]); |
|
20 | + ->field('password', ['minlength'=>6, 'maxlength'=>20, 'required'=>true]) |
|
21 | + ->field('password2', ['minlength'=>6, 'maxlength'=>20, 'equals'=>'password', 'required'=>true]) |
|
22 | + ->field('remember', ['minlength'=>2, 'maxlength'=>2, 'required'=>false]) |
|
23 | + ->field('birth', ['type'=>'date', 'required'=>true]) |
|
24 | + ->field('phones', ['mincount'=>2, 'maxcount'=>3, 'required'=>true, 'minlength'=>8, 'maxlength'=>9]); |
|
25 | 25 | |
26 | 26 | return $rules; |
27 | 27 | }); |