Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/Data/Locale/Validator/En.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Ballen\Plexity\Data\Locale\Validator;

class En{
static $messages = [
'checkMinimumLength'=>'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.'
];
}
16 changes: 16 additions & 0 deletions lib/Data/Locale/Validator/Tr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Ballen\Plexity\Data\Locale\Validator;

class Tr{
static $messages = [
'checkMinimumLength'=>'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.'
];
}
4 changes: 3 additions & 1 deletion lib/Plexity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])));
}

/**
Expand Down
40 changes: 33 additions & 7 deletions lib/Support/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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__]);
}
}
}
Expand All @@ -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__]);
}
}
}
Expand All @@ -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__]);
}
}
}
Expand All @@ -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__]);
}
}
}
Expand All @@ -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__]);
}
}
}
Expand Down Expand Up @@ -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__]);
}
}

Expand All @@ -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__]);
}
}

Expand All @@ -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;
}
}