web/lib/Zend/Locale/Format.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    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_Locale
    16  * @package    Zend_Locale
    17  * @subpackage Format
    17  * @subpackage Format
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @version    $Id: Format.php 22808 2010-08-08 09:38:42Z thomas $
    19  * @version    $Id: Format.php 24807 2012-05-15 12:10:42Z adamlundrigan $
    20  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    21  */
    21  */
    22 
    22 
    23 /**
    23 /**
    24  * include needed classes
    24  * include needed classes
    27 
    27 
    28 /**
    28 /**
    29  * @category   Zend
    29  * @category   Zend
    30  * @package    Zend_Locale
    30  * @package    Zend_Locale
    31  * @subpackage Format
    31  * @subpackage Format
    32  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    32  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    33  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    33  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    34  */
    34  */
    35 class Zend_Locale_Format
    35 class Zend_Locale_Format
    36 {
    36 {
    37     const STANDARD   = 'auto';
    37     const STANDARD   = 'auto';
    97                             $locale = $options['locale'];
    97                             $locale = $options['locale'];
    98                         }
    98                         }
    99                         $options['number_format'] = Zend_Locale_Data::getContent($locale, 'decimalnumber');
    99                         $options['number_format'] = Zend_Locale_Data::getContent($locale, 'decimalnumber');
   100                     } else if ((gettype($value) !== 'string') and ($value !== NULL)) {
   100                     } else if ((gettype($value) !== 'string') and ($value !== NULL)) {
   101                         require_once 'Zend/Locale/Exception.php';
   101                         require_once 'Zend/Locale/Exception.php';
       
   102                         $stringValue = (string)(is_array($value) ? implode(' ', $value) : $value);
   102                         throw new Zend_Locale_Exception("Unknown number format type '" . gettype($value) . "'. "
   103                         throw new Zend_Locale_Exception("Unknown number format type '" . gettype($value) . "'. "
   103                             . "Format '$value' must be a valid number format string.");
   104                             . "Format '$stringValue' must be a valid number format string.");
   104                     }
   105                     }
   105                     break;
   106                     break;
   106 
   107 
   107                 case 'date_format' :
   108                 case 'date_format' :
   108                     if ($value == Zend_Locale_Format::STANDARD) {
   109                     if ($value == Zend_Locale_Format::STANDARD) {
   111                             $locale = $options['locale'];
   112                             $locale = $options['locale'];
   112                         }
   113                         }
   113                         $options['date_format'] = Zend_Locale_Format::getDateFormat($locale);
   114                         $options['date_format'] = Zend_Locale_Format::getDateFormat($locale);
   114                     } else if ((gettype($value) !== 'string') and ($value !== NULL)) {
   115                     } else if ((gettype($value) !== 'string') and ($value !== NULL)) {
   115                         require_once 'Zend/Locale/Exception.php';
   116                         require_once 'Zend/Locale/Exception.php';
       
   117                         $stringValue = (string)(is_array($value) ? implode(' ', $value) : $value);
   116                         throw new Zend_Locale_Exception("Unknown dateformat type '" . gettype($value) . "'. "
   118                         throw new Zend_Locale_Exception("Unknown dateformat type '" . gettype($value) . "'. "
   117                             . "Format '$value' must be a valid ISO or PHP date format string.");
   119                             . "Format '$stringValue' must be a valid ISO or PHP date format string.");
   118                     } else {
   120                     } else {
   119                         if (((isset($options['format_type']) === true) and ($options['format_type'] == 'php')) or
   121                         if (((isset($options['format_type']) === true) and ($options['format_type'] == 'php')) or
   120                             ((isset($options['format_type']) === false) and (self::$_options['format_type'] == 'php'))) {
   122                             ((isset($options['format_type']) === false) and (self::$_options['format_type'] == 'php'))) {
   121                             $options['date_format'] = Zend_Locale_Format::convertPhpToIsoFormat($value);
   123                             $options['date_format'] = Zend_Locale_Format::convertPhpToIsoFormat($value);
   122                         }
   124                         }
   298     public static function toNumber($value, array $options = array())
   300     public static function toNumber($value, array $options = array())
   299     {
   301     {
   300         // load class within method for speed
   302         // load class within method for speed
   301         require_once 'Zend/Locale/Math.php';
   303         require_once 'Zend/Locale/Math.php';
   302 
   304 
       
   305         $value             = Zend_Locale_Math::floatalize($value);
   303         $value             = Zend_Locale_Math::normalize($value);
   306         $value             = Zend_Locale_Math::normalize($value);
   304         $value             = Zend_Locale_Math::floatalize($value);
       
   305         $options           = self::_checkOptions($options) + self::$_options;
   307         $options           = self::_checkOptions($options) + self::$_options;
   306         $options['locale'] = (string) $options['locale'];
   308         $options['locale'] = (string) $options['locale'];
   307 
   309 
   308         // Get correct signs for this locale
   310         // Get correct signs for this locale
   309         $symbols = Zend_Locale_Data::getList($options['locale'], 'symbols');
   311         $symbols = Zend_Locale_Data::getList($options['locale'], 'symbols');
  1135             return false;
  1137             return false;
  1136         }
  1138         }
  1137 
  1139 
  1138         if (empty($options['date_format'])) {
  1140         if (empty($options['date_format'])) {
  1139             $options['format_type'] = 'iso';
  1141             $options['format_type'] = 'iso';
  1140             $options['date_format'] = self::getDateFormat($options['locale']);
  1142             $options['date_format'] = self::getDateFormat(isset($options['locale']) ? $options['locale'] : null);
  1141         }
  1143         }
  1142         $options = self::_checkOptions($options) + self::$_options;
  1144         $options = self::_checkOptions($options) + self::$_options;
  1143 
  1145 
  1144         // day expected but not parsed
  1146         // day expected but not parsed
  1145         if ((iconv_strpos($options['date_format'], 'd', 0, 'UTF-8') !== false) and (!isset($date['day']) or ($date['day'] === ""))) {
  1147         if ((iconv_strpos($options['date_format'], 'd', 0, 'UTF-8') !== false) and (!isset($date['day']) or ($date['day'] === ""))) {