PageRenderTime 60ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Widget/Validator/Max.php

https://github.com/putersham/widget
PHP | 46 lines | 21 code | 8 blank | 17 comment | 2 complexity | 7be221bb443b06a800addf6300f15b39 MD5 | raw file
  1. <?php
  2. /**
  3. * Widget Framework
  4. *
  5. * @copyright Copyright (c) 2008-2013 Twin Huang
  6. * @license http://opensource.org/licenses/mit-license.php MIT License
  7. */
  8. namespace Widget\Validator;
  9. /**
  10. * Check if the input is less or equal than specified value
  11. *
  12. * @author Twin Huang <twinhuang@qq.com>
  13. */
  14. class Max extends AbstractValidator
  15. {
  16. protected $maxMessage = '%name% must be less or equal than %max%';
  17. protected $negativeMessage = '%name% must not be less or equal than %max%';
  18. protected $max;
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function __invoke($input, $max = null)
  23. {
  24. $max && $this->storeOption('max', $max);
  25. return $this->isValid($input);
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. protected function validate($input)
  31. {
  32. if ($this->max < $input) {
  33. $this->addError('max');
  34. return false;
  35. }
  36. return true;
  37. }
  38. }