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.
16 * @package Zend_Filter
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
23 * @see Zend_Filter_Interface
25 require_once 'Zend/Filter/Interface.php';
29 * @package Zend_Filter
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
33 class Zend_Filter_StringToLower
implements Zend_Filter_Interface
36 * Encoding for the input string
40 protected $_encoding = null;
45 * @param string|array|Zend_Config $options OPTIONAL
47 public function __construct($options = null)
49 if ($options instanceof Zend_Config
) {
50 $options = $options->toArray();
51 } else if (!is_array($options)) {
52 $options = func_get_args();
54 if (!empty($options)) {
55 $temp['encoding'] = array_shift($options);
60 if (array_key_exists('encoding', $options)) {
61 $this->setEncoding($options['encoding']);
66 * Returns the set encoding
70 public function getEncoding()
72 return $this->_encoding
;
76 * Set the input encoding for the given string
78 * @param string $encoding
79 * @return Zend_Filter_StringToLower Provides a fluent interface
80 * @throws Zend_Filter_Exception
82 public function setEncoding($encoding = null)
84 if ($encoding !== null) {
85 if (!function_exists('mb_strtolower')) {
86 require_once 'Zend/Filter/Exception.php';
87 throw new Zend_Filter_Exception('mbstring is required for this feature');
90 $encoding = (string) $encoding;
91 if (!in_array(strtolower($encoding), array_map('strtolower', mb_list_encodings()))) {
92 require_once 'Zend/Filter/Exception.php';
93 throw new Zend_Filter_Exception("The given encoding '$encoding' is not supported by mbstring");
97 $this->_encoding
= $encoding;
102 * Defined by Zend_Filter_Interface
104 * Returns the string $value, converting characters to lowercase as necessary
106 * @param string $value
109 public function filter($value)
111 if ($this->_encoding
!== null) {
112 return mb_strtolower((string) $value, $this->_encoding
);
115 return strtolower((string) $value);