@@ -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 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | private static function getClass(string $class) |
| 53 | 53 | { |
| 54 | 54 | if(!class_exists($class)){ |
| 55 | - $class = basename($class); |
|
| 55 | + $class = basename($class); |
|
| 56 | 56 | throw new Exception("Form ID {$class} inválido."); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | public static function checkDatas() |
| 70 | 70 | { |
| 71 | - self::existData(); |
|
| 71 | + self::existData(); |
|
| 72 | 72 | self::jsonData(); |
| 73 | 73 | self::hasProvider(); |
| 74 | 74 | self::hasRole(); |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | self::$model = get_class(self::getClass('HnrAzevedo\\Validator\\'.ucfirst(self::$data['provider']))); |
| 86 | 86 | |
| 87 | - self::existRole(self::$model); |
|
| 87 | + self::existRole(self::$model); |
|
| 88 | 88 | |
| 89 | - foreach ( (self::$validators[self::$model]->getRules($datas['role'])) as $key => $value) { |
|
| 89 | + foreach ( (self::$validators[self::$model]->getRules($datas['role'])) as $key => $value) { |
|
| 90 | 90 | if(@$value['required'] === true){ |
| 91 | 91 | self::$required[$key] = $value; |
| 92 | 92 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | self::check_requireds(); |
| 100 | 100 | |
| 101 | - return self::check_errors(); |
|
| 101 | + return self::check_errors(); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | public static function check_errors(): bool |
@@ -110,23 +110,23 @@ discard block |
||
| 110 | 110 | { |
| 111 | 111 | foreach ( (self::$validators[self::$model]->getRules(self::$data['role'])) as $key => $value) { |
| 112 | 112 | |
| 113 | - foreach (json_decode(self::$data['data']) as $keyy => $valuee) { |
|
| 113 | + foreach (json_decode(self::$data['data']) as $keyy => $valuee) { |
|
| 114 | 114 | |
| 115 | - if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){ |
|
| 115 | + if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){ |
|
| 116 | 116 | throw new Exception("O campo '{$keyy}' não é esperado para está operação."); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if($keyy===$key){ |
|
| 119 | + if($keyy===$key){ |
|
| 120 | 120 | |
| 121 | 121 | unset(self::$required[$key]); |
| 122 | 122 | |
| 123 | - foreach ($value as $subkey => $subvalue) { |
|
| 123 | + foreach ($value as $subkey => $subvalue) { |
|
| 124 | 124 | $function = "check_{$subkey}"; |
| 125 | 125 | self::testMethod($function); |
| 126 | 126 | self::$function($keyy,$subvalue); |
| 127 | - } |
|
| 128 | - } |
|
| 129 | - } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | self::existRole(self::$model); |
| 157 | 157 | |
| 158 | - foreach ( self::$validators[self::$model]->getRules($request['role']) as $field => $r) { |
|
| 158 | + foreach ( self::$validators[self::$model]->getRules($request['role']) as $field => $r) { |
|
| 159 | 159 | $r = self::replaceRegex($r); |
| 160 | 160 | $response .= ("{$field}:".json_encode(array_reverse($r))).','; |
| 161 | 161 | } |