PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/filter/max.php

https://bitbucket.org/oligriffiths/com_validation
PHP | 52 lines | 27 code | 9 blank | 16 comment | 0 complexity | a9eafe3c466a206ea2f434f5d55cb7b9 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 FilterMax extends Library\FilterAbstract
  10. {
  11. protected $_max;
  12. public function __construct(Library\ObjectConfig $config)
  13. {
  14. parent::__construct($config);
  15. $this->_max = $config->max;
  16. }
  17. protected function _initialize(Library\ObjectConfig $config)
  18. {
  19. $config->append(array(
  20. 'max' => null
  21. ));
  22. parent::_initialize($config);
  23. }
  24. /**
  25. * Validate the value is not greater than max
  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->_max;
  33. }
  34. /**
  35. * Sanitize the data, returns null if value greater than max
  36. * @param scalar Value to be sanitized
  37. * @return mixed
  38. */
  39. public function sanitize($value)
  40. {
  41. return $value > $this->_max ? null : $value;
  42. }
  43. }