Skip to content

Commit e42ebcb

Browse files
authored
Merge pull request #38 from bim-g/v2
[UPD] update translation for vnumber
2 parents 3665bd1 + 31c5635 commit e42ebcb

File tree

13 files changed

+167
-82
lines changed

13 files changed

+167
-82
lines changed

.idea/php.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/wepesi_validation.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
"autoload": {
1717
"psr-4": {
18-
"Wepesi\\app\\":"src/"
18+
"Wepesi\\App\\":"src/"
1919
}
2020
},
2121
"require": {

lang/fr/language.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
<?php
22
$language=[
3-
"`%s` should have minimum of `%s` caracters"=>"`%s` doit avoir un minimum de `%s` caracteres",
4-
"`%s` should have maximum of `%s` caracters"=>"`%s` doit avoir un maximum de `%s` caracteres",
3+
"`%s` should have minimum of `%s` characters"=>"`%s` doit avoir un minimum de `%s` caractèress",
4+
"`%s` should have maximum of `%s` characters"=>"`%s` doit avoir un maximum de `%s` caractèress",
55
"`%s` this should be an email"=>"`%s` doit etre un email",
66
"`%s` this should be a link(url)"=>"`%s` doit avoir un lien(url) ",
77
"`%s` should match %s"=>"`%s` doit correpondre a `%s`",
88
"`%s` is required"=>"`%s` est obligatoire",
9+
"`%s` should be a string"=>"`%s` doit est une chaine de caractères",
10+
"`%s` should be greater than `%s`"=>"`%s` devrait être supérieur à `%s`",
11+
"`%s` should be less than `%s`"=>"`%s` devrait être inférieur à `%s`",
12+
"`%s` should be a positive number"=>"`%s` devrait être un nombre positif",
13+
"`%s` should be a number"=>"`%s` devrait être un nombre.",
14+
"`%s` is unknow"=>"`%s` n'est pas definit",
15+
"`%s` should be a date."=>"`%s` devrait être une date.",
16+
"`%s` should be greater than now"=>"`%s` devrait être plus grand que maintenant",
917
"`%s` should be a string"=>"`%s` doit est une chaine de caractere",
1018
];

src/VBoolean.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Wepesi\app;
3+
namespace Wepesi\App;
44
/*
55
* To change this license header, choose License Headers in Project Properties.
66
* To change this template file, choose Tools | Templates

src/VDate.php

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@
22

33

44
namespace Wepesi\App;
5-
65
/**
7-
* Description of VNumber
6+
* Description of VDate
87
*
98
* @author Boss Ibrahim Mussa
109
*/
1110
class VDate
1211
{
1312
private $date_value;
14-
private $string_item;
15-
private $source_data;
16-
private $_errors;
17-
private $_min;
18-
private $_max;
19-
// private $_mois=["Janviers","Fevrier","Mars","Avril","Mai","Juin","Jouillet","Aout","Septenbre","Octobre","Novembre","Decembre"];
13+
private ?string $string_item;
14+
private array $source_data;
15+
private array $_errors=[];
16+
private int $_min;
17+
private int $_max;
2018
//put your code here
2119
function __construct(array $source,string $string_item=null) {
2220
$this->date_value=$source[$string_item];
@@ -29,14 +27,15 @@ function __construct(array $source,string $string_item=null) {
2927
/**
3028
* @return $this
3129
*/
32-
function now(){
30+
function now(): VDate
31+
{
3332
$min_date_time=strtotime("now");
3433
$min_date=date("d/F/Y",$min_date_time);
3534
$date_value_time= strtotime($this->date_value);
3635
if ($date_value_time < $min_date_time) {
3736
$message=[
3837
"type"=>"date.now",
39-
"message"=> "`{$this->string_item}` should be greater than now",
38+
"message"=> i18n::translate("`%s` should be greater than now",[$this->string_item]),
4039
"label"=>$this->string_item,
4140
"limit"=>$min_date
4241
];
@@ -50,42 +49,44 @@ function now(){
5049
* @return $this
5150
* while trying to get day validation use this module
5251
*/
53-
function today(string $times=null){
54-
$regeg="#+[0-9]h:[0-9]min:[0-9]sec#";
52+
function today(string $times=null): VDate
53+
{
5554
$min_date_time=strtotime("now {$times}");
5655
$min_date=date("d/F/Y",$min_date_time);
5756
$date_value_time= strtotime($this->date_value);
5857
if ($date_value_time > $min_date_time) {
5958
$message=[
6059
"type"=>"date.now",
61-
"message"=> "`{$this->string_item}` should be greater than today ",
60+
"message"=> i18n::translate("`%s` should be greater than today ",[$this->string_item]),
6261
"label"=>$this->string_item,
6362
"limit"=>$min_date
6463
];
6564
$this->addError($message);
6665
}
6766
return $this;
6867
}
68+
6969
/**
70-
* @param string $rule_values
70+
* @param string|null $rule_values
7171
* @return $this
7272
* get the min date control from the given date
7373
*/
74-
function min(string $rule_values=null){
74+
function min(string $rule_values=null): VDate
75+
{
7576
/**
7677
* $regex= "#[a-zA-Z]#";
7778
* $time= preg_match($regex,$rule_values);
7879
* $con=!$time?$time:(int)$time;
7980
* in case the parameters are integers
8081
*/
81-
$rule_values=isset($rule_values)?$rule_values: "now";
82+
$rule_values= $rule_values ?? "now";
8283
$min_date_time=strtotime($rule_values);
8384
$min_date=date("d/F/Y",$min_date_time);
8485
$date_value_time= strtotime($this->date_value);
8586
if ($date_value_time > $min_date_time) {
8687
$message=[
8788
"type"=>"date.min",
88-
"message"=> "`{$this->string_item}` should greater than `{$min_date}`",
89+
"message"=> i18n::translate("`%s` should be greater than `%s`",[$this->string_item,$min_date]),
8990
"label"=>$this->string_item,
9091
"limit"=>$min_date
9192
];
@@ -99,16 +100,16 @@ function min(string $rule_values=null){
99100
* @return $this
100101
* while try to check maximum date of a defined period use this module
101102
*/
102-
function max(string $rule_values=null){
103-
$rule_values=isset($rule_values)?$rule_values: "now";
104-
103+
function max(string $rule_values=null): VDate
104+
{
105+
$rule_values= $rule_values ?? "now";
105106
$max_date_time=strtotime($rule_values);
106107
$max_date=date("d/F/Y",$max_date_time);
107108
$date_value_time= strtotime($this->date_value);
108109
if ($max_date_time<$date_value_time) {
109110
$message = [
110111
"type" => "date.max",
111-
"message" => "`{$this->string_item}` should be less than `{$max_date}`",
112+
"message" => i18n::translate("`%s` should be less than `%s`",[$this->string_item,$max_date]),
112113
"label" => $this->string_item,
113114
"limit" => $max_date
114115
];
@@ -120,42 +121,44 @@ function max(string $rule_values=null){
120121
* @return $this
121122
* call this module is the input is requied and should not be null or empty
122123
*/
123-
function required(){
124+
function required(): VDate
125+
{
124126
$required_value= trim($this->date_value);
125127
if (empty($required_value) || strlen($required_value)==0) {
126128
$message = [
127129
"type"=> "any.required",
128-
"message" => "`{$this->string_item}` {$this->lang->required}",
130+
"message" => i18n::translate("`%s` is required",[$this->string_item]),
129131
"label" => $this->string_item,
130132
];
131133
$this->addError($message);
132134
}
133135
return $this;
134136
}
135137
// private methode
136-
private function checkExist(string $itemKey=null){
138+
private function checkExist(string $itemKey=null): void
139+
{
137140
$item_to_check=$itemKey?$itemKey:$this->string_item;
138141
$regex="#[a-zA-Z0-9]#";
139142
$this->_errors=[];
140143
if (!isset($this->source_data[$item_to_check])) {
141144
$message = [
142145
"type"=> "any.unknow",
143-
"message" => "`{$item_to_check}` {$this->lang->unknow}",
146+
"message" => i18n::translate("`%s` is unknow",[$item_to_check]),
144147
"label" => $item_to_check,
145148
];
146149
$this->addError($message);
147150
}else if(!preg_match($regex,$this->source_data[$item_to_check]) || strlen(trim($this->source_data[$item_to_check]))==0){
148151
$message=[
149152
"type" => "date.unknow",
150-
"message" => "`{$item_to_check}` {$this->lang->string_unknow}",
153+
"message" => i18n::translate("`%s` should be a date.",[$item_to_check]),
151154
"label" => $item_to_check,
152155
];
153156
$this->addError($message);
154157
}
155-
return true;
156158
}
157-
private function addError(array $value){
158-
return $this->_errors[]=$value;
159+
private function addError(array $value): void
160+
{
161+
$this->_errors[] = $value;
159162
}
160163
function check(){
161164
return $this->_errors;

src/VNumber.php

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* and open the template in the editor.
77
*/
88

9-
namespace Wepesi\app;
9+
namespace Wepesi\App;
1010

1111
/**
1212
* Description of VNumber
@@ -16,11 +16,11 @@
1616
class VNumber {
1717
//put your code here
1818
private $string_value;
19-
private $string_item;
20-
private $source_data;
21-
private $_errors;
22-
private $_min;
23-
private $_max;
19+
private string $string_item;
20+
private array $source_data;
21+
private array $_errors;
22+
private int $_min;
23+
private int $_max;
2424

2525
function __construct(array $source,string $string_item) {
2626
$this->source_data=$source;
@@ -30,82 +30,120 @@ function __construct(array $source,string $string_item) {
3030
$this->string_value=$source[$string_item];
3131
}
3232
}
33-
function min(int $min_values){
33+
34+
/**
35+
* @param int $min_values
36+
* @return $this
37+
*/
38+
function min(int $min_values): VNumber
39+
{
3440
if ((int) $this->string_value < $min_values) {
3541
$message=[
3642
"type"=>"number.min",
37-
"message"=> "`{$this->string_item}` should be greater than `{$min_values}`",
43+
"message"=> i18n::translate("`%s` should be greater than `%s`",[$this->string_item,$min_values]),
3844
"label"=>$this->string_item,
3945
"limit"=>$min_values
4046
];
4147
$this->addError($message);
4248
}
4349
return $this;
4450
}
45-
function max(int $min_values){
51+
52+
/**
53+
* @param int $min_values
54+
* @return $this
55+
*/
56+
function max(int $min_values): VNumber
57+
{
4658
if ((int) $this->string_value > $min_values) {
4759
$message=[
4860
"type"=>"number.max",
49-
"message"=> "`{$this->string_item}` should be less than `{$min_values}`",
61+
"message"=> i18n::translate("`%s` should be less than `%s`",[$this->string_item,$min_values]),
5062
"label"=>$this->string_item,
5163
"limit"=>$min_values
5264
];
5365
$this->addError($message);
5466
}
5567
return $this;
5668
}
57-
function positive(int $min_values){
69+
70+
/**
71+
* @param int $min_values
72+
* @return $this
73+
*/
74+
function positive(int $min_values): VNumber
75+
{
5876
if ((int) $this->string_value < 0) {
5977
$message=[
6078
"type"=>"number.positive",
61-
"message"=> "`{$this->string_item}` should be a positive number",
79+
"message"=> i18n::translate("`%s` should be a positive number",[$this->string_item]),
6280
"label"=>$this->string_item,
6381
"limit"=>1
6482
];
6583
$this->addError($message);
6684
}
6785
return $this;
6886
}
69-
function required(){
87+
88+
/**
89+
* @return $this
90+
*/
91+
function required(): VNumber
92+
{
7093
$required_value= trim($this->string_value);
7194
if (empty($required_value)) {
7295
$message = [
7396
"type"=> "any.required",
74-
"message" => "`{$this->string_item}` is required",
97+
"message" => i18n::translate("`%s` is required",[$this->string_item]),
7598
"label" => $this->string_item,
7699
];
77100
$this->addError($message);
78101
}
79102
return $this;
80103
}
81-
//
82-
private function checkExist(string $itemKey=null){
83-
$item_to_check=$itemKey?$itemKey:$this->string_item;
104+
105+
/**
106+
* @param string|null $itemKey
107+
* @return bool
108+
*/
109+
private function checkExist(string $itemKey=null): bool
110+
{
111+
$item_to_check=!$itemKey?$this->string_item:$itemKey;
84112
$regex_string="#[a-zA-Z]#";
85113
$status_key_exist=true;
86114
if (!isset($this->source_data[$item_to_check])) {
87115
$message = [
88116
"type"=> "any.unknow",
89-
"message" => "`{$item_to_check}` is unknow",
117+
"message" => i18n::translate("`%s` is unknow",[$item_to_check]),
90118
"label" => $item_to_check,
91119
];
92120
$this->addError($message);
93121
$status_key_exist=false;
94122
}else if (preg_match($regex_string,trim($this->source_data[$item_to_check])) || !is_integer($this->source_data[$item_to_check])) {
95123
$message = [
96124
"type"=> "number.unknow",
97-
"message" => "`{$item_to_check}` should be a number",
125+
"message" => i18n::translate("`%s` should be a number",[$item_to_check]),
98126
"label" => $item_to_check,
99127
];
100128
$this->addError($message);
101129
$status_key_exist=false;
102130
}
103131
return $status_key_exist;
104132
}
105-
private function addError(array $value){
106-
return $this->_errors[]=$value;
133+
134+
/**
135+
* @param array $value
136+
*/
137+
private function addError(array $value): void
138+
{
139+
$this->_errors[] = $value;
107140
}
108-
function check(){
141+
142+
/**
143+
* @return array
144+
*/
145+
function check(): array
146+
{
109147
return $this->_errors;
110148
}
111149
}

0 commit comments

Comments
 (0)