import v1.1.0_beta1 | 2009-08-21

This commit is contained in:
2019-07-17 22:16:19 +02:00
parent 2c1152f0d3
commit 8dee6b1a10
2306 changed files with 251360 additions and 23428 deletions

View File

@ -96,13 +96,6 @@ class Zend_Currency
$currency = $temp;
}
if (empty($locale)) {
require_once 'Zend/Registry.php';
if (Zend_Registry::isRegistered('Zend_Locale') === true) {
$locale = Zend_Registry::get('Zend_Locale');
}
}
$this->setLocale($locale);
// Get currency details
@ -116,7 +109,6 @@ class Zend_Currency
}
// Get the format
$this->_options['position'] = $this->_updateFormat();
$this->_options['display'] = self::NO_SYMBOL;
if (empty($this->_options['symbol']) === false) {
$this->_options['display'] = self::USE_SYMBOL;
@ -125,33 +117,6 @@ class Zend_Currency
}
}
/**
* Gets the information required for formating the currency from Zend_Locale
*
* @return Zend_Currency
*/
protected function _updateFormat()
{
$locale = (empty($this->_options['format']) === true) ? $this->_locale : $this->_options['format'];
// Getting the format information of the currency
$format = Zend_Locale_Data::getContent($locale, 'currencynumber');
iconv_set_encoding('internal_encoding', 'UTF-8');
if (iconv_strpos($format, ';') !== false) {
$format = iconv_substr($format, 0, iconv_strpos($format, ';'));
}
// Knowing the sign positioning information
if (iconv_strpos($format, '¤') === 0) {
$position = self::LEFT;
} else if (iconv_strpos($format, '¤') === (iconv_strlen($format) - 1)) {
$position = self::RIGHT;
}
return $position;
}
/**
* Returns a localized currency string
*
@ -171,12 +136,35 @@ class Zend_Currency
$options = $this->_checkOptions($options) + $this->_options;
// Format the number
if (empty($options['format']) === true) {
$options['format'] = $this->_locale;
$format = $options['format'];
$locale = $this->_locale;
if (empty($format) === true) {
$format = Zend_Locale_Data::getContent($this->_locale, 'currencynumber');
} else if (Zend_Locale::isLocale($format, true, false)) {
$locale = $format;
$format = Zend_Locale_Data::getContent($format, 'currencynumber');
}
$value = Zend_Locale_Format::toNumber($value, array('locale' => $options['format'],
'precision' => $options['precision']));
$symbols = Zend_Locale_Data::getList($locale, 'symbols');
$original = $value;
$value = Zend_Locale_Format::toNumber($value, array('locale' => $locale,
'number_format' => $format,
'precision' => $options['precision']));
if ($options['position'] !== self::STANDARD) {
$value = str_replace('¤', '', $value);
$space = '';
if (iconv_strpos($value, ' ') !== false) {
$value = str_replace(' ', '', $value);
$space = ' ';
}
if ($options['position'] == self::LEFT) {
$value = '¤' . $space . $value;
} else {
$value = $value . $space . '¤';
}
}
// Localize the number digits
if (empty($options['script']) === false) {
@ -185,35 +173,68 @@ class Zend_Currency
// Get the sign to be placed next to the number
if (is_numeric($options['display']) === false) {
$sign = ' ' . $options['display'] . ' ';
$sign = $options['display'];
} else {
switch($options['display']) {
case self::USE_SYMBOL:
$sign = ' ' . $options['symbol'] . ' ';
$sign = $this->_extractPattern($options['symbol'], $original);
break;
case self::USE_SHORTNAME:
$sign = ' ' . $options['currency'] . ' ';
$sign = $options['currency'];
break;
case self::USE_NAME:
$sign = ' ' . $options['name'] . ' ';
$sign = $options['name'];
break;
default:
$sign = '';
$value = str_replace(' ', '', $value);
break;
}
}
// Place the sign next to the number
if ($options['position'] === self::RIGHT) {
$value = $value . $sign;
} else if ($options['position'] === self::LEFT) {
$value = $sign . $value;
$value = str_replace('¤', $sign, $value);
return $value;
}
/**
* Internal method to extract the currency pattern
* when a choice is given based on the given value
*
* @param string $pattern
* @param float|integer $value
* @return string
*/
private function _extractPattern($pattern, $value)
{
if (strpos($pattern, '|') === false) {
return $pattern;
}
return trim($value);
$patterns = explode('|', $pattern);
$token = $pattern;
$value = trim(str_replace('¤', '', $value));
krsort($patterns);
foreach($patterns as $content) {
if (strpos($content, '<') !== false) {
$check = iconv_substr($content, 0, iconv_strpos($content, '<'));
$token = iconv_substr($content, iconv_strpos($content, '<') + 1);
if ($check < $value) {
return $token;
}
} else {
$check = iconv_substr($content, 0, iconv_strpos($content, '≤'));
$token = iconv_substr($content, iconv_strpos($content, '≤') + 1);
if ($check <= $value) {
return $token;
}
}
}
return $token;
}
/**
@ -485,17 +506,14 @@ class Zend_Currency
*/
public function setLocale($locale = null)
{
if (!Zend_Locale::isLocale($locale, false, false)) {
if (!Zend_Locale::isLocale($locale, true, false)) {
require_once 'Zend/Currency/Exception.php';
throw new Zend_Currency_Exception("Given locale (" . (string) $locale . ") does not exist");
} else {
$locale = new Zend_Locale();
}
require_once 'Zend/Locale.php';
try {
$this->_locale = Zend_Locale::findLocale($locale);
} catch (Zend_Locale_Exception $e) {
require_once 'Zend/Currency/Exception.php';
throw new Zend_Currency_Exception($e->getMessage());
}
$this->_locale = (string) $locale;
// Get currency details
$this->_options['currency'] = $this->getShortName(null, $this->_locale);
$this->_options['name'] = $this->getName(null, $this->_locale);
@ -547,9 +565,6 @@ class Zend_Currency
throw new Zend_Currency_Exception("Unknown position '" . $value . "'");
}
if ($value === self::STANDARD) {
$options['position'] = $this->_updateFormat();
}
break;
case 'format':