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

/filter/min.php

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