@@ -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 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | self::$errors[] = $er->getMessage(); |
82 | 82 | } |
83 | 83 | |
84 | - return self::checkErrors(); |
|
84 | + return self::checkErrors(); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | public static function checkErrors(): bool |
@@ -93,23 +93,23 @@ discard block |
||
93 | 93 | { |
94 | 94 | foreach ( (self::$validators[self::$model]->getRules(self::$data['ROLE'])) as $key => $value) { |
95 | 95 | |
96 | - foreach (self::$data as $keyy => $valuee) { |
|
96 | + foreach (self::$data as $keyy => $valuee) { |
|
97 | 97 | |
98 | - if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['ROLE'])) ) && !in_array($keyy,self::getInstance()->defaultData)){ |
|
98 | + if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['ROLE'])) ) && !in_array($keyy,self::getInstance()->defaultData)){ |
|
99 | 99 | throw new \RuntimeException("O campo '{$keyy}' não é esperado para está operação"); |
100 | 100 | } |
101 | 101 | |
102 | - if($keyy===$key){ |
|
102 | + if($keyy===$key){ |
|
103 | 103 | |
104 | 104 | unset(self::$required[$key]); |
105 | 105 | |
106 | - foreach ($value as $subkey => $subvalue) { |
|
106 | + foreach ($value as $subkey => $subvalue) { |
|
107 | 107 | $function = "check".ucfirst($subkey); |
108 | 108 | self::testMethod($function); |
109 | 109 | self::$function($keyy,$subvalue); |
110 | - } |
|
111 | - } |
|
112 | - } |
|
110 | + } |
|
111 | + } |
|
112 | + } |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | self::existRole(self::$model); |
142 | 142 | |
143 | - foreach ( self::$validators[self::$model]->getRules($request['ROLE']) as $field => $r) { |
|
143 | + foreach ( self::$validators[self::$model]->getRules($request['ROLE']) as $field => $r) { |
|
144 | 144 | $r = self::replaceRegex($r); |
145 | 145 | $response .= ("{$field}:".json_encode(array_reverse($r))).','; |
146 | 146 | } |
@@ -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; |