Added new validators without tests
This commit is contained in:
39
validator/MbStrlenValidator.php
Normal file
39
validator/MbStrlenValidator.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright NetMonsters <team@netmonsters.ru>
|
||||||
|
* @link http://netmonsters.ru
|
||||||
|
* @package Majestic
|
||||||
|
* @subpackage forms
|
||||||
|
* @since 17.05.12
|
||||||
|
* @author Aleksander Demidov
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class MbStrlenValidator extends Validator
|
||||||
|
{
|
||||||
|
|
||||||
|
const GREATHER_THAN = 'not_match';
|
||||||
|
|
||||||
|
protected $templates = array(self::GREATHER_THAN => 'String length greather than.');
|
||||||
|
|
||||||
|
protected $token;
|
||||||
|
|
||||||
|
public function __construct($token)
|
||||||
|
{
|
||||||
|
$this->token = $token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isValid($value, $context = null)
|
||||||
|
{
|
||||||
|
$this->setValue($value);
|
||||||
|
if ($this->token === null) {
|
||||||
|
throw new InitializationException('Token not defined.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mb_strlen($value) > $this->token) {
|
||||||
|
$this->error();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
39
validator/StrlenValidator.php
Normal file
39
validator/StrlenValidator.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright NetMonsters <team@netmonsters.ru>
|
||||||
|
* @link http://netmonsters.ru
|
||||||
|
* @package Majestic
|
||||||
|
* @subpackage forms
|
||||||
|
* @since 17.05.12
|
||||||
|
* @author Aleksander Demidov
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class StrlenValidator extends Validator
|
||||||
|
{
|
||||||
|
|
||||||
|
const GREATHER_THAN = 'not_match';
|
||||||
|
|
||||||
|
protected $templates = array(self::GREATHER_THAN => 'String length greather than.');
|
||||||
|
|
||||||
|
protected $token;
|
||||||
|
|
||||||
|
public function __construct($token)
|
||||||
|
{
|
||||||
|
$this->token = $token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isValid($value, $context = null)
|
||||||
|
{
|
||||||
|
$this->setValue($value);
|
||||||
|
if ($this->token === null) {
|
||||||
|
throw new InitializationException('Token not defined.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen($value) > $this->token) {
|
||||||
|
$this->error();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user