@@ -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 | } |
@@ -12,15 +12,15 @@ |
||
12 | 12 | |
13 | 13 | Validator::add($this, function(Rules $rules){ |
14 | 14 | $rules->setAction('login') |
15 | - //->addField('email',['minlength'=>1,'regex'=>'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/','required'=>true]) |
|
16 | - ->addField('email',['minlength'=>1,'filter'=>FILTER_VALIDATE_EMAIL,'required'=>true]) |
|
17 | - ->addField('password',['minlength'=>6,'maxlength'=>20,'required'=>true]) |
|
18 | - ->addField('password2',['equals'=>'password','required'=>true]) |
|
19 | - ->addField('remember',['minlength'=>2,'maxlength'=>2,'required'=>false]) |
|
20 | - ->addField('birth',['type'=>'date','required'=>true]) |
|
21 | - ->addField('phones',['mincount'=>2,'maxcount'=>3,'required'=>true,'minlength'=>8,'maxlength'=>9]); |
|
22 | - |
|
23 | - return $rules; |
|
15 | + //->addField('email',['minlength'=>1,'regex'=>'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/','required'=>true]) |
|
16 | + ->addField('email',['minlength'=>1,'filter'=>FILTER_VALIDATE_EMAIL,'required'=>true]) |
|
17 | + ->addField('password',['minlength'=>6,'maxlength'=>20,'required'=>true]) |
|
18 | + ->addField('password2',['equals'=>'password','required'=>true]) |
|
19 | + ->addField('remember',['minlength'=>2,'maxlength'=>2,'required'=>false]) |
|
20 | + ->addField('birth',['type'=>'date','required'=>true]) |
|
21 | + ->addField('phones',['mincount'=>2,'maxcount'=>3,'required'=>true,'minlength'=>8,'maxlength'=>9]); |
|
22 | + |
|
23 | + return $rules; |
|
24 | 24 | }); |
25 | 25 | |
26 | 26 | return $this; |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | |
65 | 65 | self::$model = self::getClass($model); |
66 | 66 | |
67 | - self::existRole(self::$model); |
|
67 | + self::existRole(self::$model); |
|
68 | 68 | |
69 | - foreach ( (self::$validators[self::$model]->getRules($data['ROLE'])) as $key => $value) { |
|
69 | + foreach ( (self::$validators[self::$model]->getRules($data['ROLE'])) as $key => $value) { |
|
70 | 70 | if(@$value['required'] === true){ |
71 | 71 | self::$required[$key] = $value; |
72 | 72 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | self::checkRequireds(); |
80 | 80 | |
81 | - return self::checkErrors(); |
|
81 | + return self::checkErrors(); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | public static function checkErrors(): bool |
@@ -90,23 +90,23 @@ discard block |
||
90 | 90 | { |
91 | 91 | foreach ( (self::$validators[self::$model]->getRules(self::$data['ROLE'])) as $key => $value) { |
92 | 92 | |
93 | - foreach (self::$data as $keyy => $valuee) { |
|
93 | + foreach (self::$data as $keyy => $valuee) { |
|
94 | 94 | |
95 | - if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['ROLE'])) ) && !in_array($keyy,self::getInstance()->defaultData)){ |
|
95 | + if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['ROLE'])) ) && !in_array($keyy,self::getInstance()->defaultData)){ |
|
96 | 96 | throw new \RuntimeException("O campo '{$keyy}' não é esperado para está operação."); |
97 | 97 | } |
98 | 98 | |
99 | - if($keyy===$key){ |
|
99 | + if($keyy===$key){ |
|
100 | 100 | |
101 | 101 | unset(self::$required[$key]); |
102 | 102 | |
103 | - foreach ($value as $subkey => $subvalue) { |
|
103 | + foreach ($value as $subkey => $subvalue) { |
|
104 | 104 | $function = "check".ucfirst($subkey); |
105 | 105 | self::testMethod($function); |
106 | 106 | self::$function($keyy,$subvalue); |
107 | - } |
|
108 | - } |
|
109 | - } |
|
107 | + } |
|
108 | + } |
|
109 | + } |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | |
138 | 138 | self::existRole(self::$model); |
139 | 139 | |
140 | - foreach ( self::$validators[self::$model]->getRules($request['ROLE']) as $field => $r) { |
|
140 | + foreach ( self::$validators[self::$model]->getRules($request['ROLE']) as $field => $r) { |
|
141 | 141 | $r = self::replaceRegex($r); |
142 | 142 | $response .= ("{$field}:".json_encode(array_reverse($r))).','; |
143 | 143 | } |