@@ -9,15 +9,15 @@ |
||
| 9 | 9 | |
| 10 | 10 | Validator::add($this, function(Rules $rules){ |
| 11 | 11 | $rules->setAction('login') |
| 12 | - //->addField('email',['minlength'=>1,'regex'=>'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/','required'=>true]) |
|
| 13 | - ->addField('email',['minlength'=>1,'filter'=>FILTER_VALIDATE_EMAIL,'required'=>true]) |
|
| 14 | - ->addField('password',['minlength'=>6,'maxlength'=>20,'required'=>true]) |
|
| 15 | - ->addField('password2',['equals'=>'password','required'=>true]) |
|
| 16 | - ->addField('remember',['minlength'=>2,'maxlength'=>2,'required'=>false]) |
|
| 17 | - ->addField('birth',['type'=>'date','required'=>true]) |
|
| 18 | - ->addField('phones',['mincount'=>2,'maxcount'=>3,'required'=>true,'minlength'=>8,'maxlength'=>9]); |
|
| 12 | + //->addField('email',['minlength'=>1,'regex'=>'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/','required'=>true]) |
|
| 13 | + ->addField('email',['minlength'=>1,'filter'=>FILTER_VALIDATE_EMAIL,'required'=>true]) |
|
| 14 | + ->addField('password',['minlength'=>6,'maxlength'=>20,'required'=>true]) |
|
| 15 | + ->addField('password2',['equals'=>'password','required'=>true]) |
|
| 16 | + ->addField('remember',['minlength'=>2,'maxlength'=>2,'required'=>false]) |
|
| 17 | + ->addField('birth',['type'=>'date','required'=>true]) |
|
| 18 | + ->addField('phones',['mincount'=>2,'maxcount'=>3,'required'=>true,'minlength'=>8,'maxlength'=>9]); |
|
| 19 | 19 | |
| 20 | - return $rules; |
|
| 20 | + return $rules; |
|
| 21 | 21 | }); |
| 22 | 22 | |
| 23 | 23 | return $this; |
@@ -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 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | public static function checkDatas() |
| 69 | 69 | { |
| 70 | - self::existData(); |
|
| 70 | + self::existData(); |
|
| 71 | 71 | self::jsonData(); |
| 72 | 72 | self::hasProvider(); |
| 73 | 73 | self::hasRole(); |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | self::$model = get_class(self::getClass('HnrAzevedo\\Validator\\'.ucfirst(self::$data['provider']))); |
| 85 | 85 | |
| 86 | - self::existRole(self::$model); |
|
| 86 | + self::existRole(self::$model); |
|
| 87 | 87 | |
| 88 | - foreach ( (self::$validators[self::$model]->getRules($datas['role'])) as $key => $value) { |
|
| 88 | + foreach ( (self::$validators[self::$model]->getRules($datas['role'])) as $key => $value) { |
|
| 89 | 89 | if(@$value['required'] === true){ |
| 90 | 90 | self::$required[$key] = $value; |
| 91 | 91 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | self::check_requireds(); |
| 99 | 99 | |
| 100 | - return self::check_errors(); |
|
| 100 | + return self::check_errors(); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | public static function check_errors(): bool |
@@ -109,23 +109,23 @@ discard block |
||
| 109 | 109 | { |
| 110 | 110 | foreach ( (self::$validators[self::$model]->getRules(self::$data['role'])) as $key => $value) { |
| 111 | 111 | |
| 112 | - foreach (json_decode(self::$data['data']) as $keyy => $valuee) { |
|
| 112 | + foreach (json_decode(self::$data['data']) as $keyy => $valuee) { |
|
| 113 | 113 | |
| 114 | - if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){ |
|
| 114 | + if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){ |
|
| 115 | 115 | throw new Exception("O campo '{$keyy}' não é esperado para está operação."); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - if($keyy===$key){ |
|
| 118 | + if($keyy===$key){ |
|
| 119 | 119 | |
| 120 | 120 | unset(self::$required[$key]); |
| 121 | 121 | |
| 122 | - foreach ($value as $subkey => $subvalue) { |
|
| 122 | + foreach ($value as $subkey => $subvalue) { |
|
| 123 | 123 | $function = "check_{$subkey}"; |
| 124 | 124 | self::testMethod($function); |
| 125 | 125 | self::$function($keyy,$subvalue); |
| 126 | - } |
|
| 127 | - } |
|
| 128 | - } |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | self::existRole(self::$model); |
| 156 | 156 | |
| 157 | - foreach ( self::$validators[self::$model]->getRules($request['role']) as $field => $r) { |
|
| 157 | + foreach ( self::$validators[self::$model]->getRules($request['role']) as $field => $r) { |
|
| 158 | 158 | |
| 159 | 159 | $response .= ("{$field}:".json_encode(array_reverse($r))).','; |
| 160 | 160 | |
@@ -165,6 +165,6 @@ discard block |
||
| 165 | 165 | $response = str_replace('{"','',$response); |
| 166 | 166 | $response = str_replace('":',':',$response); |
| 167 | 167 | |
| 168 | - return $response; |
|
| 169 | - } |
|
| 168 | + return $response; |
|
| 169 | + } |
|
| 170 | 170 | } |