123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <?php
- namespace Cube\Validate;
- class GreaterThan extends AbstractValidate
- {
- const GREATER_EQUAL = 1;
- const GREATER = 2;
- const TOO_LONG = 3;
- protected $_messages = array(
- self::GREATER_EQUAL => "'%s' must be greater or equal to %value%.",
- self::GREATER => "'%s' must be greater than %value%.",
- );
-
- private $_minValue;
-
- private $_equal = false;
-
- private $_strict = false;
-
- public function __construct(array $data = null)
- {
- $this->setMinValue($data[0]);
- if (isset($data[1])) {
- $this->setEqual($data[1]);
- }
- if (isset($data[2])) {
- $this->setStrict($data[2]);
- }
- }
-
- public function getMinValue()
- {
- return $this->_minValue;
- }
-
- public function setMinValue($minValue)
- {
- $this->_minValue = $minValue;
- return $this;
- }
-
- public function getEqual()
- {
- return $this->_equal;
- }
-
- public function setEqual($equal = true)
- {
- $this->_equal = (bool) $equal;
- if ($this->_equal === true) {
- $this->setMessage($this->_messages[self::GREATER_EQUAL]);
- }
- else {
- $this->setMessage($this->_messages[self::GREATER]);
- }
- return $this;
- }
-
- public function getStrict()
- {
- return $this->_strict;
- }
-
- public function setStrict($strict = true)
- {
- $this->_strict = (bool) $strict;
- return $this;
- }
-
- public function isValid()
- {
- $this->setMessage(
- str_replace('%value%', $this->_minValue, $this->getMessage()));
- if (((empty($this->_value) || (doubleval($this->_value) == 0)) && $this->_strict === false)
- || (is_null($this->_value) && $this->_strict === true)) {
- return true;
- }
- else if ($this->_equal === true) {
- if ($this->_value < $this->_minValue) {
- return false;
- }
- return true;
- }
- else {
- if ($this->_value <= $this->_minValue) {
- return false;
- }
- return true;
- }
- }
- }
|