@@ -77,7 +77,7 @@ |
||
77 | 77 | |
78 | 78 | runMiddlewares($serverRequest); |
79 | 79 | |
80 | -}catch(Exception $er){ |
|
80 | +} catch(Exception $er){ |
|
81 | 81 | |
82 | 82 | die("Code Error: {$er->getCode()}<br>Line: {$er->getLine()}<br>File: {$er->getFile()}<br>Message: {$er->getMessage()}."); |
83 | 83 |
@@ -11,24 +11,24 @@ discard block |
||
11 | 11 | use Psr\Http\Message\ResponseInterface; |
12 | 12 | use Psr\Http\Server\MiddlewareInterface; |
13 | 13 | |
14 | -try{ |
|
14 | +try { |
|
15 | 15 | $serverRequest = (new Factory())->createServerRequest('GET', new Uri('/')); |
16 | - $serverRequest = $serverRequest->withAttribute('validator',[ |
|
16 | + $serverRequest = $serverRequest->withAttribute('validator', [ |
|
17 | 17 | 'namespace' => 'HnrAzevedo\\Validator\\Example\\Rules', |
18 | 18 | 'data' => $data, |
19 | 19 | 'lang' => 'pt_br' |
20 | 20 | ]); |
21 | 21 | |
22 | - class App implements MiddlewareInterface{ |
|
22 | + class App implements MiddlewareInterface { |
|
23 | 23 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
24 | 24 | { |
25 | - if(!$request->getAttribute('validator')['valid']){ |
|
25 | + if (!$request->getAttribute('validator')['valid']) { |
|
26 | 26 | |
27 | 27 | $errors = []; |
28 | 28 | |
29 | - foreach($request->getAttribute('validator')['errors'] as $error){ |
|
29 | + foreach ($request->getAttribute('validator')['errors'] as $error) { |
|
30 | 30 | $errors[] = [ |
31 | - 'input' => array_keys($error)[0], // Return name input error |
|
31 | + 'input' => array_keys($error)[0], // Return name input error |
|
32 | 32 | 'message' => array_values($error)[0] // Return message error |
33 | 33 | ]; |
34 | 34 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | - define('GLOBAL_MIDDLEWARES',[ |
|
45 | + define('GLOBAL_MIDDLEWARES', [ |
|
46 | 46 | Validator::class, |
47 | 47 | App::class |
48 | 48 | ]); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | function runMiddlewares($serverRequest) |
80 | 80 | { |
81 | - nextExample(new class implements RequestHandlerInterface{ |
|
81 | + nextExample(new class implements RequestHandlerInterface { |
|
82 | 82 | public function handle(ServerRequestInterface $request): ResponseInterface |
83 | 83 | { |
84 | 84 | return (new Factory())->createResponse(200); |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | |
89 | 89 | runMiddlewares($serverRequest); |
90 | 90 | |
91 | -}catch(Exception $er){ |
|
91 | +}catch (Exception $er) { |
|
92 | 92 | |
93 | 93 | die("Code Error: {$er->getCode()}<br>Line: {$er->getLine()}<br>File: {$er->getFile()}<br>Message: {$er->getMessage()}."); |
94 | 94 |
@@ -23,7 +23,7 @@ |
||
23 | 23 | /* Transforms validation to Json format to be validated on the client if desired */ |
24 | 24 | $json = Validator::namespace('HnrAzevedo\\Validator\\Example\\Rules')->toJson($data); |
25 | 25 | |
26 | -}catch(Exception $er){ |
|
26 | +} catch(Exception $er){ |
|
27 | 27 | |
28 | 28 | die("Code Error: {$er->getCode()}<br> Line: {$er->getLine()}<br> File: {$er->getFile()}<br> Message: {$er->getMessage()}"); |
29 | 29 |
@@ -4,17 +4,17 @@ discard block |
||
4 | 4 | |
5 | 5 | use HnrAzevedo\Validator\Validator; |
6 | 6 | |
7 | -try{ |
|
7 | +try { |
|
8 | 8 | |
9 | 9 | /* Checks whether the passed data is valid for the selected function */ |
10 | 10 | $valid = Validator::lang('pt_br')->namespace('HnrAzevedo\\Validator\\Example\\Rules')->execute($data); |
11 | 11 | |
12 | 12 | $errors = []; |
13 | 13 | |
14 | - if(!$valid){ |
|
15 | - foreach(Validator::getErrors() as $error){ |
|
14 | + if (!$valid) { |
|
15 | + foreach (Validator::getErrors() as $error) { |
|
16 | 16 | $errors[] = [ |
17 | - 'input' => array_keys($error)[0], // Return name input error |
|
17 | + 'input' => array_keys($error)[0], // Return name input error |
|
18 | 18 | 'message' => array_values($error)[0] // Return message error |
19 | 19 | ]; |
20 | 20 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /* Transforms validation to Json format to be validated on the client if desired */ |
26 | 26 | $json = Validator::namespace('HnrAzevedo\\Validator\\Example\\Rules')->toJson($data); |
27 | 27 | |
28 | -}catch(Exception $er){ |
|
28 | +}catch (Exception $er) { |
|
29 | 29 | |
30 | 30 | die("Code Error: {$er->getCode()}<br> Line: {$er->getLine()}<br> File: {$er->getFile()}<br> Message: {$er->getMessage()}"); |
31 | 31 |
@@ -8,15 +8,15 @@ discard block |
||
8 | 8 | |
9 | 9 | protected function requireds(): void |
10 | 10 | { |
11 | - if(count(self::getInstance()->required()) > 0){ |
|
12 | - self::getInstance()->error([ self::$err['needed'].implode(', ', array_keys(self::getInstance()->required())) ]); |
|
11 | + if (count(self::getInstance()->required())>0) { |
|
12 | + self::getInstance()->error([self::$err['needed'].implode(', ', array_keys(self::getInstance()->required()))]); |
|
13 | 13 | } |
14 | 14 | } |
15 | 15 | |
16 | 16 | public function validateDate($date, $format = 'Y-m-d H:i:s') |
17 | 17 | { |
18 | 18 | $d = \DateTime::createFromFormat($format, $date); |
19 | - return $d && $d->format($format) == $date; |
|
19 | + return $d && $d->format($format)==$date; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | protected function isRequired(string $param): bool |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | protected function valid(string $param, $value): bool |
29 | 29 | { |
30 | - return (self::getInstance()->isRequired($param) || strlen($value > 0)); |
|
30 | + return (self::getInstance()->isRequired($param) || strlen($value>0)); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | } |
@@ -11,38 +11,38 @@ |
||
11 | 11 | { |
12 | 12 | Validator::add($this, function(Rules $rules){ |
13 | 13 | $rules->action('login') |
14 | - ->field( |
|
15 | - 'field_email', |
|
16 | - ['minlength' => 1, 'filter' => FILTER_VALIDATE_EMAIL, 'regex' => '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', 'required' => true], |
|
17 | - 'Email address' |
|
14 | + ->field( |
|
15 | + 'field_email', |
|
16 | + ['minlength' => 1, 'filter' => FILTER_VALIDATE_EMAIL, 'regex' => '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', 'required' => true], |
|
17 | + 'Email address' |
|
18 | 18 | ) |
19 | - ->field( |
|
20 | - 'field_password', |
|
21 | - ['minlength' => 6, 'maxlength' => 20, 'required' => true], |
|
22 | - 'Password' |
|
19 | + ->field( |
|
20 | + 'field_password', |
|
21 | + ['minlength' => 6, 'maxlength' => 20, 'required' => true], |
|
22 | + 'Password' |
|
23 | 23 | ) |
24 | - ->field( |
|
25 | - 'field_password2', |
|
26 | - ['minlength' => 6, 'maxlength' => 20, 'equals' => 'field_password', 'required' => true], |
|
27 | - 'Confirm password' |
|
24 | + ->field( |
|
25 | + 'field_password2', |
|
26 | + ['minlength' => 6, 'maxlength' => 20, 'equals' => 'field_password', 'required' => true], |
|
27 | + 'Confirm password' |
|
28 | 28 | ) |
29 | - ->field( |
|
30 | - 'field_remember', |
|
31 | - ['minlength' => 2, 'maxlength' => 2, 'required' => false], |
|
32 | - 'Keep connected' |
|
29 | + ->field( |
|
30 | + 'field_remember', |
|
31 | + ['minlength' => 2, 'maxlength' => 2, 'required' => false], |
|
32 | + 'Keep connected' |
|
33 | 33 | ) |
34 | - ->field( |
|
35 | - 'field_birth', |
|
36 | - ['type' => 'date', 'required' => true], |
|
37 | - 'Date of birth' |
|
34 | + ->field( |
|
35 | + 'field_birth', |
|
36 | + ['type' => 'date', 'required' => true], |
|
37 | + 'Date of birth' |
|
38 | 38 | ) |
39 | - ->field( |
|
40 | - 'field_phones', |
|
41 | - ['mincount' => 2, 'maxcount' => 3, 'required' => true, 'minlength' => 8, 'maxlength' => 9], |
|
42 | - 'Phones' |
|
39 | + ->field( |
|
40 | + 'field_phones', |
|
41 | + ['mincount' => 2, 'maxcount' => 3, 'required' => true, 'minlength' => 8, 'maxlength' => 9], |
|
42 | + 'Phones' |
|
43 | 43 | ); |
44 | 44 | |
45 | - return $rules; |
|
45 | + return $rules; |
|
46 | 46 | }); |
47 | 47 | } |
48 | 48 |
@@ -9,7 +9,7 @@ |
||
9 | 9 | { |
10 | 10 | public function __construct() |
11 | 11 | { |
12 | - Validator::add($this, function(Rules $rules){ |
|
12 | + Validator::add($this, function(Rules $rules) { |
|
13 | 13 | $rules->action('login') |
14 | 14 | ->field( |
15 | 15 | 'field_email', |
@@ -6,7 +6,7 @@ |
||
6 | 6 | 'field_password' => '123456', |
7 | 7 | 'field_password2' => '1234567', |
8 | 8 | 'field_phones' => [ |
9 | - '949164770','949164771','949164772' |
|
9 | + '949164770', '949164771', '949164772' |
|
10 | 10 | ], |
11 | 11 | 'field_birth' => '28/09/1996', |
12 | 12 | '_PROVIDER' => 'user', |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | protected static function array($value): Array |
17 | 17 | { |
18 | - return (is_array($value)) ? $value : [ $value ]; |
|
18 | + return (is_array($value)) ? $value : [$value]; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | protected static function getInstance(?string $lang = null): Validator |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | |
32 | 32 | protected function data($field = null, ?array $values = null) |
33 | 33 | { |
34 | - if(null !== $values){ |
|
34 | + if (null!==$values) { |
|
35 | 35 | $this->data[$field] = $values; |
36 | 36 | } |
37 | - if(null !== $field){ |
|
37 | + if (null!==$field) { |
|
38 | 38 | return $this->data[$field]; |
39 | 39 | } |
40 | 40 | return $this->data; |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | protected function validator(string $model, ?object $callback = null) |
44 | 44 | { |
45 | - if(null !== $callback){ |
|
45 | + if (null!==$callback) { |
|
46 | 46 | $this->validators[$model] = $callback; |
47 | 47 | } |
48 | 48 | return $this->validators[$model]; |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | protected function model(?string $model = null): string |
52 | 52 | { |
53 | - if(null !== $model){ |
|
53 | + if (null!==$model) { |
|
54 | 54 | $this->model = $model; |
55 | 55 | } |
56 | 56 | return $this->model; |
@@ -9,19 +9,19 @@ discard block |
||
9 | 9 | |
10 | 10 | protected function minlength(string $param, int $value, array $rules): void |
11 | 11 | { |
12 | - if(!self::getInstance()->valid($param, self::getInstance()->data($param))){ |
|
12 | + if (!self::getInstance()->valid($param, self::getInstance()->data($param))) { |
|
13 | 13 | return; |
14 | 14 | } |
15 | 15 | |
16 | - foreach( self::array(self::getInstance()->data($param)) as $val ){ |
|
16 | + foreach (self::array(self::getInstance()->data($param)) as $val) { |
|
17 | 17 | |
18 | - if(strlen($val) === 0) { |
|
19 | - self::getInstance()->error([ $param => $rules[$param]['placeholder'] . self::$err['required'] ]); |
|
18 | + if (strlen($val)===0) { |
|
19 | + self::getInstance()->error([$param => $rules[$param]['placeholder'].self::$err['required']]); |
|
20 | 20 | continue; |
21 | 21 | } |
22 | 22 | |
23 | - if($value > strlen($val)){ |
|
24 | - self::getInstance()->error([ $param => $rules[$param]['placeholder'] . self::$err['minlength'] ]); |
|
23 | + if ($value>strlen($val)) { |
|
24 | + self::getInstance()->error([$param => $rules[$param]['placeholder'].self::$err['minlength']]); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | } |
@@ -30,76 +30,76 @@ discard block |
||
30 | 30 | |
31 | 31 | protected function regex(string $param, string $value, array $rules): void |
32 | 32 | { |
33 | - if(!self::getInstance()->valid($param, self::getInstance()->data($param))){ |
|
33 | + if (!self::getInstance()->valid($param, self::getInstance()->data($param))) { |
|
34 | 34 | return; |
35 | 35 | } |
36 | 36 | |
37 | - foreach(self::array(self::getInstance()->data($param)) as $val){ |
|
38 | - if(!preg_match($value, $val)){ |
|
39 | - self::getInstance()->error([ $param => $rules[$param]['placeholder'] . self::$err['regex'] ]); |
|
37 | + foreach (self::array(self::getInstance()->data($param)) as $val) { |
|
38 | + if (!preg_match($value, $val)) { |
|
39 | + self::getInstance()->error([$param => $rules[$param]['placeholder'].self::$err['regex']]); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | protected function mincount(string $param, string $value, array $rules): void |
45 | 45 | { |
46 | - if(!self::getInstance()->valid($param, self::getInstance()->data($param))){ |
|
46 | + if (!self::getInstance()->valid($param, self::getInstance()->data($param))) { |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | - if(count(self::array(self::getInstance()->data($param))) < intval($value)){ |
|
51 | - self::getInstance()->error([ $param => $rules[$param]['placeholder'] . self::$err['mincount'] ]); |
|
50 | + if (count(self::array(self::getInstance()->data($param)))<intval($value)) { |
|
51 | + self::getInstance()->error([$param => $rules[$param]['placeholder'].self::$err['mincount']]); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | } |
55 | 55 | |
56 | 56 | protected function maxcount(string $param, string $value, array $rules): void |
57 | 57 | { |
58 | - if(!self::getInstance()->valid($param, self::getInstance()->data($param))){ |
|
58 | + if (!self::getInstance()->valid($param, self::getInstance()->data($param))) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | 61 | |
62 | - if(count(self::array(self::getInstance()->data($param))) > intval($value)){ |
|
63 | - self::getInstance()->error([ $param => $rules[$param]['placeholder'] . self::$err['maxcount'] ]); |
|
62 | + if (count(self::array(self::getInstance()->data($param)))>intval($value)) { |
|
63 | + self::getInstance()->error([$param => $rules[$param]['placeholder'].self::$err['maxcount']]); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | } |
67 | 67 | |
68 | 68 | protected function equals(string $param, string $value, array $rules): void |
69 | 69 | { |
70 | - if(!array_key_exists($param, self::getInstance()->data())){ |
|
71 | - self::getInstance()->error([ $param => $rules[$value]['placeholder'] . self::$err['nFoundEquals'] ]); |
|
70 | + if (!array_key_exists($param, self::getInstance()->data())) { |
|
71 | + self::getInstance()->error([$param => $rules[$value]['placeholder'].self::$err['nFoundEquals']]); |
|
72 | 72 | return; |
73 | 73 | } |
74 | 74 | |
75 | - if(self::getInstance()->data($param) != self::getInstance()->data($value)){ |
|
76 | - self::getInstance()->error([ $param => $rules[$param]['placeholder'] . self::$err['equals'] . $rules[$value]['placeholder'] ]); |
|
75 | + if (self::getInstance()->data($param)!=self::getInstance()->data($value)) { |
|
76 | + self::getInstance()->error([$param => $rules[$param]['placeholder'].self::$err['equals'].$rules[$value]['placeholder']]); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | 80 | protected function maxlength(string $param, string $value, array $rules): void |
81 | 81 | { |
82 | - if(!self::getInstance()->valid($param, self::getInstance()->data($param))){ |
|
82 | + if (!self::getInstance()->valid($param, self::getInstance()->data($param))) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
86 | - foreach( self::array(self::getInstance()->data($param)) as $val ){ |
|
87 | - if(intval($value) < strlen($val)) { |
|
88 | - self::getInstance()->error([ $param => $rules[$param]['placeholder'] . self::$err['maxlength'] ]); |
|
86 | + foreach (self::array(self::getInstance()->data($param)) as $val) { |
|
87 | + if (intval($value)<strlen($val)) { |
|
88 | + self::getInstance()->error([$param => $rules[$param]['placeholder'].self::$err['maxlength']]); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
93 | 93 | protected function type(string $param, string $value, array $rules): void |
94 | 94 | { |
95 | - if(!self::getInstance()->valid($param, self::getInstance()->data($param))){ |
|
95 | + if (!self::getInstance()->valid($param, self::getInstance()->data($param))) { |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
99 | 99 | switch ($value) { |
100 | 100 | case 'date': |
101 | - if(!self::getInstance()->validateDate(self::getInstance()->data($param) , 'd/m/Y')){ |
|
102 | - self::getInstance()->error([ $param => $rules[$param]['placeholder'] . self::$err['type'] ]); |
|
101 | + if (!self::getInstance()->validateDate(self::getInstance()->data($param), 'd/m/Y')) { |
|
102 | + self::getInstance()->error([$param => $rules[$param]['placeholder'].self::$err['type']]); |
|
103 | 103 | } |
104 | 104 | break; |
105 | 105 | } |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | |
109 | 109 | protected function filter(string $param, string $value, array $rules): void |
110 | 110 | { |
111 | - if(!self::getInstance()->valid($param, self::getInstance()->data($param))){ |
|
111 | + if (!self::getInstance()->valid($param, self::getInstance()->data($param))) { |
|
112 | 112 | return; |
113 | 113 | } |
114 | 114 | |
115 | - if(!filter_var(self::getInstance()->data($param), $value)){ |
|
116 | - self::getInstance()->error([ $param => $rules[$param]['placeholder'] . self::$err['filter'] ]); |
|
115 | + if (!filter_var(self::getInstance()->data($param), $value)) { |
|
116 | + self::getInstance()->error([$param => $rules[$param]['placeholder'].self::$err['filter']]); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | } |
@@ -11,29 +11,29 @@ |
||
11 | 11 | |
12 | 12 | public function __construct(string $model) |
13 | 13 | { |
14 | - $this->form['model'] = ucfirst($model); |
|
15 | - } |
|
14 | + $this->form['model'] = ucfirst($model); |
|
15 | + } |
|
16 | 16 | |
17 | 17 | public function action(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 field(string $field, array $test, ?string $placeholder = null): Rules |
24 | 24 | { |
25 | - if(empty($this->action)){ |
|
25 | + if(empty($this->action)){ |
|
26 | 26 | $this->error([ 'form' => self::$err['nFoundForm'] ]); |
27 | 27 | return $this; |
28 | 28 | } |
29 | 29 | |
30 | 30 | $this->form[$this->action][$field] = $test; |
31 | 31 | $this->form[$this->action][$field]['placeholder'] = (null !== $placeholder) ? $placeholder : $field; |
32 | - return $this; |
|
33 | - } |
|
32 | + return $this; |
|
33 | + } |
|
34 | 34 | |
35 | 35 | public function getRules(string $action): Array |
36 | 36 | { |
37 | - return (array_key_exists($action, $this->form)) ? $this->form[$action] : []; |
|
38 | - } |
|
37 | + return (array_key_exists($action, $this->form)) ? $this->form[$action] : []; |
|
38 | + } |
|
39 | 39 | } |
@@ -22,13 +22,13 @@ |
||
22 | 22 | |
23 | 23 | public function field(string $field, array $test, ?string $placeholder = null): Rules |
24 | 24 | { |
25 | - if(empty($this->action)){ |
|
26 | - $this->error([ 'form' => self::$err['nFoundForm'] ]); |
|
25 | + if (empty($this->action)) { |
|
26 | + $this->error(['form' => self::$err['nFoundForm']]); |
|
27 | 27 | return $this; |
28 | 28 | } |
29 | 29 | |
30 | 30 | $this->form[$this->action][$field] = $test; |
31 | - $this->form[$this->action][$field]['placeholder'] = (null !== $placeholder) ? $placeholder : $field; |
|
31 | + $this->form[$this->action][$field]['placeholder'] = (null!==$placeholder) ? $placeholder : $field; |
|
32 | 32 | return $this; |
33 | 33 | } |
34 | 34 |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | self::getInstance()->errors[] = ['form' => $er->getMessage()]; |
93 | 93 | } |
94 | 94 | |
95 | - return self::errors(); |
|
95 | + return self::errors(); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | public static function errors(): bool |
@@ -104,24 +104,24 @@ discard block |
||
104 | 104 | { |
105 | 105 | foreach ( (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) as $key => $value) { |
106 | 106 | |
107 | - foreach (self::getInstance()->data as $keyy => $valuee) { |
|
107 | + foreach (self::getInstance()->data as $keyy => $valuee) { |
|
108 | 108 | |
109 | - self::getInstance()->checkExpected($keyy); |
|
109 | + self::getInstance()->checkExpected($keyy); |
|
110 | 110 | |
111 | - if($keyy!==$key){ |
|
111 | + if($keyy!==$key){ |
|
112 | 112 | continue; |
113 | 113 | } |
114 | 114 | |
115 | 115 | unset(self::getInstance()->required[$key]); |
116 | 116 | |
117 | - foreach ($value as $subkey => $subvalue) { |
|
117 | + foreach ($value as $subkey => $subvalue) { |
|
118 | 118 | |
119 | 119 | $function = strtolower($subkey); |
120 | 120 | |
121 | 121 | self::getInstance()->hasMethod($function)->$function($keyy, $subvalue, (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) ); |
122 | 122 | } |
123 | 123 | |
124 | - } |
|
124 | + } |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | |
162 | 162 | self::getInstance()->existRole(self::getInstance()->model()); |
163 | 163 | |
164 | - foreach ( self::getInstance()->validator(self::getInstance()->model())->getRules($request['_ROLE']) as $field => $r) { |
|
164 | + foreach ( self::getInstance()->validator(self::getInstance()->model())->getRules($request['_ROLE']) as $field => $r) { |
|
165 | 165 | $r = self::getInstance()->replaceRegex($r); |
166 | 166 | $response .= ("'$field':".json_encode(array_reverse($r))).','; |
167 | 167 | } |
@@ -88,7 +88,7 @@ |
||
88 | 88 | |
89 | 89 | self::getInstance()->validate(); |
90 | 90 | self::getInstance()->requireds(); |
91 | - }catch(\Exception $er){ |
|
91 | + } catch(\Exception $er){ |
|
92 | 92 | self::getInstance()->errors[] = ['form' => $er->getMessage()]; |
93 | 93 | } |
94 | 94 |
@@ -14,15 +14,15 @@ discard block |
||
14 | 14 | |
15 | 15 | public function __construct(?string $lang = null) |
16 | 16 | { |
17 | - $lang = (null !== $lang) ? $lang : 'en'; |
|
18 | - require __DIR__.DIRECTORY_SEPARATOR.'languages'. DIRECTORY_SEPARATOR . $lang .'.php'; |
|
17 | + $lang = (null!==$lang) ? $lang : 'en'; |
|
18 | + require __DIR__.DIRECTORY_SEPARATOR.'languages'.DIRECTORY_SEPARATOR.$lang.'.php'; |
|
19 | 19 | self::$err = (isset($VALIDATOR_LANG)) ? $VALIDATOR_LANG : []; |
20 | 20 | } |
21 | 21 | |
22 | 22 | public static function lang(string $lang): Validator |
23 | 23 | { |
24 | 24 | unset($VALIDATOR_LANG); |
25 | - require __DIR__.DIRECTORY_SEPARATOR.'languages'. DIRECTORY_SEPARATOR . $lang .'.php'; |
|
25 | + require __DIR__.DIRECTORY_SEPARATOR.'languages'.DIRECTORY_SEPARATOR.$lang.'.php'; |
|
26 | 26 | self::$err = (isset($VALIDATOR_LANG)) ? $VALIDATOR_LANG : []; |
27 | 27 | return self::getInstance($lang); |
28 | 28 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | private static function getClass(string $class) |
44 | 44 | { |
45 | - if(!class_exists($class)){ |
|
45 | + if (!class_exists($class)) { |
|
46 | 46 | throw new \RuntimeException(self::$err['nFormID']); |
47 | 47 | } |
48 | 48 | |
@@ -53,21 +53,21 @@ discard block |
||
53 | 53 | |
54 | 54 | private function existRole($getRules) |
55 | 55 | { |
56 | - if(empty(self::getInstance()->validator($getRules)->getRules(self::getInstance()->data['_ROLE']))){ |
|
56 | + if (empty(self::getInstance()->validator($getRules)->getRules(self::getInstance()->data['_ROLE']))) { |
|
57 | 57 | throw new \RuntimeException(self::$err['nFoundForm']); |
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | 61 | public function checkDatas(array $data): void |
62 | 62 | { |
63 | - if(!isset($data['_PROVIDER']) || !isset($data['_ROLE'])){ |
|
63 | + if (!isset($data['_PROVIDER']) || !isset($data['_ROLE'])) { |
|
64 | 64 | throw new \RuntimeException(self::$err['issetData']); |
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | 68 | public static function execute(array $data): bool |
69 | 69 | { |
70 | - try{ |
|
70 | + try { |
|
71 | 71 | self::getInstance()->checkDatas($data); |
72 | 72 | |
73 | 73 | self::getInstance()->data = $data; |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | |
79 | 79 | self::getInstance()->existRole(self::getInstance()->model); |
80 | 80 | |
81 | - foreach ( (self::getInstance()->validator(self::getInstance()->model)->getRules($data['_ROLE'])) as $key => $value) { |
|
82 | - if(@$value['required'] === true){ |
|
81 | + foreach ((self::getInstance()->validator(self::getInstance()->model)->getRules($data['_ROLE'])) as $key => $value) { |
|
82 | + if (@$value['required']===true) { |
|
83 | 83 | self::getInstance()->required[$key] = $value; |
84 | 84 | } |
85 | 85 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | |
89 | 89 | self::getInstance()->validate(); |
90 | 90 | self::getInstance()->requireds(); |
91 | - }catch(\Exception $er){ |
|
91 | + }catch (\Exception $er) { |
|
92 | 92 | self::getInstance()->errors[] = ['form' => $er->getMessage()]; |
93 | 93 | } |
94 | 94 | |
@@ -97,18 +97,18 @@ discard block |
||
97 | 97 | |
98 | 98 | public static function errors(): bool |
99 | 99 | { |
100 | - return (count(self::getInstance()->errors) === 0); |
|
100 | + return (count(self::getInstance()->errors)===0); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | public function validate(): void |
104 | 104 | { |
105 | - foreach ( (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) as $key => $value) { |
|
105 | + foreach ((self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) as $key => $value) { |
|
106 | 106 | |
107 | 107 | foreach (self::getInstance()->data as $keyy => $valuee) { |
108 | 108 | |
109 | 109 | self::getInstance()->checkExpected($keyy); |
110 | 110 | |
111 | - if($keyy!==$key){ |
|
111 | + if ($keyy!==$key) { |
|
112 | 112 | continue; |
113 | 113 | } |
114 | 114 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | $function = strtolower($subkey); |
120 | 120 | |
121 | - self::getInstance()->hasMethod($function)->$function($keyy, $subvalue, (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) ); |
|
121 | + self::getInstance()->hasMethod($function)->$function($keyy, $subvalue, (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE']))); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | } |
@@ -127,8 +127,8 @@ discard block |
||
127 | 127 | |
128 | 128 | private function checkExpected(string $keyy): void |
129 | 129 | { |
130 | - if(!array_key_exists($keyy, (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) ) && !in_array($keyy, self::getInstance()->defaultData)){ |
|
131 | - throw new \RuntimeException($keyy . self::$err['nExpected']); |
|
130 | + if (!array_key_exists($keyy, (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE']))) && !in_array($keyy, self::getInstance()->defaultData)) { |
|
131 | + throw new \RuntimeException($keyy.self::$err['nExpected']); |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | |
140 | 140 | public function hasMethod($method): Validator |
141 | 141 | { |
142 | - if(!method_exists(static::class, $method)){ |
|
143 | - throw new \RuntimeException($method . self::$err['nMethod']); |
|
142 | + if (!method_exists(static::class, $method)) { |
|
143 | + throw new \RuntimeException($method.self::$err['nMethod']); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | return $this; |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | |
162 | 162 | self::getInstance()->existRole(self::getInstance()->model()); |
163 | 163 | |
164 | - foreach ( self::getInstance()->validator(self::getInstance()->model())->getRules($request['_ROLE']) as $field => $r) { |
|
164 | + foreach (self::getInstance()->validator(self::getInstance()->model())->getRules($request['_ROLE']) as $field => $r) { |
|
165 | 165 | $r = self::getInstance()->replaceRegex($r); |
166 | 166 | $response .= ("'$field':".json_encode(array_reverse($r))).','; |
167 | 167 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | |
172 | 172 | private function replaceRegex(array $getRules): array |
173 | 173 | { |
174 | - if(array_key_exists('regex', $getRules)){ |
|
174 | + if (array_key_exists('regex', $getRules)) { |
|
175 | 175 | $getRules['regex'] = substr($getRules['regex'], 1, -2); |
176 | 176 | } |
177 | 177 |