Skip to content

Commit

Permalink
Merge pull request #38 from bim-g/v2
Browse files Browse the repository at this point in the history
[UPD] update translation for vnumber
  • Loading branch information
bim-g committed Jan 2, 2022
2 parents 3665bd1 + 31c5635 commit e42ebcb
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 82 deletions.
5 changes: 5 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/wepesi_validation.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"autoload": {
"psr-4": {
"Wepesi\\app\\":"src/"
"Wepesi\\App\\":"src/"
}
},
"require": {
Expand Down
12 changes: 10 additions & 2 deletions lang/fr/language.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<?php
$language=[
"`%s` should have minimum of `%s` caracters"=>"`%s` doit avoir un minimum de `%s` caracteres",
"`%s` should have maximum of `%s` caracters"=>"`%s` doit avoir un maximum de `%s` caracteres",
"`%s` should have minimum of `%s` characters"=>"`%s` doit avoir un minimum de `%s` caractèress",
"`%s` should have maximum of `%s` characters"=>"`%s` doit avoir un maximum de `%s` caractèress",
"`%s` this should be an email"=>"`%s` doit etre un email",
"`%s` this should be a link(url)"=>"`%s` doit avoir un lien(url) ",
"`%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 a positive number"=>"`%s` devrait être un nombre positif",
"`%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",
"`%s` should be a string"=>"`%s` doit est une chaine de caractere",
];
2 changes: 1 addition & 1 deletion src/VBoolean.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Wepesi\app;
namespace Wepesi\App;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
Expand Down
61 changes: 32 additions & 29 deletions src/VDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@


namespace Wepesi\App;

/**
* Description of VNumber
* Description of VDate
*
* @author Boss Ibrahim Mussa
*/
class VDate
{
private $date_value;
private $string_item;
private $source_data;
private $_errors;
private $_min;
private $_max;
// private $_mois=["Janviers","Fevrier","Mars","Avril","Mai","Juin","Jouillet","Aout","Septenbre","Octobre","Novembre","Decembre"];
private ?string $string_item;
private array $source_data;
private array $_errors=[];
private int $_min;
private int $_max;
//put your code here
function __construct(array $source,string $string_item=null) {
$this->date_value=$source[$string_item];
Expand All @@ -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
];
Expand All @@ -50,42 +49,44 @@ 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
];
$this->addError($message);
}
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
];
Expand All @@ -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
];
Expand All @@ -120,42 +121,44 @@ 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);
}
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;
Expand Down
82 changes: 60 additions & 22 deletions src/VNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* and open the template in the editor.
*/

namespace Wepesi\app;
namespace Wepesi\App;

/**
* Description of VNumber
Expand All @@ -16,11 +16,11 @@
class VNumber {
//put your code here
private $string_value;
private $string_item;
private $source_data;
private $_errors;
private $_min;
private $_max;
private string $string_item;
private array $source_data;
private array $_errors;
private int $_min;
private int $_max;

function __construct(array $source,string $string_item) {
$this->source_data=$source;
Expand All @@ -30,82 +30,120 @@ function __construct(array $source,string $string_item) {
$this->string_value=$source[$string_item];
}
}
function min(int $min_values){

/**
* @param int $min_values
* @return $this
*/
function min(int $min_values): VNumber
{
if ((int) $this->string_value < $min_values) {
$message=[
"type"=>"number.min",
"message"=> "`{$this->string_item}` should be greater than `{$min_values}`",
"message"=> i18n::translate("`%s` should be greater than `%s`",[$this->string_item,$min_values]),
"label"=>$this->string_item,
"limit"=>$min_values
];
$this->addError($message);
}
return $this;
}
function max(int $min_values){

/**
* @param int $min_values
* @return $this
*/
function max(int $min_values): VNumber
{
if ((int) $this->string_value > $min_values) {
$message=[
"type"=>"number.max",
"message"=> "`{$this->string_item}` should be less than `{$min_values}`",
"message"=> i18n::translate("`%s` should be less than `%s`",[$this->string_item,$min_values]),
"label"=>$this->string_item,
"limit"=>$min_values
];
$this->addError($message);
}
return $this;
}
function positive(int $min_values){

/**
* @param int $min_values
* @return $this
*/
function positive(int $min_values): VNumber
{
if ((int) $this->string_value < 0) {
$message=[
"type"=>"number.positive",
"message"=> "`{$this->string_item}` should be a positive number",
"message"=> i18n::translate("`%s` should be a positive number",[$this->string_item]),
"label"=>$this->string_item,
"limit"=>1
];
$this->addError($message);
}
return $this;
}
function required(){

/**
* @return $this
*/
function required(): VNumber
{
$required_value= trim($this->string_value);
if (empty($required_value)) {
$message = [
"type"=> "any.required",
"message" => "`{$this->string_item}` is required",
"message" => i18n::translate("`%s` is required",[$this->string_item]),
"label" => $this->string_item,
];
$this->addError($message);
}
return $this;
}
//
private function checkExist(string $itemKey=null){
$item_to_check=$itemKey?$itemKey:$this->string_item;

/**
* @param string|null $itemKey
* @return bool
*/
private function checkExist(string $itemKey=null): bool
{
$item_to_check=!$itemKey?$this->string_item:$itemKey;
$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",
"message" => i18n::translate("`%s` is unknow",[$item_to_check]),
"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",
"message" => i18n::translate("`%s` should be a number",[$item_to_check]),
"label" => $item_to_check,
];
$this->addError($message);
$status_key_exist=false;
}
return $status_key_exist;
}
private function addError(array $value){
return $this->_errors[]=$value;

/**
* @param array $value
*/
private function addError(array $value): void
{
$this->_errors[] = $value;
}
function check(){

/**
* @return array
*/
function check(): array
{
return $this->_errors;
}
}
Loading

0 comments on commit e42ebcb

Please sign in to comment.