PageRenderTime 53ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/components/com_validation/filters/min.php

https://bitbucket.org/oligriffiths/com_validation
PHP | 50 lines | 26 code | 8 blank | 16 comment | 0 complexity | de81a49e24d9df0fcf5c666324d6090c MD5 | raw file
  1. <?php
  2. /**
  3. * Created By: Oli Griffiths
  4. * Date: 11/12/2012
  5. * Time: 12:24
  6. */
  7. defined('KOOWA') or die('Protected resource');
  8. class ComValidationFilterMin extends KFilterAbstract
  9. {
  10. protected $_min;
  11. public function __construct(KConfig $config)
  12. {
  13. parent::__construct($config);
  14. $this->_min = $config->min;
  15. }
  16. protected function _initialize(KConfig $config)
  17. {
  18. $config->append(array(
  19. 'min' => null
  20. ));
  21. parent::_initialize($config);
  22. }
  23. /**
  24. * Validate the value is not less than min
  25. *
  26. * @param scalar Value to be validated
  27. * @return bool True when the variable is valid
  28. */
  29. protected function _validate($value)
  30. {
  31. return $value >= $this->_min;
  32. }
  33. /**
  34. * Sanitize the data, returns null if value less than min
  35. * @param scalar Value to be sanitized
  36. * @return mixed
  37. */
  38. protected function _sanitize($value)
  39. {
  40. return $value < $this->_min ? null : $value;
  41. }
  42. }