12 * obtain it through the world-wide-web, please send an email |
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. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Validate |
16 * @package Zend_Validate |
17 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
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 |
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @version $Id: StringLength.php 24593 2012-01-05 20:35:02Z matthew $ |
19 * @version $Id$ |
20 */ |
20 */ |
21 |
21 |
22 /** |
22 /** |
23 * @see Zend_Validate_Abstract |
23 * @see Zend_Validate_Abstract |
24 */ |
24 */ |
25 require_once 'Zend/Validate/Abstract.php'; |
25 require_once 'Zend/Validate/Abstract.php'; |
26 |
26 |
27 /** |
27 /** |
28 * @category Zend |
28 * @category Zend |
29 * @package Zend_Validate |
29 * @package Zend_Validate |
30 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
30 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
31 * @license http://framework.zend.com/license/new-bsd New BSD License |
31 * @license http://framework.zend.com/license/new-bsd New BSD License |
32 */ |
32 */ |
33 class Zend_Validate_StringLength extends Zend_Validate_Abstract |
33 class Zend_Validate_StringLength extends Zend_Validate_Abstract |
34 { |
34 { |
35 const INVALID = 'stringLengthInvalid'; |
35 const INVALID = 'stringLengthInvalid'; |
77 protected $_encoding; |
77 protected $_encoding; |
78 |
78 |
79 /** |
79 /** |
80 * Sets validator options |
80 * Sets validator options |
81 * |
81 * |
82 * @param integer|array|Zend_Config $options |
82 * @param integer|array|Zend_Config $options |
83 * @return void |
|
84 */ |
83 */ |
85 public function __construct($options = array()) |
84 public function __construct($options = array()) |
86 { |
85 { |
87 if ($options instanceof Zend_Config) { |
86 if ($options instanceof Zend_Config) { |
88 $options = $options->toArray(); |
87 $options = $options->toArray(); |
192 |
191 |
193 /** |
192 /** |
194 * Sets a new encoding to use |
193 * Sets a new encoding to use |
195 * |
194 * |
196 * @param string $encoding |
195 * @param string $encoding |
|
196 * @throws Zend_Validate_Exception |
197 * @return Zend_Validate_StringLength |
197 * @return Zend_Validate_StringLength |
198 */ |
198 */ |
199 public function setEncoding($encoding = null) |
199 public function setEncoding($encoding = null) |
200 { |
200 { |
201 if ($encoding !== null) { |
201 if ($encoding !== null) { |
202 $orig = iconv_get_encoding('internal_encoding'); |
202 $orig = PHP_VERSION_ID < 50600 |
203 $result = iconv_set_encoding('internal_encoding', $encoding); |
203 ? iconv_get_encoding('internal_encoding') |
|
204 : ini_get('default_charset'); |
|
205 if (PHP_VERSION_ID < 50600) { |
|
206 $result = iconv_set_encoding('internal_encoding', $encoding); |
|
207 } else { |
|
208 $result = ini_set('default_charset', $encoding); |
|
209 } |
204 if (!$result) { |
210 if (!$result) { |
205 require_once 'Zend/Validate/Exception.php'; |
211 require_once 'Zend/Validate/Exception.php'; |
206 throw new Zend_Validate_Exception('Given encoding not supported on this OS!'); |
212 throw new Zend_Validate_Exception('Given encoding not supported on this OS!'); |
207 } |
213 } |
208 |
214 |
209 iconv_set_encoding('internal_encoding', $orig); |
215 if (PHP_VERSION_ID < 50600) { |
|
216 iconv_set_encoding('internal_encoding', $orig); |
|
217 } else { |
|
218 ini_set('default_charset', $orig); |
|
219 } |
210 } |
220 } |
211 |
221 |
212 $this->_encoding = $encoding; |
222 $this->_encoding = $encoding; |
213 return $this; |
223 return $this; |
214 } |
224 } |