@@ -9,30 +9,30 @@ |
||
9 | 9 | |
10 | 10 | public function __construct(object $model) |
11 | 11 | { |
12 | - $this->form['model'] = ucfirst(get_class($model)); |
|
13 | - } |
|
12 | + $this->form['model'] = ucfirst(get_class($model)); |
|
13 | + } |
|
14 | 14 | |
15 | 15 | public function setAction(string $action): Rules |
16 | 16 | { |
17 | - $this->action = $action; |
|
18 | - return $this; |
|
19 | - } |
|
17 | + $this->action = $action; |
|
18 | + return $this; |
|
19 | + } |
|
20 | 20 | |
21 | 21 | public function addField(string $field, array $test): Rules |
22 | 22 | { |
23 | - if(empty($this->action)){ |
|
23 | + if(empty($this->action)){ |
|
24 | 24 | self::$errors[] = "Form action not registered."; |
25 | 25 | } |
26 | 26 | |
27 | - if(empty($this->form[$this->action][$field])){ |
|
27 | + if(empty($this->form[$this->action][$field])){ |
|
28 | 28 | $this->form[$this->action][$field] = $test; |
29 | 29 | } |
30 | 30 | |
31 | - return $this; |
|
32 | - } |
|
31 | + return $this; |
|
32 | + } |
|
33 | 33 | |
34 | 34 | public function getRules(string $action): ?array |
35 | 35 | { |
36 | - return (array_key_exists($action, $this->form)) ? $this->form[$action] : null; |
|
37 | - } |
|
36 | + return (array_key_exists($action, $this->form)) ? $this->form[$action] : null; |
|
37 | + } |
|
38 | 38 | } |
@@ -11,15 +11,15 @@ |
||
11 | 11 | { |
12 | 12 | Validator::add($this, function(Rules $rules){ |
13 | 13 | $rules->setAction('login') |
14 | - //->addField('email',['minlength'=>1,'regex'=>'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/','required'=>true]) |
|
15 | - ->addField('email',['minlength'=>1,'filter'=>FILTER_VALIDATE_EMAIL,'required'=>true]) |
|
16 | - ->addField('password',['minlength'=>6,'maxlength'=>20,'required'=>true]) |
|
17 | - ->addField('password2',['equals'=>'password','required'=>true]) |
|
18 | - ->addField('remember',['minlength'=>2,'maxlength'=>2,'required'=>false]) |
|
19 | - ->addField('birth',['type'=>'date','required'=>true]) |
|
20 | - ->addField('phones',['mincount'=>2,'maxcount'=>3,'required'=>true,'minlength'=>8,'maxlength'=>9]); |
|
14 | + //->addField('email',['minlength'=>1,'regex'=>'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/','required'=>true]) |
|
15 | + ->addField('email',['minlength'=>1,'filter'=>FILTER_VALIDATE_EMAIL,'required'=>true]) |
|
16 | + ->addField('password',['minlength'=>6,'maxlength'=>20,'required'=>true]) |
|
17 | + ->addField('password2',['equals'=>'password','required'=>true]) |
|
18 | + ->addField('remember',['minlength'=>2,'maxlength'=>2,'required'=>false]) |
|
19 | + ->addField('birth',['type'=>'date','required'=>true]) |
|
20 | + ->addField('phones',['mincount'=>2,'maxcount'=>3,'required'=>true,'minlength'=>8,'maxlength'=>9]); |
|
21 | 21 | |
22 | - return $rules; |
|
22 | + return $rules; |
|
23 | 23 | }); |
24 | 24 | |
25 | 25 | return $this; |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | self::getInstance()->errors[] = $er->getMessage(); |
77 | 77 | } |
78 | 78 | |
79 | - return self::checkErrors(); |
|
79 | + return self::checkErrors(); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | public static function checkErrors(): bool |
@@ -88,21 +88,21 @@ discard block |
||
88 | 88 | { |
89 | 89 | foreach ( (self::getInstance()->validators[self::getInstance()->model]->getRules(self::getInstance()->data['ROLE'])) as $key => $value) { |
90 | 90 | |
91 | - foreach (self::getInstance()->data as $keyy => $valuee) { |
|
91 | + foreach (self::getInstance()->data as $keyy => $valuee) { |
|
92 | 92 | |
93 | - self::getInstance()->checkExpected($keyy); |
|
93 | + self::getInstance()->checkExpected($keyy); |
|
94 | 94 | |
95 | - if($keyy===$key){ |
|
95 | + if($keyy===$key){ |
|
96 | 96 | |
97 | 97 | unset(self::getInstance()->required[$key]); |
98 | 98 | |
99 | - foreach ($value as $subkey => $subvalue) { |
|
99 | + foreach ($value as $subkey => $subvalue) { |
|
100 | 100 | $function = "check".ucfirst($subkey); |
101 | 101 | self::getInstance()->testMethod($function); |
102 | 102 | self::getInstance()->$function($keyy, $subvalue); |
103 | - } |
|
104 | - } |
|
105 | - } |
|
103 | + } |
|
104 | + } |
|
105 | + } |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | self::getInstance()->existRole(self::getInstance()->model); |
142 | 142 | |
143 | - foreach ( self::getInstance()->validators[self::getInstance()->model]->getRules($request['ROLE']) as $field => $r) { |
|
143 | + foreach ( self::getInstance()->validators[self::getInstance()->model]->getRules($request['ROLE']) as $field => $r) { |
|
144 | 144 | $r = self::getInstance()->replaceRegex($r); |
145 | 145 | $response .= ("{$field}:".json_encode(array_reverse($r))).','; |
146 | 146 | } |