| @@ -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; | 
| @@ -62,7 +62,7 @@ discard block | ||
| 62 | 62 | |
| 63 | 63 | public static function checkDatas() | 
| 64 | 64 |      { | 
| 65 | - self::existData(); | |
| 65 | + self::existData(); | |
| 66 | 66 | self::jsonData(); | 
| 67 | 67 | self::hasProvider(); | 
| 68 | 68 | self::hasRole(); | 
| @@ -78,9 +78,9 @@ discard block | ||
| 78 | 78 | |
| 79 | 79 | self::$model = self::getClass($model); | 
| 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 | } | 
| @@ -92,7 +92,7 @@ discard block | ||
| 92 | 92 | |
| 93 | 93 | self::checkRequireds(); | 
| 94 | 94 | |
| 95 | - return self::checkErrors(); | |
| 95 | + return self::checkErrors(); | |
| 96 | 96 | } | 
| 97 | 97 | |
| 98 | 98 | public static function checkErrors(): bool | 
| @@ -104,23 +104,23 @@ discard block | ||
| 104 | 104 |      { | 
| 105 | 105 |          foreach ( (self::$validators[self::$model]->getRules(self::$data['role'])) as $key => $value) { | 
| 106 | 106 | |
| 107 | -			foreach (json_decode(self::$data['data']) as $keyy => $valuee) { | |
| 107 | +            foreach (json_decode(self::$data['data']) as $keyy => $valuee) { | |
| 108 | 108 | |
| 109 | -				if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){ | |
| 109 | +                if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){ | |
| 110 | 110 |                      throw new Exception("O campo '{$keyy}' não é esperado para está operação."); | 
| 111 | 111 | } | 
| 112 | 112 | |
| 113 | -				if($keyy===$key){ | |
| 113 | +                if($keyy===$key){ | |
| 114 | 114 | |
| 115 | 115 | unset(self::$required[$key]); | 
| 116 | 116 | |
| 117 | -					foreach ($value as $subkey => $subvalue) { | |
| 117 | +                    foreach ($value as $subkey => $subvalue) { | |
| 118 | 118 | $function = "check".ucfirst($subkey); | 
| 119 | 119 | self::testMethod($function); | 
| 120 | 120 | self::$function($keyy,$subvalue); | 
| 121 | - } | |
| 122 | - } | |
| 123 | - } | |
| 121 | + } | |
| 122 | + } | |
| 123 | + } | |
| 124 | 124 | } | 
| 125 | 125 | } | 
| 126 | 126 | |
| @@ -149,7 +149,7 @@ discard block | ||
| 149 | 149 | |
| 150 | 150 | self::existRole(self::$model); | 
| 151 | 151 | |
| 152 | -		foreach ( self::$validators[self::$model]->getRules($request['role'])  as $field => $r) { | |
| 152 | +        foreach ( self::$validators[self::$model]->getRules($request['role'])  as $field => $r) { | |
| 153 | 153 | $r = self::replaceRegex($r); | 
| 154 | 154 |              $response .= ("{$field}:".json_encode(array_reverse($r))).','; | 
| 155 | 155 | } |