PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Widget/Validator/Min.php

https://github.com/putersham/widget
PHP | 46 lines | 21 code | 8 blank | 17 comment | 2 complexity | e5fb60e6c1b95096439cfd477b0353e2 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 greater or equal than specified value
  11. *
  12. * @author Twin Huang <twinhuang@qq.com>
  13. */
  14. class Min extends AbstractValidator
  15. {
  16. protected $minMessage = '%name% must be greater or equal than %min%';
  17. protected $negativeMessage = '%name% must not be greater or equal than %min%';
  18. protected $min;
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function __invoke($input, $min = null)
  23. {
  24. $min && $this->storeOption('min', $min);
  25. return $this->isValid($input);
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. protected function validate($input)
  31. {
  32. if ($this->min > $input) {
  33. $this->addError('min');
  34. return false;
  35. }
  36. return true;
  37. }
  38. }