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-2010 Zend Technologies USA Inc. (http://www.zend.com) |
---|
18 | * @license http://framework.zend.com/license/new-bsd New BSD License |
---|
19 | * @version $Id: GreaterThan.php 20352 2010-01-17 17:55:38Z thomas $ |
---|
20 | */ |
---|
21 | |
---|
22 | /** |
---|
23 | * @see Zend_Validate_Abstract |
---|
24 | */ |
---|
25 | require_once 'Zend/Validate/Abstract.php'; |
---|
26 | |
---|
27 | /** |
---|
28 | * @category Zend |
---|
29 | * @package Zend_Validate |
---|
30 | * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
---|
31 | * @license http://framework.zend.com/license/new-bsd New BSD License |
---|
32 | */ |
---|
33 | class Zend_Validate_GreaterThan extends Zend_Validate_Abstract |
---|
34 | { |
---|
35 | |
---|
36 | const NOT_GREATER = 'notGreaterThan'; |
---|
37 | |
---|
38 | /** |
---|
39 | * @var array |
---|
40 | */ |
---|
41 | protected $_messageTemplates = array( |
---|
42 | self::NOT_GREATER => "'%value%' is not greater than '%min%'", |
---|
43 | ); |
---|
44 | |
---|
45 | /** |
---|
46 | * @var array |
---|
47 | */ |
---|
48 | protected $_messageVariables = array( |
---|
49 | 'min' => '_min' |
---|
50 | ); |
---|
51 | |
---|
52 | /** |
---|
53 | * Minimum value |
---|
54 | * |
---|
55 | * @var mixed |
---|
56 | */ |
---|
57 | protected $_min; |
---|
58 | |
---|
59 | /** |
---|
60 | * Sets validator options |
---|
61 | * |
---|
62 | * @param mixed|Zend_Config $min |
---|
63 | * @return void |
---|
64 | */ |
---|
65 | public function __construct($min) |
---|
66 | { |
---|
67 | if ($min instanceof Zend_Config) { |
---|
68 | $min = $min->toArray(); |
---|
69 | } |
---|
70 | |
---|
71 | if (is_array($min)) { |
---|
72 | if (array_key_exists('min', $min)) { |
---|
73 | $min = $min['min']; |
---|
74 | } else { |
---|
75 | require_once 'Zend/Validate/Exception.php'; |
---|
76 | throw new Zend_Validate_Exception("Missing option 'min'"); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | $this->setMin($min); |
---|
81 | } |
---|
82 | |
---|
83 | /** |
---|
84 | * Returns the min option |
---|
85 | * |
---|
86 | * @return mixed |
---|
87 | */ |
---|
88 | public function getMin() |
---|
89 | { |
---|
90 | return $this->_min; |
---|
91 | } |
---|
92 | |
---|
93 | /** |
---|
94 | * Sets the min option |
---|
95 | * |
---|
96 | * @param mixed $min |
---|
97 | * @return Zend_Validate_GreaterThan Provides a fluent interface |
---|
98 | */ |
---|
99 | public function setMin($min) |
---|
100 | { |
---|
101 | $this->_min = $min; |
---|
102 | return $this; |
---|
103 | } |
---|
104 | |
---|
105 | /** |
---|
106 | * Defined by Zend_Validate_Interface |
---|
107 | * |
---|
108 | * Returns true if and only if $value is greater than min option |
---|
109 | * |
---|
110 | * @param mixed $value |
---|
111 | * @return boolean |
---|
112 | */ |
---|
113 | public function isValid($value) |
---|
114 | { |
---|
115 | $this->_setValue($value); |
---|
116 | |
---|
117 | if ($this->_min >= $value) { |
---|
118 | $this->_error(self::NOT_GREATER); |
---|
119 | return false; |
---|
120 | } |
---|
121 | return true; |
---|
122 | } |
---|
123 | |
---|
124 | } |
---|