00001 <?php 00002 00027 require_once 'Zend/Validate/Abstract.php'; 00028 00029 00036 class Zend_Validate_Between extends Zend_Validate_Abstract 00037 { 00041 const NOT_BETWEEN = 'notBetween'; 00042 00046 const NOT_BETWEEN_STRICT = 'notBetweenStrict'; 00047 00053 protected $_messageTemplates = array( 00054 self::NOT_BETWEEN => "'%value%' is not between '%min%' and '%max%', inclusively", 00055 self::NOT_BETWEEN_STRICT => "'%value%' is not strictly between '%min%' and '%max%'" 00056 ); 00057 00063 protected $_messageVariables = array( 00064 'min' => '_min', 00065 'max' => '_max' 00066 ); 00067 00073 protected $_min; 00074 00080 protected $_max; 00081 00090 protected $_inclusive; 00091 00100 public function __construct($min, $max, $inclusive = true) 00101 { 00102 $this->setMin($min) 00103 ->setMax($max) 00104 ->setInclusive($inclusive); 00105 } 00106 00112 public function getMin() 00113 { 00114 return $this->_min; 00115 } 00116 00123 public function setMin($min) 00124 { 00125 $this->_min = $min; 00126 return $this; 00127 } 00128 00134 public function getMax() 00135 { 00136 return $this->_max; 00137 } 00138 00145 public function setMax($max) 00146 { 00147 $this->_max = $max; 00148 return $this; 00149 } 00150 00156 public function getInclusive() 00157 { 00158 return $this->_inclusive; 00159 } 00160 00167 public function setInclusive($inclusive) 00168 { 00169 $this->_inclusive = $inclusive; 00170 return $this; 00171 } 00172 00182 public function isValid($value) 00183 { 00184 $this->_setValue($value); 00185 00186 if ($this->_inclusive) { 00187 if ($this->_min > $value || $value > $this->_max) { 00188 $this->_error(self::NOT_BETWEEN); 00189 return false; 00190 } 00191 } else { 00192 if ($this->_min >= $value || $value >= $this->_max) { 00193 $this->_error(self::NOT_BETWEEN_STRICT); 00194 return false; 00195 } 00196 } 00197 return true; 00198 } 00199 00200 }