Add namespace.
This commit is contained in:
39
Validator/RegexValidator.php
Normal file
39
Validator/RegexValidator.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php namespace Majestic\Validator;
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage validator
|
||||
* @since 2010-04-26
|
||||
*/
|
||||
|
||||
class RegexValidator extends Validator
|
||||
{
|
||||
|
||||
const NOT_MATCH = 'regex_not_match';
|
||||
|
||||
protected $vars = array('regex');
|
||||
protected $templates = array(self::NOT_MATCH => '"%value%" does not match against regex "%regex%"');
|
||||
|
||||
protected $regex;
|
||||
|
||||
public function __construct($regex)
|
||||
{
|
||||
$this->regex = $regex;
|
||||
}
|
||||
|
||||
public function isValid($value, $context = null)
|
||||
{
|
||||
$this->setValue($value);
|
||||
|
||||
$status = preg_match($this->regex, $value);
|
||||
if ($status === false) {
|
||||
throw new \Majestic\Exception\GeneralException('Internal error matching regex "' . $this->regex . ' against value "' . $value . '"');
|
||||
}
|
||||
if (!$status) {
|
||||
$this->error();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user