2014-06-02 18:58:49 +04:00
|
|
|
<?php namespace Majestic\Validator;
|
2010-04-27 23:03:54 +00:00
|
|
|
/**
|
|
|
|
* @copyright NetMonsters <team@netmonsters.ru>
|
|
|
|
* @link http://netmonsters.ru
|
|
|
|
* @package Majestic
|
|
|
|
* @subpackage validator
|
|
|
|
* @since 2010-04-26
|
|
|
|
*/
|
|
|
|
|
2014-06-04 21:57:19 +04:00
|
|
|
class EqualValidator extends Validator
|
2010-04-27 23:03:54 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
const NOT_EQUAL = 'not_match';
|
|
|
|
|
|
|
|
protected $templates = array(self::NOT_EQUAL => 'Tokens do not match');
|
|
|
|
|
|
|
|
protected $token;
|
|
|
|
|
|
|
|
public function __construct($token)
|
|
|
|
{
|
|
|
|
$this->token = $token;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isValid($value, $context = null)
|
|
|
|
{
|
|
|
|
$this->setValue($value);
|
|
|
|
if ($this->token === null) {
|
2011-11-25 14:55:45 +04:00
|
|
|
throw new InitializationException('Token not defined.');
|
2010-04-27 23:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($value !== $this->token) {
|
|
|
|
$this->error();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|