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
824 B

  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage forms
  7. * @since 17.05.12
  8. * @author Aleksander Demidov
  9. *
  10. */
  11. class StrlenValidator extends \Majestic\Validator
  12. {
  13. const GREATHER_THAN = 'not_match';
  14. protected $templates = array(self::GREATHER_THAN => 'String length greather than.');
  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 (strlen($value) > $this->token) {
  27. $this->error();
  28. return false;
  29. }
  30. return true;
  31. }
  32. }