Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/bim-g/wepesi_validation i…
Browse files Browse the repository at this point in the history
…nto version_emmanuel
  • Loading branch information
Domeshow committed May 6, 2021
2 parents 6d11239 + 410b77a commit 75d6b8d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
12 changes: 8 additions & 4 deletions class/VNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ class VNumber {
private $_max;

function __construct(array $source,string $string_item, string $string_value) {
$this->source_data=$source;
$this->string_value=$string_value;
$this->source_data=$source;
$this->string_item=$string_item;
$this->_max= $this->_min=0;
$this->checkExist();
if($this->checkExist()){
$this->string_value=$source[$string_item];
}
}
function min(int $min_values){
if ((int) $this->string_value < $min_values) {
Expand Down Expand Up @@ -81,22 +82,25 @@ function required(){
private function checkExist(string $itemKey=null){
$item_to_check=$itemKey?$itemKey:$this->string_item;
$regex_string="#[a-zA-Z]#";
$status_key_exist=true;
if (!isset($this->source_data[$item_to_check])) {
$message = [
"type"=> "any.unknow",
"message" => "`{$item_to_check}` is unknow",
"label" => $item_to_check,
];
$this->addError($message);
$status_key_exist=false;
}else if (preg_match($regex_string,trim($this->source_data[$item_to_check])) || !is_integer($this->source_data[$item_to_check])) {
$message = [
"type"=> "number.unknow",
"message" => "`{$item_to_check}` should be a number",
"label" => $item_to_check,
];
$this->addError($message);
$status_key_exist=false;
}
return true;
return $status_key_exist;
}
private function addError(array $value){
return $this->_errors[]=$value;
Expand Down
3 changes: 2 additions & 1 deletion class/VString.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function required(){
private function checkExist(string $itemKey=null){
$item_to_check=$itemKey?$itemKey:$this->string_item;
$regex="#[a-zA-Z0-9]#";
$status_keys_exist=true;
if (!isset($this->source_data[$item_to_check])) {
$message = [
"type"=> "any.unknow",
Expand All @@ -154,7 +155,7 @@ private function checkExist(string $itemKey=null){
$this->addError($message);
return false;
}
return true;
return $status_keys_exist;
}/**
*
* @param array $value
Expand Down
14 changes: 13 additions & 1 deletion class/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ function check($source,array $items=[]){
*
* @param array $source
* @param array $items
* @return boolean
*/
private function check_undefined_Object_key(array $source,array $items){
$diff_array_key= array_diff_key($source,$items);
$source_key= array_keys($diff_array_key);
$status_key=false;
if(count($source_key)>0){
foreach($source_key as $key){
$message=[
Expand All @@ -67,8 +69,10 @@ private function check_undefined_Object_key(array $source,array $items){
"label" => $key,
];
$this->addError($message);
$status_key=true;
}
}
return $status_key;
}
/**
*
Expand All @@ -84,7 +88,15 @@ function string(string $tring_key=null){
* @return \Wepesi\app\VNumber
*/
function number(string $tring_key=null){
return new VNumber($this->source,$tring_key,$this->source[$tring_key]);
return new VNumber($this->source,$tring_key);
}
/**
*
* @param string $tring_key
* @return type
*/
function any(string $tring_key=null){
return $this->check_undefined_Object_key($this->source,$tring_key);
}
/**
*
Expand Down

0 comments on commit 75d6b8d

Please sign in to comment.