@@ -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 | } |
@@ -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), |
@@ -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 | |