Skip to content

Commit 97e85ad

Browse files
committed
[UPD]translate date,[FIX] make namestace start with uppercase
1 parent 5496d99 commit 97e85ad

File tree

13 files changed

+58
-49
lines changed

13 files changed

+58
-49
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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
"`%s` should match %s"=>"`%s` doit correpondre a `%s`",
88
"`%s` is required"=>"`%s` est obligatoire",
99
"`%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`",
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`",
1212
"`%s` should be a positive number"=>"`%s` devrait être un nombre positif",
13-
"`%s` is unknow"=>"`%s` devrait être inférieur à `%s`",
14-
"`%s` should be less than `%s`"=>"`%s` devrait être inférieur à `%s`",
15-
"`%s` should be less than `%s`"=>"`%s` devrait être inférieur à `%s`",
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",
1617
];

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: 3 additions & 3 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
@@ -40,7 +40,7 @@ function min(int $min_values): VNumber
4040
if ((int) $this->string_value < $min_values) {
4141
$message=[
4242
"type"=>"number.min",
43-
"message"=> i18n::translate("`%s` should be greater than `%s`",[$this->string_item,$min_values]),
43+
"message"=> i18n::translate("`%s` should be greater than `%s`",[$this->string_item,$min_values]),
4444
"label"=>$this->string_item,
4545
"limit"=>$min_values
4646
];
@@ -58,7 +58,7 @@ function max(int $min_values): VNumber
5858
if ((int) $this->string_value > $min_values) {
5959
$message=[
6060
"type"=>"number.max",
61-
"message"=> i18n::translate("`%s` should be less than `%s`",[$this->string_item,$min_values]),
61+
"message"=> i18n::translate("`%s` should be less than `%s`",[$this->string_item,$min_values]),
6262
"label"=>$this->string_item,
6363
"limit"=>$min_values
6464
];

src/VString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
namespace Wepesi\app;
2+
namespace Wepesi\App;
33
/*
44
* To change this license header, choose License Headers in Project Properties.
55
* To change this template file, choose Tools | Templates

src/Validate.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
* Description of validate
66
*

src/i18n.php

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

33

4-
namespace Wepesi\app;
4+
namespace Wepesi\App;
55

66
class i18n
77
{

test/date.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
$schema=[
33
"birth_day"=>$valid->date("birth_day")->min("-18years")->required()->check(),
4-
"date_created"=>$valid->date("birth_day")->now()->required()->check()
4+
"date_created"=>$valid->date("birth_day")->now()->max("100years")->required()->check()
55
];
66
$valid->check($source,$schema);
77

test/index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
use Wepesi\app\Validate;
2+
use Wepesi\App\Validate;
33
//
44
$source = [
55
"name" => "",
@@ -17,6 +17,6 @@
1717
];
1818
$valid=new Validate($source);
1919
// include "./test/string.php";
20-
include "./test/number.php";
20+
// include "./test/number.php";
2121
// include "./test/boolean.php";
22-
// include "./test/date.php";
22+
include "./test/date.php";

test/number.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
2-
$check=[
2+
$schema=[
33
"age"=>$valid->number("age")->min(18)->max(50)->required()->check()
44
];
5-
$valid->check($source,$check);
5+
$valid->check($source,$schema);
66
var_dump($valid->passed());
77
var_dump($valid->errors());

0 commit comments

Comments
 (0)