GreaterThan.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Validate
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @see Zend_Validate_Abstract
  23. */
  24. #require_once 'Zend/Validate/Abstract.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Validate
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Validate_GreaterThan extends Zend_Validate_Abstract
  32. {
  33. const NOT_GREATER = 'notGreaterThan';
  34. /**
  35. * @var array
  36. */
  37. protected $_messageTemplates = array(
  38. self::NOT_GREATER => "'%value%' is not greater than '%min%'",
  39. );
  40. /**
  41. * @var array
  42. */
  43. protected $_messageVariables = array(
  44. 'min' => '_min'
  45. );
  46. /**
  47. * Minimum value
  48. *
  49. * @var mixed
  50. */
  51. protected $_min;
  52. /**
  53. * Sets validator options
  54. *
  55. * @param mixed|Zend_Config $min
  56. * @throws Zend_Validate_Exception
  57. */
  58. public function __construct($min)
  59. {
  60. if ($min instanceof Zend_Config) {
  61. $min = $min->toArray();
  62. }
  63. if (is_array($min)) {
  64. if (array_key_exists('min', $min)) {
  65. $min = $min['min'];
  66. } else {
  67. #require_once 'Zend/Validate/Exception.php';
  68. throw new Zend_Validate_Exception("Missing option 'min'");
  69. }
  70. }
  71. $this->setMin($min);
  72. }
  73. /**
  74. * Returns the min option
  75. *
  76. * @return mixed
  77. */
  78. public function getMin()
  79. {
  80. return $this->_min;
  81. }
  82. /**
  83. * Sets the min option
  84. *
  85. * @param mixed $min
  86. * @return Zend_Validate_GreaterThan Provides a fluent interface
  87. */
  88. public function setMin($min)
  89. {
  90. $this->_min = $min;
  91. return $this;
  92. }
  93. /**
  94. * Defined by Zend_Validate_Interface
  95. *
  96. * Returns true if and only if $value is greater than min option
  97. *
  98. * @param mixed $value
  99. * @return boolean
  100. */
  101. public function isValid($value)
  102. {
  103. $this->_setValue($value);
  104. if ($this->_min >= $value) {
  105. $this->_error(self::NOT_GREATER);
  106. return false;
  107. }
  108. return true;
  109. }
  110. }