فهرست منبع

[ZF-7864] Zend_Currency:

- added new feature to automatically detect the wished display type at output


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18432 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 سال پیش
والد
کامیت
e5b6e9e0ce
2فایلهای تغییر یافته به همراه13 افزوده شده و 3 حذف شده
  1. 11 1
      library/Zend/Currency.php
  2. 2 2
      tests/Zend/CurrencyTest.php

+ 11 - 1
library/Zend/Currency.php

@@ -133,6 +133,16 @@ class Zend_Currency
             throw new Zend_Currency_Exception("Value '$value' has to be numeric");
         }
 
+        if (!isset($options['display'])) {
+            if (isset($options['symbol'])) {
+                $options['display'] = Zend_Currency::USE_SYMBOL;
+            } else if (isset($options['currency'])) {
+                $options['display'] = Zend_Currency::USE_SHORTNAME;
+            } else if (isset($options['name'])) {
+                $options['display'] = Zend_Currency::USE_NAME;
+            }
+        }
+
         $options = $this->_checkOptions($options) + $this->_options;
 
         // Format the number
@@ -149,7 +159,7 @@ class Zend_Currency
         $original = $value;
         $value    = Zend_Locale_Format::toNumber($value, array('locale'        => $locale,
                                                                'number_format' => $format,
-                                                              'precision'     => $options['precision']));
+                                                               'precision'     => $options['precision']));
 
         if ($options['position'] !== self::STANDARD) {
             $value = str_replace('¤', '', $value);

+ 2 - 2
tests/Zend/CurrencyTest.php

@@ -288,12 +288,12 @@ class Zend_CurrencyTest extends PHPUnit_Framework_TestCase
         $USD = new Zend_Currency('USD','en_US');
         $EGP = new Zend_Currency('EGP','ar_EG');
 
-        $this->assertSame('$53,292.18', $USD->toCurrency(53292.18                            ));
+        $this->assertSame('$53,292.18', $USD->toCurrency(53292.18));
         $this->assertSame('$٥٣,٢٩٢.١٨', $USD->toCurrency(53292.18, array('script' => 'Arab' )));
         $this->assertSame('$ ٥٣.٢٩٢,١٨', $USD->toCurrency(53292.18, array('script' => 'Arab', 'format' => 'de_AT')));
         $this->assertSame('$ 53.292,18', $USD->toCurrency(53292.18, array('format' => 'de_AT')));
 
-        $this->assertSame('ج.م.‏ 53٬292٫18', $EGP->toCurrency(53292.18                            ));
+        $this->assertSame('ج.م.‏ 53.292,18', $EGP->toCurrency(53292.18));
         $this->assertSame('ج.م.‏ ٥٣٬٢٩٢٫١٨', $EGP->toCurrency(53292.18, array('script' => 'Arab' )));
         $this->assertSame('ج.م.‏ ٥٣.٢٩٢,١٨', $EGP->toCurrency(53292.18, array('script' =>'Arab', 'format' => 'de_AT')));
         $this->assertSame('ج.م.‏ 53.292,18', $EGP->toCurrency(53292.18, array('format' => 'de_AT')));