You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
820 B

11 years ago
  1. <?php namespace Majestic\Validator;
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage validator
  7. * @since 2010-04-26
  8. */
  9. class EqualValidator extends \Majestic\Validator
  10. {
  11. const NOT_EQUAL = 'not_match';
  12. protected $templates = array(self::NOT_EQUAL => 'Tokens do not match');
  13. protected $token;
  14. public function __construct($token)
  15. {
  16. $this->token = $token;
  17. }
  18. public function isValid($value, $context = null)
  19. {
  20. $this->setValue($value);
  21. if ($this->token === null) {
  22. throw new InitializationException('Token not defined.');
  23. }
  24. if ($value !== $this->token) {
  25. $this->error();
  26. return false;
  27. }
  28. return true;
  29. }
  30. }