diff --git a/.idea/php.xml b/.idea/php.xml index 3b1bcf5..9a0a9fd 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -6,4 +6,9 @@ + + + + + \ No newline at end of file diff --git a/.idea/wepesi_validation.iml b/.idea/wepesi_validation.iml index 1ee89a6..40fe797 100644 --- a/.idea/wepesi_validation.iml +++ b/.idea/wepesi_validation.iml @@ -3,7 +3,7 @@ - + diff --git a/composer.json b/composer.json index 609da5c..7991ca0 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ ], "autoload": { "psr-4": { - "Wepesi\\app\\":"src/" + "Wepesi\\App\\":"src/" } }, "require": { diff --git a/lang/fr/language.php b/lang/fr/language.php index 2d8868e..6872663 100644 --- a/lang/fr/language.php +++ b/lang/fr/language.php @@ -7,10 +7,11 @@ "`%s` should match %s"=>"`%s` doit correpondre a `%s`", "`%s` is required"=>"`%s` est obligatoire", "`%s` should be a string"=>"`%s` doit est une chaine de caractères", - "`%s` should be greater than `%s`"=>"`%s` devrait être supérieur à `%s`", - "`%s` should be less than `%s`"=>"`%s` devrait être inférieur à `%s`", + "`%s` should be greater than `%s`"=>"`%s` devrait être supérieur à `%s`", + "`%s` should be less than `%s`"=>"`%s` devrait être inférieur à `%s`", "`%s` should be a positive number"=>"`%s` devrait être un nombre positif", - "`%s` is unknow"=>"`%s` devrait être inférieur à `%s`", - "`%s` should be less than `%s`"=>"`%s` devrait être inférieur à `%s`", - "`%s` should be less than `%s`"=>"`%s` devrait être inférieur à `%s`", + "`%s` should be a number"=>"`%s` devrait être un nombre.", + "`%s` is unknow"=>"`%s` n'est pas definit", + "`%s` should be a date."=>"`%s` devrait être une date.", + "`%s` should be greater than now"=>"`%s` devrait être plus grand que maintenant", ]; \ No newline at end of file diff --git a/src/VBoolean.php b/src/VBoolean.php index 9a62c58..270abdd 100644 --- a/src/VBoolean.php +++ b/src/VBoolean.php @@ -1,6 +1,6 @@ date_value=$source[$string_item]; @@ -29,14 +27,15 @@ function __construct(array $source,string $string_item=null) { /** * @return $this */ - function now(){ + function now(): VDate + { $min_date_time=strtotime("now"); $min_date=date("d/F/Y",$min_date_time); $date_value_time= strtotime($this->date_value); if ($date_value_time < $min_date_time) { $message=[ "type"=>"date.now", - "message"=> "`{$this->string_item}` should be greater than now", + "message"=> i18n::translate("`%s` should be greater than now",[$this->string_item]), "label"=>$this->string_item, "limit"=>$min_date ]; @@ -50,15 +49,15 @@ function now(){ * @return $this * while trying to get day validation use this module */ - function today(string $times=null){ - $regeg="#+[0-9]h:[0-9]min:[0-9]sec#"; + function today(string $times=null): VDate + { $min_date_time=strtotime("now {$times}"); $min_date=date("d/F/Y",$min_date_time); $date_value_time= strtotime($this->date_value); if ($date_value_time > $min_date_time) { $message=[ "type"=>"date.now", - "message"=> "`{$this->string_item}` should be greater than today ", + "message"=> i18n::translate("`%s` should be greater than today ",[$this->string_item]), "label"=>$this->string_item, "limit"=>$min_date ]; @@ -66,26 +65,28 @@ function today(string $times=null){ } return $this; } + /** - * @param string $rule_values + * @param string|null $rule_values * @return $this * get the min date control from the given date */ - function min(string $rule_values=null){ + function min(string $rule_values=null): VDate + { /** * $regex= "#[a-zA-Z]#"; * $time= preg_match($regex,$rule_values); * $con=!$time?$time:(int)$time; * in case the parameters are integers */ - $rule_values=isset($rule_values)?$rule_values: "now"; + $rule_values= $rule_values ?? "now"; $min_date_time=strtotime($rule_values); $min_date=date("d/F/Y",$min_date_time); $date_value_time= strtotime($this->date_value); if ($date_value_time > $min_date_time) { $message=[ "type"=>"date.min", - "message"=> "`{$this->string_item}` should greater than `{$min_date}`", + "message"=> i18n::translate("`%s` should be greater than `%s`",[$this->string_item,$min_date]), "label"=>$this->string_item, "limit"=>$min_date ]; @@ -99,16 +100,16 @@ function min(string $rule_values=null){ * @return $this * while try to check maximum date of a defined period use this module */ - function max(string $rule_values=null){ - $rule_values=isset($rule_values)?$rule_values: "now"; - + function max(string $rule_values=null): VDate + { + $rule_values= $rule_values ?? "now"; $max_date_time=strtotime($rule_values); $max_date=date("d/F/Y",$max_date_time); $date_value_time= strtotime($this->date_value); if ($max_date_time<$date_value_time) { $message = [ "type" => "date.max", - "message" => "`{$this->string_item}` should be less than `{$max_date}`", + "message" => i18n::translate("`%s` should be less than `%s`",[$this->string_item,$max_date]), "label" => $this->string_item, "limit" => $max_date ]; @@ -120,12 +121,13 @@ function max(string $rule_values=null){ * @return $this * call this module is the input is requied and should not be null or empty */ - function required(){ + function required(): VDate + { $required_value= trim($this->date_value); if (empty($required_value) || strlen($required_value)==0) { $message = [ "type"=> "any.required", - "message" => "`{$this->string_item}` {$this->lang->required}", + "message" => i18n::translate("`%s` is required",[$this->string_item]), "label" => $this->string_item, ]; $this->addError($message); @@ -133,29 +135,30 @@ function required(){ return $this; } // private methode - private function checkExist(string $itemKey=null){ + private function checkExist(string $itemKey=null): void + { $item_to_check=$itemKey?$itemKey:$this->string_item; $regex="#[a-zA-Z0-9]#"; $this->_errors=[]; if (!isset($this->source_data[$item_to_check])) { $message = [ "type"=> "any.unknow", - "message" => "`{$item_to_check}` {$this->lang->unknow}", + "message" => i18n::translate("`%s` is unknow",[$item_to_check]), "label" => $item_to_check, ]; $this->addError($message); }else if(!preg_match($regex,$this->source_data[$item_to_check]) || strlen(trim($this->source_data[$item_to_check]))==0){ $message=[ "type" => "date.unknow", - "message" => "`{$item_to_check}` {$this->lang->string_unknow}", + "message" => i18n::translate("`%s` should be a date.",[$item_to_check]), "label" => $item_to_check, ]; $this->addError($message); } - return true; } - private function addError(array $value){ - return $this->_errors[]=$value; + private function addError(array $value): void + { + $this->_errors[] = $value; } function check(){ return $this->_errors; diff --git a/src/VNumber.php b/src/VNumber.php index 3839bec..d7f1aa7 100644 --- a/src/VNumber.php +++ b/src/VNumber.php @@ -6,7 +6,7 @@ * and open the template in the editor. */ -namespace Wepesi\app; +namespace Wepesi\App; /** * Description of VNumber @@ -40,7 +40,7 @@ function min(int $min_values): VNumber if ((int) $this->string_value < $min_values) { $message=[ "type"=>"number.min", - "message"=> i18n::translate("`%s` should be greater than `%s`",[$this->string_item,$min_values]), + "message"=> i18n::translate("`%s` should be greater than `%s`",[$this->string_item,$min_values]), "label"=>$this->string_item, "limit"=>$min_values ]; @@ -58,7 +58,7 @@ function max(int $min_values): VNumber if ((int) $this->string_value > $min_values) { $message=[ "type"=>"number.max", - "message"=> i18n::translate("`%s` should be less than `%s`",[$this->string_item,$min_values]), + "message"=> i18n::translate("`%s` should be less than `%s`",[$this->string_item,$min_values]), "label"=>$this->string_item, "limit"=>$min_values ]; diff --git a/src/VString.php b/src/VString.php index 22337c9..594499c 100644 --- a/src/VString.php +++ b/src/VString.php @@ -1,5 +1,5 @@ $valid->date("birth_day")->min("-18years")->required()->check(), - "date_created"=>$valid->date("birth_day")->now()->required()->check() + "date_created"=>$valid->date("birth_day")->now()->max("100years")->required()->check() ]; $valid->check($source,$schema); diff --git a/test/index.php b/test/index.php index 88d6042..9c51fa1 100644 --- a/test/index.php +++ b/test/index.php @@ -1,5 +1,5 @@ "", @@ -17,6 +17,6 @@ ]; $valid=new Validate($source); // include "./test/string.php"; - include "./test/number.php"; +// include "./test/number.php"; // include "./test/boolean.php"; -// include "./test/date.php"; + include "./test/date.php"; diff --git a/test/number.php b/test/number.php index f264145..4137f99 100644 --- a/test/number.php +++ b/test/number.php @@ -1,7 +1,7 @@ $valid->number("age")->min(18)->max(50)->required()->check() ]; - $valid->check($source,$check); + $valid->check($source,$schema); var_dump($valid->passed()); var_dump($valid->errors()); \ No newline at end of file