Skip to content

Commit 75d6b8d

Browse files
committed
Merge branch 'master' of https://github.com/bim-g/wepesi_validation into version_emmanuel
2 parents 6d11239 + 410b77a commit 75d6b8d

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

class/VNumber.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ class VNumber {
2323
private $_max;
2424

2525
function __construct(array $source,string $string_item, string $string_value) {
26-
$this->source_data=$source;
27-
$this->string_value=$string_value;
26+
$this->source_data=$source;
2827
$this->string_item=$string_item;
2928
$this->_max= $this->_min=0;
30-
$this->checkExist();
29+
if($this->checkExist()){
30+
$this->string_value=$source[$string_item];
31+
}
3132
}
3233
function min(int $min_values){
3334
if ((int) $this->string_value < $min_values) {
@@ -81,22 +82,25 @@ function required(){
8182
private function checkExist(string $itemKey=null){
8283
$item_to_check=$itemKey?$itemKey:$this->string_item;
8384
$regex_string="#[a-zA-Z]#";
85+
$status_key_exist=true;
8486
if (!isset($this->source_data[$item_to_check])) {
8587
$message = [
8688
"type"=> "any.unknow",
8789
"message" => "`{$item_to_check}` is unknow",
8890
"label" => $item_to_check,
8991
];
9092
$this->addError($message);
93+
$status_key_exist=false;
9194
}else if (preg_match($regex_string,trim($this->source_data[$item_to_check])) || !is_integer($this->source_data[$item_to_check])) {
9295
$message = [
9396
"type"=> "number.unknow",
9497
"message" => "`{$item_to_check}` should be a number",
9598
"label" => $item_to_check,
9699
];
97100
$this->addError($message);
101+
$status_key_exist=false;
98102
}
99-
return true;
103+
return $status_key_exist;
100104
}
101105
private function addError(array $value){
102106
return $this->_errors[]=$value;

class/VString.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function required(){
137137
private function checkExist(string $itemKey=null){
138138
$item_to_check=$itemKey?$itemKey:$this->string_item;
139139
$regex="#[a-zA-Z0-9]#";
140+
$status_keys_exist=true;
140141
if (!isset($this->source_data[$item_to_check])) {
141142
$message = [
142143
"type"=> "any.unknow",
@@ -154,7 +155,7 @@ private function checkExist(string $itemKey=null){
154155
$this->addError($message);
155156
return false;
156157
}
157-
return true;
158+
return $status_keys_exist;
158159
}/**
159160
*
160161
* @param array $value

class/Validate.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ function check($source,array $items=[]){
5555
*
5656
* @param array $source
5757
* @param array $items
58+
* @return boolean
5859
*/
5960
private function check_undefined_Object_key(array $source,array $items){
6061
$diff_array_key= array_diff_key($source,$items);
6162
$source_key= array_keys($diff_array_key);
63+
$status_key=false;
6264
if(count($source_key)>0){
6365
foreach($source_key as $key){
6466
$message=[
@@ -67,8 +69,10 @@ private function check_undefined_Object_key(array $source,array $items){
6769
"label" => $key,
6870
];
6971
$this->addError($message);
72+
$status_key=true;
7073
}
7174
}
75+
return $status_key;
7276
}
7377
/**
7478
*
@@ -84,7 +88,15 @@ function string(string $tring_key=null){
8488
* @return \Wepesi\app\VNumber
8589
*/
8690
function number(string $tring_key=null){
87-
return new VNumber($this->source,$tring_key,$this->source[$tring_key]);
91+
return new VNumber($this->source,$tring_key);
92+
}
93+
/**
94+
*
95+
* @param string $tring_key
96+
* @return type
97+
*/
98+
function any(string $tring_key=null){
99+
return $this->check_undefined_Object_key($this->source,$tring_key);
88100
}
89101
/**
90102
*

0 commit comments

Comments
 (0)