File indexing completed on 2025-01-19 05:21:08
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_Filter 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_Filter_Interface 0024 */ 0025 // require_once 'Zend/Filter/Interface.php'; 0026 0027 /** 0028 * @see Zend_Loader 0029 */ 0030 // require_once 'Zend/Locale/Format.php'; 0031 0032 /** 0033 * Localizes given normalized input 0034 * 0035 * @category Zend 0036 * @package Zend_Filter 0037 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0038 * @license http://framework.zend.com/license/new-bsd New BSD License 0039 */ 0040 class Zend_Filter_NormalizedToLocalized implements Zend_Filter_Interface 0041 { 0042 /** 0043 * Set options 0044 */ 0045 protected $_options = array( 0046 'locale' => null, 0047 'date_format' => null, 0048 'precision' => null 0049 ); 0050 0051 /** 0052 * Class constructor 0053 * 0054 * @param string|Zend_Locale $locale (Optional) Locale to set 0055 */ 0056 public function __construct($options = null) 0057 { 0058 if ($options instanceof Zend_Config) { 0059 $options = $options->toArray(); 0060 } 0061 0062 if (null !== $options) { 0063 $this->setOptions($options); 0064 } 0065 } 0066 0067 /** 0068 * Returns the set options 0069 * 0070 * @return array 0071 */ 0072 public function getOptions() 0073 { 0074 return $this->_options; 0075 } 0076 0077 /** 0078 * Sets options to use 0079 * 0080 * @param array $options (Optional) Options to use 0081 * @return Zend_Filter_LocalizedToNormalized 0082 */ 0083 public function setOptions(array $options = null) 0084 { 0085 $this->_options = $options + $this->_options; 0086 return $this; 0087 } 0088 0089 /** 0090 * Defined by Zend_Filter_Interface 0091 * 0092 * Normalizes the given input 0093 * 0094 * @param string $value Value to normalized 0095 * @return string|array The normalized value 0096 */ 0097 public function filter($value) 0098 { 0099 if (is_array($value)) { 0100 // require_once 'Zend/Date.php'; 0101 $date = new Zend_Date($value, $this->_options['locale']); 0102 return $date->toString($this->_options['date_format']); 0103 } else if ($this->_options['precision'] === 0) { 0104 return Zend_Locale_Format::toInteger($value, $this->_options); 0105 } else if ($this->_options['precision'] === null) { 0106 return Zend_Locale_Format::toFloat($value, $this->_options); 0107 } 0108 0109 return Zend_Locale_Format::toNumber($value, $this->_options); 0110 } 0111 }