@@ -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 | } |
@@ -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; |
@@ -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 | } |
@@ -95,24 +95,24 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | self::check_requireds(); |
| 97 | 97 | |
| 98 | - return self::check_errors(); |
|
| 98 | + return self::check_errors(); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | public static function validate() |
| 102 | 102 | { |
| 103 | 103 | foreach ( (self::$validators[self::$model]->getRules(self::$data['role'])) as $key => $value) { |
| 104 | 104 | |
| 105 | - foreach (json_decode(self::$data['data']) as $keyy => $valuee) { |
|
| 105 | + foreach (json_decode(self::$data['data']) as $keyy => $valuee) { |
|
| 106 | 106 | |
| 107 | - if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){ |
|
| 107 | + if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){ |
|
| 108 | 108 | throw new Exception("O campo '{$keyy}' não é esperado para está operação."); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if($keyy===$key){ |
|
| 111 | + if($keyy===$key){ |
|
| 112 | 112 | |
| 113 | 113 | unset(self::$required[$key]); |
| 114 | 114 | |
| 115 | - foreach ($value as $subkey => $subvalue) { |
|
| 115 | + foreach ($value as $subkey => $subvalue) { |
|
| 116 | 116 | try{ |
| 117 | 117 | $function = "check_{$subkey}"; |
| 118 | 118 | self::testMethod($function); |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | self::$errors[] = $exception->getMessage(); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - } |
|
| 125 | - } |
|
| 126 | - } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | self::existRole(self::$model); |
| 154 | 154 | |
| 155 | - foreach ( self::$validators[self::$model]->getRules($request['role']) as $field => $r) { |
|
| 155 | + foreach ( self::$validators[self::$model]->getRules($request['role']) as $field => $r) { |
|
| 156 | 156 | |
| 157 | 157 | $response .= ("{$field}:".json_encode(array_reverse($r))).','; |
| 158 | 158 | |
@@ -163,6 +163,6 @@ discard block |
||
| 163 | 163 | $response = str_replace('{"','',$response); |
| 164 | 164 | $response = str_replace('":',':',$response); |
| 165 | 165 | |
| 166 | - return $response; |
|
| 167 | - } |
|
| 166 | + return $response; |
|
| 167 | + } |
|
| 168 | 168 | } |