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.

38 lines
823 B

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