import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -17,7 +17,7 @@
|
||||
* @subpackage Data
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Data.php 12057 2008-10-21 17:19:43Z thomas $
|
||||
* @version $Id: Data.php 15765 2009-05-25 19:59:45Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -54,12 +54,20 @@ class Zend_Locale_Data
|
||||
|
||||
/**
|
||||
* Internal cache for ldml values
|
||||
*
|
||||
*
|
||||
* @var Zend_Cache_Core
|
||||
* @access private
|
||||
*/
|
||||
private static $_cache = null;
|
||||
|
||||
/**
|
||||
* Internal option, cache disabled
|
||||
*
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
private static $_cacheDisabled = false;
|
||||
|
||||
/**
|
||||
* Read the content from locale
|
||||
*
|
||||
@ -202,7 +210,6 @@ class Zend_Locale_Data
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read the right LDML file
|
||||
*
|
||||
@ -236,7 +243,6 @@ class Zend_Locale_Data
|
||||
return $temp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find the details for supplemental calendar datas
|
||||
*
|
||||
@ -291,17 +297,25 @@ class Zend_Locale_Data
|
||||
public static function getList($locale, $path, $value = false)
|
||||
{
|
||||
$locale = self::_checkLocale($locale);
|
||||
if (isset(self::$_cache)) {
|
||||
$val = $value;
|
||||
if (is_array($value)) {
|
||||
$val = implode('_' , $value);
|
||||
}
|
||||
|
||||
$val = urlencode($val);
|
||||
$id = strtr('Zend_LocaleL_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_'));
|
||||
if ($result = self::$_cache->load($id)) {
|
||||
return unserialize($result);
|
||||
}
|
||||
if (!isset(self::$_cache) && !self::$_cacheDisabled) {
|
||||
require_once 'Zend/Cache.php';
|
||||
self::$_cache = Zend_Cache::factory(
|
||||
'Core',
|
||||
'File',
|
||||
array('automatic_serialization' => true),
|
||||
array());
|
||||
}
|
||||
|
||||
$val = $value;
|
||||
if (is_array($value)) {
|
||||
$val = implode('_' , $value);
|
||||
}
|
||||
|
||||
$val = urlencode($val);
|
||||
$id = strtr('Zend_LocaleL_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_'));
|
||||
if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
|
||||
return unserialize($result);
|
||||
}
|
||||
|
||||
$temp = array();
|
||||
@ -507,7 +521,7 @@ class Zend_Locale_Data
|
||||
}
|
||||
$temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/availableFormats/dateFormatItem', 'id');
|
||||
break;
|
||||
|
||||
|
||||
case 'field':
|
||||
if (empty($value)) {
|
||||
$value = "gregorian";
|
||||
@ -744,6 +758,56 @@ class Zend_Locale_Data
|
||||
}
|
||||
break;
|
||||
|
||||
case 'phonetoterritory':
|
||||
$_temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory');
|
||||
foreach ($_temp as $key => $keyvalue) {
|
||||
$temp += self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'territorytophone':
|
||||
$_temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory');
|
||||
foreach ($_temp as $key => $keyvalue) {
|
||||
$val = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key);
|
||||
if (!isset($val[$key])) {
|
||||
continue;
|
||||
}
|
||||
if (!isset($temp[$val[$key]])) {
|
||||
$temp[$val[$key]] = $key;
|
||||
} else {
|
||||
$temp[$val[$key]] .= " " . $key;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'numerictoterritory':
|
||||
$_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'type');
|
||||
foreach ($_temp as $key => $keyvalue) {
|
||||
$temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\'' . $key . '\']', 'numeric', $key);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'territorytonumeric':
|
||||
$_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'numeric');
|
||||
foreach ($_temp as $key => $keyvalue) {
|
||||
$temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@numeric=\'' . $key . '\']', 'type', $key);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'alpha3toterritory':
|
||||
$_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'type');
|
||||
foreach ($_temp as $key => $keyvalue) {
|
||||
$temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\'' . $key . '\']', 'alpha3', $key);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'territorytoalpha3':
|
||||
$_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'alpha3');
|
||||
foreach ($_temp as $key => $keyvalue) {
|
||||
$temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@alpha3=\'' . $key . '\']', 'type', $key);
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
require_once 'Zend/Locale/Exception.php';
|
||||
throw new Zend_Locale_Exception("Unknown list ($path) for parsing locale data.");
|
||||
@ -770,16 +834,23 @@ class Zend_Locale_Data
|
||||
{
|
||||
$locale = self::_checkLocale($locale);
|
||||
|
||||
if (isset(self::$_cache)) {
|
||||
$val = $value;
|
||||
if (is_array($value)) {
|
||||
$val = implode('_' , $value);
|
||||
}
|
||||
$val = urlencode($val);
|
||||
$id = strtr('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_'));
|
||||
if ($result = self::$_cache->load($id)) {
|
||||
return unserialize($result);
|
||||
}
|
||||
if (!isset(self::$_cache) && !self::$_cacheDisabled) {
|
||||
require_once 'Zend/Cache.php';
|
||||
self::$_cache = Zend_Cache::factory(
|
||||
'Core',
|
||||
'File',
|
||||
array('automatic_serialization' => true),
|
||||
array());
|
||||
}
|
||||
|
||||
$val = $value;
|
||||
if (is_array($value)) {
|
||||
$val = implode('_' , $value);
|
||||
}
|
||||
$val = urlencode($val);
|
||||
$id = strtr('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_'));
|
||||
if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
|
||||
return unserialize($result);
|
||||
}
|
||||
|
||||
switch(strtolower($path)) {
|
||||
@ -928,7 +999,7 @@ class Zend_Locale_Data
|
||||
}
|
||||
$temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength/dateTimeFormat/pattern', '', 'pattern');
|
||||
break;
|
||||
|
||||
|
||||
case 'field':
|
||||
if (!is_array($value)) {
|
||||
$temp = $value;
|
||||
@ -1136,6 +1207,48 @@ class Zend_Locale_Data
|
||||
}
|
||||
break;
|
||||
|
||||
case 'phonetoterritory':
|
||||
$temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $value . '\']/telephoneCountryCode', 'code', $value);
|
||||
break;
|
||||
|
||||
case 'territorytophone':
|
||||
$_temp2 = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory');
|
||||
$_temp = array();
|
||||
foreach ($_temp2 as $key => $found) {
|
||||
$_temp += self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key);
|
||||
}
|
||||
$temp = array();
|
||||
foreach($_temp as $key => $found) {
|
||||
$_temp3 = explode(" ", $found);
|
||||
foreach($_temp3 as $found3) {
|
||||
if ($found3 !== $value) {
|
||||
continue;
|
||||
}
|
||||
if (!isset($temp[$found3])) {
|
||||
$temp[$found3] = (string) $key;
|
||||
} else {
|
||||
$temp[$found3] .= " " . $key;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'numerictoterritory':
|
||||
$temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\''.$value.'\']', 'numeric', $value);
|
||||
break;
|
||||
|
||||
case 'territorytonumeric':
|
||||
$temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@numeric=\''.$value.'\']', 'type', $value);
|
||||
break;
|
||||
|
||||
case 'alpha3toterritory':
|
||||
$temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\''.$value.'\']', 'alpha3', $value);
|
||||
break;
|
||||
|
||||
case 'territorytoalpha3':
|
||||
$temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@alpha3=\''.$value.'\']', 'type', $value);
|
||||
break;
|
||||
|
||||
default :
|
||||
require_once 'Zend/Locale/Exception.php';
|
||||
throw new Zend_Locale_Exception("Unknown detail ($path) for parsing locale data.");
|
||||
@ -1154,7 +1267,7 @@ class Zend_Locale_Data
|
||||
|
||||
/**
|
||||
* Returns the set cache
|
||||
*
|
||||
*
|
||||
* @return Zend_Cache_Core The set cache
|
||||
*/
|
||||
public static function getCache()
|
||||
@ -1164,7 +1277,7 @@ class Zend_Locale_Data
|
||||
|
||||
/**
|
||||
* Set a cache for Zend_Locale_Data
|
||||
*
|
||||
*
|
||||
* @param Zend_Cache_Core $cache A cache frontend
|
||||
*/
|
||||
public static function setCache(Zend_Cache_Core $cache)
|
||||
@ -1205,4 +1318,14 @@ class Zend_Locale_Data
|
||||
{
|
||||
self::$_cache->clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the cache
|
||||
*
|
||||
* @param unknown_type $flag
|
||||
*/
|
||||
public static function disableCache($flag)
|
||||
{
|
||||
self::$_cacheDisabled = (boolean) $flag;
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Locale
|
||||
* @subpackage Format
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Format.php 12057 2008-10-21 17:19:43Z thomas $
|
||||
* @version $Id: Format.php 15765 2009-05-25 19:59:45Z thomas $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
@ -34,7 +34,7 @@ require_once 'Zend/Locale/Data.php';
|
||||
*/
|
||||
class Zend_Locale_Format
|
||||
{
|
||||
const STANDARD = 'STANDARD';
|
||||
const STANDARD = 'auto';
|
||||
|
||||
private static $_options = array('date_format' => null,
|
||||
'number_format' => null,
|
||||
@ -114,7 +114,7 @@ class Zend_Locale_Format
|
||||
|
||||
switch($name) {
|
||||
case 'number_format' :
|
||||
if ($value == 'standard') {
|
||||
if ($value == Zend_Locale_Format::STANDARD) {
|
||||
$locale = self::$_options['locale'];
|
||||
if (isset($options['locale'])) {
|
||||
$locale = $options['locale'];
|
||||
@ -128,7 +128,7 @@ class Zend_Locale_Format
|
||||
break;
|
||||
|
||||
case 'date_format' :
|
||||
if ($value == 'standard') {
|
||||
if ($value == Zend_Locale_Format::STANDARD) {
|
||||
$locale = self::$_options['locale'];
|
||||
if (isset($options['locale'])) {
|
||||
$locale = $options['locale'];
|
||||
@ -163,14 +163,7 @@ class Zend_Locale_Format
|
||||
break;
|
||||
|
||||
case 'locale' :
|
||||
if (gettype($value) === 'string' && strtolower($value) == 'standard') {
|
||||
$options['locale'] = new Zend_Locale();
|
||||
} else if (!empty($value) && (!Zend_Locale::isLocale($value, null, false))) {
|
||||
require_once 'Zend/Locale/Exception.php';
|
||||
throw new Zend_Locale_Exception("'" .
|
||||
(gettype($value) === 'object' ? get_class($value) : $value)
|
||||
. "' is not a known locale.");
|
||||
}
|
||||
$options['locale'] = Zend_Locale::findLocale($value);
|
||||
break;
|
||||
|
||||
case 'cache' :
|
||||
@ -179,10 +172,15 @@ class Zend_Locale_Format
|
||||
}
|
||||
break;
|
||||
|
||||
case 'disablecache' :
|
||||
Zend_Locale_Data::disableCache($value);
|
||||
break;
|
||||
|
||||
case 'precision' :
|
||||
if ($value === NULL) {
|
||||
$value = -1;
|
||||
}
|
||||
|
||||
if (($value < -1) || ($value > 30)) {
|
||||
require_once 'Zend/Locale/Exception.php';
|
||||
throw new Zend_Locale_Exception("'$value' precision is not a whole number less than 30.");
|
||||
@ -196,6 +194,7 @@ class Zend_Locale_Format
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
@ -264,9 +263,9 @@ class Zend_Locale_Format
|
||||
* '(-){0,1}(\d+(\.){0,1})*(\,){0,1})\d+'
|
||||
* '١١٠ Tests' = 110 call: getNumber($string, 'Arab');
|
||||
*
|
||||
* @param string $input Input string to parse for numbers
|
||||
* @param array $options Options: locale, precision. See {@link setOptions()} for details.
|
||||
* @return integer|string Returns the extracted number
|
||||
* @param string $input Input string to parse for numbers
|
||||
* @param array $options Options: locale, precision. See {@link setOptions()} for details.
|
||||
* @return string Returns the extracted number
|
||||
* @throws Zend_Locale_Exception
|
||||
*/
|
||||
public static function getNumber($input, array $options = array())
|
||||
@ -288,7 +287,7 @@ class Zend_Locale_Format
|
||||
throw new Zend_Locale_Exception('No value in ' . $input . ' found');
|
||||
}
|
||||
$found = $found[0];
|
||||
// Change locale input to be standard number
|
||||
// Change locale input to be default number
|
||||
if ($symbols['minus'] != "-")
|
||||
$found = strtr($found,$symbols['minus'],'-');
|
||||
$found = str_replace($symbols['group'],'', $found);
|
||||
@ -342,7 +341,7 @@ class Zend_Locale_Format
|
||||
if ($format === null) {
|
||||
$format = Zend_Locale_Data::getContent($options['locale'], 'decimalnumber');
|
||||
if (iconv_strpos($format, ';') !== false) {
|
||||
if (call_user_func(Zend_Locale_Math::$comp, $value, 0) < 0) {
|
||||
if (call_user_func(Zend_Locale_Math::$comp, $value, 0, $options['precision']) < 0) {
|
||||
$format = iconv_substr($format, iconv_strpos($format, ';') + 1);
|
||||
} else {
|
||||
$format = iconv_substr($format, 0, iconv_strpos($format, ';'));
|
||||
@ -351,7 +350,7 @@ class Zend_Locale_Format
|
||||
} else {
|
||||
// seperate negative format pattern when available
|
||||
if (iconv_strpos($format, ';') !== false) {
|
||||
if (call_user_func(Zend_Locale_Math::$comp, $value, 0) < 0) {
|
||||
if (call_user_func(Zend_Locale_Math::$comp, $value, 0, $options['precision']) < 0) {
|
||||
$format = iconv_substr($format, iconv_strpos($format, ';') + 1);
|
||||
} else {
|
||||
$format = iconv_substr($format, 0, iconv_strpos($format, ';'));
|
||||
@ -377,17 +376,19 @@ class Zend_Locale_Format
|
||||
}
|
||||
$value = Zend_Locale_Math::normalize($value);
|
||||
}
|
||||
|
||||
if (strpos($format, '0') === false) {
|
||||
require_once 'Zend/Locale/Exception.php';
|
||||
throw new Zend_Locale_Exception('Wrong format... missing 0');
|
||||
}
|
||||
|
||||
// get number parts
|
||||
if (strlen($value) != strlen(Zend_Locale_Math::round($value, 0))) {
|
||||
$pos = iconv_strpos($value, '.');
|
||||
if ($pos !== false) {
|
||||
if ($options['precision'] === null) {
|
||||
$precstr = iconv_substr($value, strlen(Zend_Locale_Math::round($value, 0)) + 1);
|
||||
$precstr = iconv_substr($value, $pos + 1);
|
||||
} else {
|
||||
$precstr = iconv_substr($value, strlen(Zend_Locale_Math::round($value, 0)) + 1, $options['precision']);
|
||||
$precstr = iconv_substr($value, $pos + 1, $options['precision']);
|
||||
if (iconv_strlen($precstr) < $options['precision']) {
|
||||
$precstr = $precstr . str_pad("0", ($options['precision'] - iconv_strlen($precstr)), "0");
|
||||
}
|
||||
@ -418,12 +419,15 @@ class Zend_Locale_Format
|
||||
if (iconv_strpos($prec, '-') !== false) {
|
||||
$prec = iconv_substr($prec, 1);
|
||||
}
|
||||
|
||||
if (($prec == 0) and ($options['precision'] > 0)) {
|
||||
$prec = "0.0";
|
||||
}
|
||||
|
||||
if (($options['precision'] + 2) > iconv_strlen($prec)) {
|
||||
$prec = str_pad((string) $prec, $options['precision'] + 2, "0", STR_PAD_RIGHT);
|
||||
}
|
||||
|
||||
if (iconv_strpos($number, '-') !== false) {
|
||||
$number = iconv_substr($number, 1);
|
||||
}
|
||||
@ -435,15 +439,19 @@ class Zend_Locale_Format
|
||||
if (($value < 0) && (strpos($format, '.'))) {
|
||||
$rest = substr(substr($format, strpos($format, '.') + 1), -1, 1);
|
||||
}
|
||||
|
||||
if ($options['precision'] == '0') {
|
||||
$format = iconv_substr($format, 0, $point) . iconv_substr($format, iconv_strrpos($format, '#') + 2);
|
||||
} else {
|
||||
$format = iconv_substr($format, 0, $point) . $symbols['decimal']
|
||||
. iconv_substr($prec, 2) . iconv_substr($format, iconv_strrpos($format, '#') + 2 + strlen($prec) - 2);
|
||||
. iconv_substr($prec, 2)
|
||||
. iconv_substr($format, iconv_strrpos($format, '#') + 1 + strlen($prec));
|
||||
}
|
||||
|
||||
if (($value < 0) and ($rest != '0') and ($rest != '#')) {
|
||||
$format .= $rest;
|
||||
}
|
||||
|
||||
// Add seperation
|
||||
if ($group == 0) {
|
||||
// no seperation
|
||||
@ -454,7 +462,7 @@ class Zend_Locale_Format
|
||||
for ($x = iconv_strlen($number); $x > $seperation; $x -= $seperation) {
|
||||
if (iconv_substr($number, 0, $x - $seperation) !== "") {
|
||||
$number = iconv_substr($number, 0, $x - $seperation) . $symbols['group']
|
||||
. iconv_substr($number, $x - $seperation);
|
||||
. iconv_substr($number, $x - $seperation);
|
||||
}
|
||||
}
|
||||
$format = iconv_substr($format, 0, iconv_strpos($format, '#')) . $number . iconv_substr($format, $point);
|
||||
@ -468,10 +476,9 @@ class Zend_Locale_Format
|
||||
|
||||
if ((iconv_strlen($number) - 1) > ($point - $group + 1)) {
|
||||
$seperation2 = ($group - $group2 - 1);
|
||||
|
||||
for ($x = iconv_strlen($number) - $seperation2 - 2; $x > $seperation2; $x -= $seperation2) {
|
||||
$number = iconv_substr($number, 0, $x - $seperation2) . $symbols['group']
|
||||
. iconv_substr($number, $x - $seperation2);
|
||||
$number = iconv_substr($number, 0, $x - $seperation2) . $symbols['group']
|
||||
. iconv_substr($number, $x - $seperation2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -479,13 +486,14 @@ class Zend_Locale_Format
|
||||
$format = iconv_substr($format, 0, iconv_strpos($format, '#')) . $number . iconv_substr($format, $point);
|
||||
}
|
||||
// set negative sign
|
||||
if (call_user_func(Zend_Locale_Math::$comp, $value, 0) < 0) {
|
||||
if (call_user_func(Zend_Locale_Math::$comp, $value, 0, $options['precision']) < 0) {
|
||||
if (iconv_strpos($format, '-') === false) {
|
||||
$format = $symbols['minus'] . $format;
|
||||
} else {
|
||||
$format = str_replace('-', $symbols['minus'], $format);
|
||||
}
|
||||
}
|
||||
|
||||
return (string) $format;
|
||||
}
|
||||
|
||||
@ -504,8 +512,10 @@ class Zend_Locale_Format
|
||||
$symbols = Zend_Locale_Data::getList($options['locale'],'symbols');
|
||||
|
||||
// Parse input locale aware
|
||||
$regex = '/^([' . $symbols['minus'] . '-]){0,1}(\d+(\\' . $symbols['group']
|
||||
. '){0,1})*(\\' . $symbols['decimal'] . '){0,1}\d+$/';
|
||||
$regex = '/^[' . $symbols['minus'] . $symbols['plus'] . '-+]?'
|
||||
. '\d(\d*(\\' . $symbols['group'] . ')?\d+)*'
|
||||
. '((\\' . $symbols['decimal'] . ')\d*)?([' . $symbols['exponent'] . 'eE]'
|
||||
. '([' . $symbols['minus'] . $symbols['plus'] . '+-])?\d+)?$/';
|
||||
preg_match($regex, $input, $found);
|
||||
|
||||
if (!isset($found[0]))
|
||||
@ -535,7 +545,7 @@ class Zend_Locale_Format
|
||||
*/
|
||||
public static function toFloat($value, array $options = array())
|
||||
{
|
||||
$options['number_format'] = 'standard';
|
||||
$options['number_format'] = Zend_Locale_Format::STANDARD;
|
||||
return self::toNumber($value, $options);
|
||||
}
|
||||
|
||||
@ -584,7 +594,7 @@ class Zend_Locale_Format
|
||||
public static function toInteger($value, array $options = array())
|
||||
{
|
||||
$options['precision'] = 0;
|
||||
$options['number_format'] = 'standard';
|
||||
$options['number_format'] = Zend_Locale_Format::STANDARD;
|
||||
return self::toNumber($value, $options);
|
||||
}
|
||||
|
||||
@ -597,8 +607,15 @@ class Zend_Locale_Format
|
||||
*/
|
||||
public static function isInteger($value, array $options = array())
|
||||
{
|
||||
$options['precision'] = 0;
|
||||
return self::isNumber($value, $options);
|
||||
if (!self::isNumber($value, $options)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (self::getInteger($value, $options) == self::getFloat($value, $options)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -616,7 +633,7 @@ class Zend_Locale_Format
|
||||
public static function convertPhpToIsoFormat($format)
|
||||
{
|
||||
$convert = array('d' => 'dd' , 'D' => 'EE' , 'j' => 'd' , 'l' => 'EEEE', 'N' => 'e' , 'S' => 'SS' ,
|
||||
'w' => 'eee' , 'z' => 'D' , 'W' => 'w' , 'F' => 'MMMM', 'm' => 'MM' , 'M' => 'MMM' ,
|
||||
'w' => 'eee' , 'z' => 'D' , 'W' => 'ww' , 'F' => 'MMMM', 'm' => 'MM' , 'M' => 'MMM' ,
|
||||
'n' => 'M' , 't' => 'ddd' , 'L' => 'l' , 'o' => 'YYYY', 'Y' => 'yyyy', 'y' => 'yy' ,
|
||||
'a' => 'a' , 'A' => 'a' , 'B' => 'B' , 'g' => 'h' , 'G' => 'H' , 'h' => 'hh' ,
|
||||
'H' => 'HH' , 'i' => 'mm' , 's' => 'ss' , 'e' => 'zzzz', 'I' => 'I' , 'O' => 'Z' ,
|
||||
@ -645,13 +662,6 @@ class Zend_Locale_Format
|
||||
'X', 'r', 'U', 'G', 'w', 'e', 'a', 'A', 'Z', 'z', 'v');
|
||||
|
||||
$format = $options['date_format'];
|
||||
foreach (str_split($format) as $splitted) {
|
||||
if ((!in_array($splitted, $test)) and (ctype_alpha($splitted))) {
|
||||
require_once 'Zend/Locale/Exception.php';
|
||||
throw new Zend_Locale_Exception("Unable to parse the date format string '" . $format
|
||||
. "' at letter '$splitted'");
|
||||
}
|
||||
}
|
||||
$number = $date; // working copy
|
||||
$result['date_format'] = $format; // save the format used to normalize $number (convenience)
|
||||
$result['locale'] = $options['locale']; // save the locale used to normalize $number (convenience)
|
||||
@ -721,7 +731,7 @@ class Zend_Locale_Format
|
||||
|
||||
if (empty($parse)) {
|
||||
require_once 'Zend/Locale/Exception.php';
|
||||
throw new Zend_Locale_Exception("unknown date format, neither date nor time in '" . $format . "' found");
|
||||
throw new Zend_Locale_Exception("Unknown date format, neither date nor time in '" . $format . "' found");
|
||||
}
|
||||
ksort($parse);
|
||||
|
||||
@ -777,6 +787,7 @@ class Zend_Locale_Format
|
||||
|| (iconv_substr($format, $year, 4) == 'YYYY')) {
|
||||
$length = 4;
|
||||
}
|
||||
|
||||
if ($split === false) {
|
||||
if (count($splitted[0]) > $cnt) {
|
||||
$result['year'] = $splitted[0][$cnt];
|
||||
@ -785,6 +796,7 @@ class Zend_Locale_Format
|
||||
$result['year'] = iconv_substr($splitted[0][0], $split, $length);
|
||||
$split += $length;
|
||||
}
|
||||
|
||||
++$cnt;
|
||||
break;
|
||||
case 'H':
|
||||
@ -843,7 +855,7 @@ class Zend_Locale_Format
|
||||
(isset($result['year']) and (iconv_strpos($date, $result['year']) === false)))) {
|
||||
if ($options['fix_date'] !== true) {
|
||||
require_once 'Zend/Locale/Exception.php';
|
||||
throw new Zend_Locale_Exception("unable to parse date '$date' using '" . $format
|
||||
throw new Zend_Locale_Exception("Unable to parse date '$date' using '" . $format
|
||||
. "' (false month, $position, $month)");
|
||||
}
|
||||
$temp = $result['day'];
|
||||
@ -858,7 +870,7 @@ class Zend_Locale_Format
|
||||
if ($result['day'] > 31) {
|
||||
if ($options['fix_date'] !== true) {
|
||||
require_once 'Zend/Locale/Exception.php';
|
||||
throw new Zend_Locale_Exception("unable to parse date '$date' using '"
|
||||
throw new Zend_Locale_Exception("Unable to parse date '$date' using '"
|
||||
. $format . "' (d <> y)");
|
||||
}
|
||||
$temp = $result['year'];
|
||||
@ -873,7 +885,7 @@ class Zend_Locale_Format
|
||||
if ($result['month'] > 31) {
|
||||
if ($options['fix_date'] !== true) {
|
||||
require_once 'Zend/Locale/Exception.php';
|
||||
throw new Zend_Locale_Exception("unable to parse date '$date' using '"
|
||||
throw new Zend_Locale_Exception("Unable to parse date '$date' using '"
|
||||
. $format . "' (M <> y)");
|
||||
}
|
||||
$temp = $result['year'];
|
||||
@ -888,7 +900,7 @@ class Zend_Locale_Format
|
||||
if ($result['month'] > 12) {
|
||||
if ($options['fix_date'] !== true || $result['month'] > 31) {
|
||||
require_once 'Zend/Locale/Exception.php';
|
||||
throw new Zend_Locale_Exception("unable to parse date '$date' using '"
|
||||
throw new Zend_Locale_Exception("Unable to parse date '$date' using '"
|
||||
. $format . "' (M <> d)");
|
||||
}
|
||||
$temp = $result['day'];
|
||||
@ -898,6 +910,21 @@ class Zend_Locale_Format
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($result['year'])) {
|
||||
if (((iconv_strlen($result['year']) == 2) && ($result['year'] < 10)) ||
|
||||
(((iconv_strpos($format, 'yy') !== false) && (iconv_strpos($format, 'yyyy') === false)) ||
|
||||
((iconv_strpos($format, 'YY') !== false) && (iconv_strpos($format, 'YYYY') === false)))) {
|
||||
if (($result['year'] >= 0) && ($result['year'] < 100)) {
|
||||
if ($result['year'] < 70) {
|
||||
$result['year'] = (int) $result['year'] + 100;
|
||||
}
|
||||
|
||||
$result['year'] = (int) $result['year'] + 1900;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -969,7 +996,7 @@ class Zend_Locale_Format
|
||||
|
||||
/**
|
||||
* Returns if the given datestring contains all date parts from the given format.
|
||||
* If no format is given, the standard date format from the locale is used
|
||||
* If no format is given, the default date format from the locale is used
|
||||
* If you want to check if the date is a proper date you should use Zend_Date::isDate()
|
||||
*
|
||||
* @param string $date Date string
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Locale
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Math.php 8584 2008-03-06 18:36:46Z thomas $
|
||||
* @version $Id: Math.php 14041 2009-02-10 21:49:38Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -37,14 +37,14 @@ class Zend_Locale_Math
|
||||
// support unit testing without using bcmath functions
|
||||
public static $_bcmathDisabled = false;
|
||||
|
||||
public static $add = 'bcadd';
|
||||
public static $sub = 'bcsub';
|
||||
public static $pow = 'bcpow';
|
||||
public static $mul = 'bcmul';
|
||||
public static $div = 'bcdiv';
|
||||
public static $comp = 'bccomp';
|
||||
public static $sqrt = 'bcsqrt';
|
||||
public static $mod = 'bcmod';
|
||||
public static $add = array('Zend_Locale_Math', 'Add');
|
||||
public static $sub = array('Zend_Locale_Math', 'Sub');
|
||||
public static $pow = array('Zend_Locale_Math', 'Pow');
|
||||
public static $mul = array('Zend_Locale_Math', 'Mul');
|
||||
public static $div = array('Zend_Locale_Math', 'Div');
|
||||
public static $comp = array('Zend_Locale_Math', 'Comp');
|
||||
public static $sqrt = array('Zend_Locale_Math', 'Sqrt');
|
||||
public static $mod = array('Zend_Locale_Math', 'Mod');
|
||||
public static $scale = 'bcscale';
|
||||
|
||||
public static function isBcmathDisabled()
|
||||
@ -127,6 +127,7 @@ class Zend_Locale_Math
|
||||
$value = str_replace($convert['negative_sign'], "", $value);
|
||||
$value = "-" . $value;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
@ -146,9 +147,153 @@ class Zend_Locale_Math
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes exponential numbers to plain string numbers
|
||||
* Fixes a problem of BCMath with numbers containing exponents
|
||||
*
|
||||
* @param integer $value Value to erase the exponent
|
||||
* @param integer $scale (Optional) Scale to use
|
||||
* @return string
|
||||
*/
|
||||
public static function exponent($value, $scale = null)
|
||||
{
|
||||
if (!extension_loaded('bcmath')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$split = explode('e', $value);
|
||||
if (count($split) == 1) {
|
||||
$split = explode('E', $value);
|
||||
}
|
||||
|
||||
if (count($split) > 1) {
|
||||
$value = bcmul($split[0], bcpow(10, $split[1], $scale), $scale);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* BCAdd - fixes a problem of BCMath and exponential numbers
|
||||
*
|
||||
* @param string $op1
|
||||
* @param string $op2
|
||||
* @param integer $scale
|
||||
* @return string
|
||||
*/
|
||||
public static function Add($op1, $op2, $scale = null)
|
||||
{
|
||||
$op1 = self::exponent($op1, $scale);
|
||||
$op2 = self::exponent($op2, $scale);
|
||||
return bcadd($op1, $op2, $scale);
|
||||
}
|
||||
|
||||
/**
|
||||
* BCSub - fixes a problem of BCMath and exponential numbers
|
||||
*
|
||||
* @param string $op1
|
||||
* @param string $op2
|
||||
* @param integer $scale
|
||||
* @return string
|
||||
*/
|
||||
public static function Sub($op1, $op2, $scale = null)
|
||||
{
|
||||
$op1 = self::exponent($op1, $scale);
|
||||
$op2 = self::exponent($op2, $scale);
|
||||
return bcsub($op1, $op2, $scale);
|
||||
}
|
||||
|
||||
/**
|
||||
* BCPow - fixes a problem of BCMath and exponential numbers
|
||||
*
|
||||
* @param string $op1
|
||||
* @param string $op2
|
||||
* @param integer $scale
|
||||
* @return string
|
||||
*/
|
||||
public static function Pow($op1, $op2, $scale = null)
|
||||
{
|
||||
$op1 = self::exponent($op1, $scale);
|
||||
$op2 = self::exponent($op2, $scale);
|
||||
return bcpow($op1, $op2, $scale);
|
||||
}
|
||||
|
||||
/**
|
||||
* BCMul - fixes a problem of BCMath and exponential numbers
|
||||
*
|
||||
* @param string $op1
|
||||
* @param string $op2
|
||||
* @param integer $scale
|
||||
* @return string
|
||||
*/
|
||||
public static function Mul($op1, $op2, $scale = null)
|
||||
{
|
||||
$op1 = self::exponent($op1, $scale);
|
||||
$op2 = self::exponent($op2, $scale);
|
||||
return bcmul($op1, $op2, $scale);
|
||||
}
|
||||
|
||||
/**
|
||||
* BCDiv - fixes a problem of BCMath and exponential numbers
|
||||
*
|
||||
* @param string $op1
|
||||
* @param string $op2
|
||||
* @param integer $scale
|
||||
* @return string
|
||||
*/
|
||||
public static function Div($op1, $op2, $scale = null)
|
||||
{
|
||||
$op1 = self::exponent($op1, $scale);
|
||||
$op2 = self::exponent($op2, $scale);
|
||||
return bcdiv($op1, $op2, $scale);
|
||||
}
|
||||
|
||||
/**
|
||||
* BCSqrt - fixes a problem of BCMath and exponential numbers
|
||||
*
|
||||
* @param string $op1
|
||||
* @param integer $scale
|
||||
* @return string
|
||||
*/
|
||||
public static function Sqrt($op1, $scale = null)
|
||||
{
|
||||
$op1 = self::exponent($op1, $scale);
|
||||
return bcsqrt($op1, $scale);
|
||||
}
|
||||
|
||||
/**
|
||||
* BCMod - fixes a problem of BCMath and exponential numbers
|
||||
*
|
||||
* @param string $op1
|
||||
* @param string $op2
|
||||
* @return string
|
||||
*/
|
||||
public static function Mod($op1, $op2)
|
||||
{
|
||||
$op1 = self::exponent($op1);
|
||||
$op2 = self::exponent($op2);
|
||||
return bcmod($op1, $op2);
|
||||
}
|
||||
|
||||
/**
|
||||
* BCComp - fixes a problem of BCMath and exponential numbers
|
||||
*
|
||||
* @param string $op1
|
||||
* @param string $op2
|
||||
* @param integer $scale
|
||||
* @return string
|
||||
*/
|
||||
public static function Comp($op1, $op2, $scale = null)
|
||||
{
|
||||
$op1 = self::exponent($op1, $scale);
|
||||
$op2 = self::exponent($op2, $scale);
|
||||
return bccomp($op1, $op2, $scale);
|
||||
}
|
||||
}
|
||||
|
||||
if ((defined('TESTS_ZEND_LOCALE_BCMATH_ENABLED') && !TESTS_ZEND_LOCALE_BCMATH_ENABLED)
|
||||
|| !extension_loaded('bcmath')) {
|
||||
require_once 'Zend/Locale/Math/PhpMath.php';
|
||||
Zend_Locale_Math_PhpMath::disable();
|
||||
}
|
||||
|
Reference in New Issue
Block a user