From d759a38b377ccd9affdce51551beacce66a808bb Mon Sep 17 00:00:00 2001 From: Mehmet Ali Date: Fri, 26 Aug 2022 12:53:08 +0300 Subject: [PATCH 1/4] add, English message list class has been created. --- lib/Data/Locale/Validator/En.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/Data/Locale/Validator/En.php diff --git a/lib/Data/Locale/Validator/En.php b/lib/Data/Locale/Validator/En.php new file mode 100644 index 0000000..3efae88 --- /dev/null +++ b/lib/Data/Locale/Validator/En.php @@ -0,0 +1,16 @@ +'The length does not meet the minimum length requirements.', + 'checkMaximumLength'=>'The length exceeds the maximum length requirements.', + 'checkLowerCase'=>'The string failed to meet the lower case requirements.', + 'checkUpperCase'=>'The string failed to meet the upper case requirements.', + 'checkNumericCharacters'=>'The string failed to meet the numeric character requirements.', + 'checkSpecialCharacters'=>'The string failed to meet the special character requirements.', + 'validateNotInArray'=>'The string exists in the list of disallowed values requirements.', + 'validateNotInPasswordHistoryImplementation'=>'The string exists in the list of disallowed values requirements.' + ]; +} \ No newline at end of file From ca6dad2537692a7dea77135c17825f9cc3218ee0 Mon Sep 17 00:00:00 2001 From: Mehmet Ali Date: Fri, 26 Aug 2022 12:53:20 +0300 Subject: [PATCH 2/4] add, Turkish message list class has been created. --- lib/Data/Locale/Validator/Tr.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/Data/Locale/Validator/Tr.php diff --git a/lib/Data/Locale/Validator/Tr.php b/lib/Data/Locale/Validator/Tr.php new file mode 100644 index 0000000..f772bc8 --- /dev/null +++ b/lib/Data/Locale/Validator/Tr.php @@ -0,0 +1,16 @@ +'Uzunluk, minimum uzunluk gereksinimlerini karşılamıyor.', + 'checkMaximumLength'=>'Uzunluk, maksimum uzunluk gereksinimlerini aşıyor.', + 'checkLowerCase'=>'Dize, küçük harf gereksinimlerini karşılayamadı.', + 'checkUpperCase'=>'Dize, büyük harf gereksinimlerini karşılayamadı.', + 'checkNumericCharacters'=>'Dize sayısal karakter gereksinimlerini karşılayamadı.', + 'checkSpecialCharacters'=>'Dize, özel karakter gereksinimlerini karşılayamadı.', + 'validateNotInArray'=>'Dize, izin verilmeyen değerler gereksinimleri listesinde var.', + 'validateNotInPasswordHistoryImplementation'=>'Dize, izin verilmeyen değerler gereksinimleri listesinde var.' + ]; +} \ No newline at end of file From a6fd9add3a3ac1f45f2b412aa56ce483ab3ba3cc Mon Sep 17 00:00:00 2001 From: Mehmet Ali Date: Fri, 26 Aug 2022 12:56:25 +0300 Subject: [PATCH 3/4] update "locale" property added, "messages" property added "validate" method updated, updated all methods with static messages "setLocale" method added --- lib/Support/Validator.php | 40 ++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/lib/Support/Validator.php b/lib/Support/Validator.php index 54127a1..8c88b81 100644 --- a/lib/Support/Validator.php +++ b/lib/Support/Validator.php @@ -38,6 +38,16 @@ class Validator */ private $configuration; + /** + * Message list of defined iso code + */ + private $locale = 'en'; + + /** + * messages list + */ + private $messages; + /** * Numeric values list * @var array @@ -103,6 +113,13 @@ class Validator */ public function validate(Plexity $configuration) { + + $tmpMessageObj = 'Ballen\\Plexity\\Data\\Locale\\Validator\\' . $this->locale; + if(!class_exists($tmpMessageObj)) + throw new ValidationException('Locale class not found.'); + + $this->messages = $tmpMessageObj::$messages; + $this->configuration = $configuration; $this->checkMinimumLength(); $this->checkMaximumLength(); @@ -137,7 +154,7 @@ public function checkMaximumLength() { if ($this->configuration->rules()->get(Plexity::RULE_LENGTH_MAX) > 0) { if (!$this->validateLengthMax()) { - throw new ValidationException('The length exceeds the maximum length requirements.'); + throw new ValidationException($this->messages[__FUNCTION__]); } } } @@ -151,7 +168,7 @@ public function checkLowerCase() { if ($this->configuration->rules()->get(Plexity::RULE_LOWER) > 0) { if (!$this->validateLowerCase()) { - throw new ValidationException('The string failed to meet the lower case requirements.'); + throw new ValidationException($this->messages[__FUNCTION__]); } } } @@ -165,7 +182,7 @@ public function checkUpperCase() { if ($this->configuration->rules()->get(Plexity::RULE_UPPER) > 0) { if (!$this->validateUpperCase()) { - throw new ValidationException('The string failed to meet the upper case requirements.'); + throw new ValidationException($this->messages[__FUNCTION__]); } } } @@ -179,7 +196,7 @@ public function checkNumericCharacters() { if ($this->configuration->rules()->get(Plexity::RULE_NUMERIC) > 0) { if (!$this->validateNumericCharacters()) { - throw new ValidationException('The string failed to meet the numeric character requirements.'); + throw new ValidationException($this->messages[__FUNCTION__]); } } } @@ -193,7 +210,7 @@ public function checkSpecialCharacters() { if ($this->configuration->rules()->get(Plexity::RULE_SPECIAL) > 0) { if (!$this->validateSpecialCharacters()) { - throw new ValidationException('The string failed to meet the special character requirements.'); + throw new ValidationException($this->messages[__FUNCTION__]); } } } @@ -309,7 +326,7 @@ private function validateNotInArray() { if (in_array($this->configuration->checkString(), (array)$this->configuration->rules()->get(Plexity::RULE_NOT_IN))) { - throw new ValidationException('The string exists in the list of disallowed values requirements.'); + throw new ValidationException($this->messages[__FUNCTION__]); } } @@ -321,7 +338,7 @@ private function validateNotInArray() private function validateNotInPasswordHistoryImplementation() { if (($this->configuration->rules()->get(Plexity::RULE_NOT_IN))->checkHistory($this->configuration->checkString())) { - throw new ValidationException('The string exists in the list of disallowed values requirements.'); + throw new ValidationException($this->messages[__FUNCTION__]); } } @@ -339,4 +356,13 @@ private function countOccurrences(array $needles, $haystack) } return $count; } + + /** + * Defines the locale property. + * @param string $isoCode This data refers to the language ISO 639-1 Code. + * @return void + */ + public function setLocale(string $isoCode) { + $this->locale = $isoCode; + } } From e84dd7c6656b7a65bd5e2faf18b76b542451858a Mon Sep 17 00:00:00 2001 From: Mehmet Ali Date: Fri, 26 Aug 2022 12:56:53 +0300 Subject: [PATCH 4/4] update "__construct" method updated --- lib/Plexity.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Plexity.php b/lib/Plexity.php index 54b9b12..a01d82e 100644 --- a/lib/Plexity.php +++ b/lib/Plexity.php @@ -65,11 +65,13 @@ class Plexity /** * Instaniate a new instance of the Plexity class. */ - public function __construct() + public function __construct(array $args=null) { $this->rules = new Collection($this->defaultConfiguration); $this->validator = new Validator; + if(isset($args['locale'])) + $this->validator->setLocale(ucwords(strtolower($args['locale']))); } /**