@@ -11,38 +11,38 @@ |
||
11 | 11 | { |
12 | 12 | Validator::add($this, function(Rules $rules){ |
13 | 13 | $rules->action('login') |
14 | - ->field( |
|
15 | - 'field_email', |
|
16 | - ['minlength' => 1, 'filter' => FILTER_VALIDATE_EMAIL, 'regex' => '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', 'required' => true], |
|
17 | - 'Email address' |
|
14 | + ->field( |
|
15 | + 'field_email', |
|
16 | + ['minlength' => 1, 'filter' => FILTER_VALIDATE_EMAIL, 'regex' => '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', 'required' => true], |
|
17 | + 'Email address' |
|
18 | 18 | ) |
19 | - ->field( |
|
20 | - 'field_password', |
|
21 | - ['minlength' => 6, 'maxlength' => 20, 'required' => true], |
|
22 | - 'Password' |
|
19 | + ->field( |
|
20 | + 'field_password', |
|
21 | + ['minlength' => 6, 'maxlength' => 20, 'required' => true], |
|
22 | + 'Password' |
|
23 | 23 | ) |
24 | - ->field( |
|
25 | - 'field_password2', |
|
26 | - ['minlength' => 6, 'maxlength' => 20, 'equals' => 'field_password', 'required' => true], |
|
27 | - 'Confirm password' |
|
24 | + ->field( |
|
25 | + 'field_password2', |
|
26 | + ['minlength' => 6, 'maxlength' => 20, 'equals' => 'field_password', 'required' => true], |
|
27 | + 'Confirm password' |
|
28 | 28 | ) |
29 | - ->field( |
|
30 | - 'field_remember', |
|
31 | - ['minlength' => 2, 'maxlength' => 2, 'required' => false], |
|
32 | - 'Keep connected' |
|
29 | + ->field( |
|
30 | + 'field_remember', |
|
31 | + ['minlength' => 2, 'maxlength' => 2, 'required' => false], |
|
32 | + 'Keep connected' |
|
33 | 33 | ) |
34 | - ->field( |
|
35 | - 'field_birth', |
|
36 | - ['type' => 'date', 'required' => true], |
|
37 | - 'Date of birth' |
|
34 | + ->field( |
|
35 | + 'field_birth', |
|
36 | + ['type' => 'date', 'required' => true], |
|
37 | + 'Date of birth' |
|
38 | 38 | ) |
39 | - ->field( |
|
40 | - 'field_phones', |
|
41 | - ['mincount' => 2, 'maxcount' => 3, 'required' => true, 'minlength' => 8, 'maxlength' => 9], |
|
42 | - 'Phones' |
|
39 | + ->field( |
|
40 | + 'field_phones', |
|
41 | + ['mincount' => 2, 'maxcount' => 3, 'required' => true, 'minlength' => 8, 'maxlength' => 9], |
|
42 | + 'Phones' |
|
43 | 43 | ); |
44 | 44 | |
45 | - return $rules; |
|
45 | + return $rules; |
|
46 | 46 | }); |
47 | 47 | } |
48 | 48 |
@@ -11,29 +11,29 @@ |
||
11 | 11 | |
12 | 12 | public function __construct(string $model) |
13 | 13 | { |
14 | - $this->form['model'] = ucfirst($model); |
|
15 | - } |
|
14 | + $this->form['model'] = ucfirst($model); |
|
15 | + } |
|
16 | 16 | |
17 | 17 | public function action(string $action): Rules |
18 | 18 | { |
19 | - $this->action = $action; |
|
20 | - return $this; |
|
21 | - } |
|
19 | + $this->action = $action; |
|
20 | + return $this; |
|
21 | + } |
|
22 | 22 | |
23 | 23 | public function field(string $field, array $test, ?string $placeholder = null): Rules |
24 | 24 | { |
25 | - if(empty($this->action)){ |
|
25 | + if(empty($this->action)){ |
|
26 | 26 | $this->error([ 'form' => self::$err['nFoundForm'] ]); |
27 | 27 | return $this; |
28 | 28 | } |
29 | 29 | |
30 | 30 | $this->form[$this->action][$field] = $test; |
31 | 31 | $this->form[$this->action][$field]['placeholder'] = (null !== $placeholder) ? $placeholder : $field; |
32 | - return $this; |
|
33 | - } |
|
32 | + return $this; |
|
33 | + } |
|
34 | 34 | |
35 | 35 | public function getRules(string $action): Array |
36 | 36 | { |
37 | - return (array_key_exists($action, $this->form)) ? $this->form[$action] : []; |
|
38 | - } |
|
37 | + return (array_key_exists($action, $this->form)) ? $this->form[$action] : []; |
|
38 | + } |
|
39 | 39 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | self::getInstance()->errors[] = ['form' => $er->getMessage()]; |
93 | 93 | } |
94 | 94 | |
95 | - return self::errors(); |
|
95 | + return self::errors(); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | public static function errors(): bool |
@@ -104,24 +104,24 @@ discard block |
||
104 | 104 | { |
105 | 105 | foreach ( (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) as $key => $value) { |
106 | 106 | |
107 | - foreach (self::getInstance()->data as $keyy => $valuee) { |
|
107 | + foreach (self::getInstance()->data as $keyy => $valuee) { |
|
108 | 108 | |
109 | - self::getInstance()->checkExpected($keyy); |
|
109 | + self::getInstance()->checkExpected($keyy); |
|
110 | 110 | |
111 | - if($keyy!==$key){ |
|
111 | + if($keyy!==$key){ |
|
112 | 112 | continue; |
113 | 113 | } |
114 | 114 | |
115 | 115 | unset(self::getInstance()->required[$key]); |
116 | 116 | |
117 | - foreach ($value as $subkey => $subvalue) { |
|
117 | + foreach ($value as $subkey => $subvalue) { |
|
118 | 118 | |
119 | 119 | $function = strtolower($subkey); |
120 | 120 | |
121 | 121 | self::getInstance()->hasMethod($function)->$function($keyy, $subvalue, (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) ); |
122 | 122 | } |
123 | 123 | |
124 | - } |
|
124 | + } |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | |
162 | 162 | self::getInstance()->existRole(self::getInstance()->model()); |
163 | 163 | |
164 | - foreach ( self::getInstance()->validator(self::getInstance()->model())->getRules($request['_ROLE']) as $field => $r) { |
|
164 | + foreach ( self::getInstance()->validator(self::getInstance()->model())->getRules($request['_ROLE']) as $field => $r) { |
|
165 | 165 | $r = self::getInstance()->replaceRegex($r); |
166 | 166 | $response .= ("'$field':".json_encode(array_reverse($r))).','; |
167 | 167 | } |
@@ -12,8 +12,8 @@ |
||
12 | 12 | { |
13 | 13 | return $handler->handle($request->withAttribute('validator', [ |
14 | 14 | 'valid' => self::lang($this->requestLang($request)) |
15 | - ->namespace($this->requestNamespace($request)) |
|
16 | - ->execute($this->requestData($request)), |
|
15 | + ->namespace($this->requestNamespace($request)) |
|
16 | + ->execute($this->requestData($request)), |
|
17 | 17 | 'errors' => self::getErrors() |
18 | 18 | ])); |
19 | 19 | } |