@@ -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', |
@@ -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 | |
@@ -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', |
@@ -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 | |
@@ -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 | } |
@@ -6,13 +6,13 @@ |
||
| 6 | 6 | use Psr\Http\Server\RequestHandlerInterface; |
| 7 | 7 | use Psr\Http\Message\ResponseInterface; |
| 8 | 8 | |
| 9 | -trait MiddlewareTrait{ |
|
| 9 | +trait MiddlewareTrait { |
|
| 10 | 10 | |
| 11 | 11 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
| 12 | 12 | { |
| 13 | - $data = ($request->getAttribute('validator') !== null && isset($request->getAttribute('validator')['data'])) ? $request->getAttribute('validator')['data'] : $_REQUEST; |
|
| 14 | - $namespace = ($request->getAttribute('validator') !== null && isset($request->getAttribute('validator')['namespace'])) ? $request->getAttribute('validator')['namespace'] : ''; |
|
| 15 | - $lang = ($request->getAttribute('validator') !== null && isset($request->getAttribute('validator')['lang'])) ? $request->getAttribute('validator')['lang'] : 'en'; |
|
| 13 | + $data = ($request->getAttribute('validator')!==null && isset($request->getAttribute('validator')['data'])) ? $request->getAttribute('validator')['data'] : $_REQUEST; |
|
| 14 | + $namespace = ($request->getAttribute('validator')!==null && isset($request->getAttribute('validator')['namespace'])) ? $request->getAttribute('validator')['namespace'] : ''; |
|
| 15 | + $lang = ($request->getAttribute('validator')!==null && isset($request->getAttribute('validator')['lang'])) ? $request->getAttribute('validator')['lang'] : 'en'; |
|
| 16 | 16 | |
| 17 | 17 | return $handler->handle($request->withAttribute('validator', [ |
| 18 | 18 | 'valid' => self::lang($lang)->namespace($namespace)->execute($data), |
@@ -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 | |
@@ -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 = $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 = $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 | |