@@ -11,30 +11,30 @@ |
||
| 11 | 11 | |
| 12 | 12 | public function __construct(object $model) |
| 13 | 13 | { |
| 14 | - $this->form['model'] = ucfirst(get_class($model)); |
|
| 15 | - } |
|
| 14 | + $this->form['model'] = ucfirst(get_class($model)); |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | 17 | public function setAction(string $action): Rules |
| 18 | 18 | { |
| 19 | - $this->action = $action; |
|
| 20 | - return $this; |
|
| 21 | - } |
|
| 19 | + $this->action = $action; |
|
| 20 | + return $this; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | 23 | public function addField(string $field, array $test): Rules |
| 24 | 24 | { |
| 25 | - if(empty($this->action)){ |
|
| 25 | + if(empty($this->action)){ |
|
| 26 | 26 | throw new Exception("Form action not registered."); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - if(empty($this->form[$this->action][$field])){ |
|
| 29 | + if(empty($this->form[$this->action][$field])){ |
|
| 30 | 30 | $this->form[$this->action][$field] = $test; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - return $this; |
|
| 34 | - } |
|
| 33 | + return $this; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | public function getRules(string $action): ?array |
| 37 | 37 | { |
| 38 | - return (array_key_exists($action, $this->form)) ? $this->form[$action] : null; |
|
| 39 | - } |
|
| 38 | + return (array_key_exists($action, $this->form)) ? $this->form[$action] : null; |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | self::$data = $datas; |
| 71 | 71 | |
| 72 | - self::existData(); |
|
| 72 | + self::existData(); |
|
| 73 | 73 | self::jsonData(); |
| 74 | 74 | self::hasProvider(); |
| 75 | 75 | self::hasRole(); |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | self::$model = get_class(self::getClass('HnrAzevedo\\Validator\\'.ucfirst(self::$data['provider']))); |
| 80 | 80 | |
| 81 | - self::existRole(self::$model); |
|
| 81 | + self::existRole(self::$model); |
|
| 82 | 82 | |
| 83 | - foreach ( (self::$validators[self::$model]->getRules($datas['role'])) as $key => $value) { |
|
| 83 | + foreach ( (self::$validators[self::$model]->getRules($datas['role'])) as $key => $value) { |
|
| 84 | 84 | if(@$value['required'] === true){ |
| 85 | 85 | self::$required[$key] = $value; |
| 86 | 86 | } |
@@ -90,29 +90,29 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | self::check_requireds(); |
| 92 | 92 | |
| 93 | - return true; |
|
| 93 | + return true; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | public static function validate() |
| 97 | 97 | { |
| 98 | 98 | foreach ( (self::$validators[self::$model]->getRules(self::$data['role'])) as $key => $value) { |
| 99 | 99 | |
| 100 | - foreach (json_decode(self::$data['data']) as $keyy => $valuee) { |
|
| 100 | + foreach (json_decode(self::$data['data']) as $keyy => $valuee) { |
|
| 101 | 101 | |
| 102 | - if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){ |
|
| 102 | + if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){ |
|
| 103 | 103 | throw new Exception("O campo '{$keyy}' não é esperado para está operação."); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - if($keyy===$key){ |
|
| 106 | + if($keyy===$key){ |
|
| 107 | 107 | |
| 108 | 108 | unset(self::$required[$key]); |
| 109 | 109 | |
| 110 | - foreach ($value as $subkey => $subvalue) { |
|
| 110 | + foreach ($value as $subkey => $subvalue) { |
|
| 111 | 111 | $function = "check_{$subkey}"; |
| 112 | 112 | self::$function($keyy,$subvalue); |
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | self::existRole(self::$model); |
| 131 | 131 | |
| 132 | - foreach ( self::$validators[self::$model]->getRules($request['role']) as $field => $r) { |
|
| 132 | + foreach ( self::$validators[self::$model]->getRules($request['role']) as $field => $r) { |
|
| 133 | 133 | |
| 134 | 134 | $response .= ("{$field}:".json_encode(array_reverse($r))).','; |
| 135 | 135 | |
@@ -140,6 +140,6 @@ discard block |
||
| 140 | 140 | $response = str_replace('{"','',$response); |
| 141 | 141 | $response = str_replace('":',':',$response); |
| 142 | 142 | |
| 143 | - return $response; |
|
| 144 | - } |
|
| 143 | + return $response; |
|
| 144 | + } |
|
| 145 | 145 | } |
@@ -9,13 +9,13 @@ |
||
| 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('password',['minlength'=>6,'maxlength'=>20,'required'=>true]) |
|
| 14 | - ->addField('password2',['equals'=>'password','required'=>true]) |
|
| 15 | - ->addField('remember',['minlength'=>2,'maxlength'=>2,'required'=>false]) |
|
| 16 | - ->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('password',['minlength'=>6,'maxlength'=>20,'required'=>true]) |
|
| 14 | + ->addField('password2',['equals'=>'password','required'=>true]) |
|
| 15 | + ->addField('remember',['minlength'=>2,'maxlength'=>2,'required'=>false]) |
|
| 16 | + ->addField('phones',['mincount'=>2,'maxcount'=>3,'required'=>true,'minlength'=>8,'maxlength'=>9]); |
|
| 17 | 17 | |
| 18 | - return $rules; |
|
| 18 | + return $rules; |
|
| 19 | 19 | }); |
| 20 | 20 | |
| 21 | 21 | return $this; |