File indexing completed on 2024-12-22 05:37:12
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Validate 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 /** 0023 * @see Zend_Validate_Abstract 0024 */ 0025 // require_once 'Zend/Validate/Abstract.php'; 0026 0027 /** 0028 * @category Zend 0029 * @package Zend_Validate 0030 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0031 * @license http://framework.zend.com/license/new-bsd New BSD License 0032 */ 0033 class Zend_Validate_GreaterThan extends Zend_Validate_Abstract 0034 { 0035 0036 const NOT_GREATER = 'notGreaterThan'; 0037 0038 /** 0039 * @var array 0040 */ 0041 protected $_messageTemplates = array( 0042 self::NOT_GREATER => "'%value%' is not greater than '%min%'", 0043 ); 0044 0045 /** 0046 * @var array 0047 */ 0048 protected $_messageVariables = array( 0049 'min' => '_min' 0050 ); 0051 0052 /** 0053 * Minimum value 0054 * 0055 * @var mixed 0056 */ 0057 protected $_min; 0058 0059 /** 0060 * Sets validator options 0061 * 0062 * @param mixed|Zend_Config $min 0063 * @throws Zend_Validate_Exception 0064 */ 0065 public function __construct($min) 0066 { 0067 if ($min instanceof Zend_Config) { 0068 $min = $min->toArray(); 0069 } 0070 0071 if (is_array($min)) { 0072 if (array_key_exists('min', $min)) { 0073 $min = $min['min']; 0074 } else { 0075 // require_once 'Zend/Validate/Exception.php'; 0076 throw new Zend_Validate_Exception("Missing option 'min'"); 0077 } 0078 } 0079 0080 $this->setMin($min); 0081 } 0082 0083 /** 0084 * Returns the min option 0085 * 0086 * @return mixed 0087 */ 0088 public function getMin() 0089 { 0090 return $this->_min; 0091 } 0092 0093 /** 0094 * Sets the min option 0095 * 0096 * @param mixed $min 0097 * @return Zend_Validate_GreaterThan Provides a fluent interface 0098 */ 0099 public function setMin($min) 0100 { 0101 $this->_min = $min; 0102 return $this; 0103 } 0104 0105 /** 0106 * Defined by Zend_Validate_Interface 0107 * 0108 * Returns true if and only if $value is greater than min option 0109 * 0110 * @param mixed $value 0111 * @return boolean 0112 */ 0113 public function isValid($value) 0114 { 0115 $this->_setValue($value); 0116 0117 if ($this->_min >= $value) { 0118 $this->_error(self::NOT_GREATER); 0119 return false; 0120 } 0121 return true; 0122 } 0123 0124 }