public function CurrencySymbol()
 {
     require_once THIRDPARTY_PATH . "/Zend/Currency.php";
     $locale = new Zend_Locale(i18n::get_locale());
     $symbol = new Zend_Currency($locale);
     return $symbol->getSymbol();
 }
示例#2
0
文件: Money.php 项目: redema/sapphire
	/**
	 * @return string
	 */
	function getSymbol($currency = null, $locale = null) {
		
		if($locale === null) $locale = $this->getLocale();
		if($currency === null) $currency = $this->getCurrency();
		
		return $this->currencyLib->getSymbol($currency, $locale);
	}
示例#3
0
 public function getDefaultCurrencySymbol()
 {
     $current_locale = I18n::getCurrentLangCode();
     require_once 'Zend/Currency.php';
     $current_currency = DEFAULT_CURRENCY;
     if (!$current_currency) {
         $current_currency = "USD";
     }
     $currency = new Zend_Currency($current_currency, $current_locale);
     $currency->getSymbol($current_currency, $current_locale);
     return $display_name;
 }
 /**
  * returns the value formatet in the current locales currency format
  * 
  * @return string
  */
 public function Currency($symbol = false)
 {
     require_once THIRDPARTY_PATH . "/Zend/Locale/Format.php";
     require_once THIRDPARTY_PATH . "/Zend/Currency.php";
     if ($this->owner->value) {
         $locale = new Zend_Locale(i18n::get_locale());
         $number = Zend_Locale_Format::toNumber($this->owner->value, array('locale' => $locale));
         if ($symbol) {
             $symbol = new Zend_Currency($locale);
             $number = $symbol->getSymbol() . " " . $number;
         }
         return $number;
     }
 }
示例#5
0
 /**
  * Parses a Zend_Currency & Zend_Locale into a NostoCurrency object.
  *
  * REQUIRES Zend Framework (version 1) to be available.
  *
  * @param string $currencyCode the 3-letter ISO 4217 currency code.
  * @param Zend_Currency $zendCurrency the zend currency object.
  * @return NostoCurrency the parsed nosto currency object.
  *
  * @throws NostoInvalidArgumentException
  */
 public function parseZendCurrencyFormat($currencyCode, Zend_Currency $zendCurrency)
 {
     try {
         $format = Zend_Locale_Data::getContent($zendCurrency->getLocale(), 'currencynumber');
         $symbols = Zend_Locale_Data::getList($zendCurrency->getLocale(), 'symbols');
         // Remove extra part, e.g. "¤ #,##0.00; (¤ #,##0.00)" => "¤ #,##0.00".
         if (($pos = strpos($format, ';')) !== false) {
             $format = substr($format, 0, $pos);
         }
         // Check if the currency symbol is before or after the amount.
         $symbolPosition = strpos(trim($format), '¤') === 0 ? NostoCurrencySymbol::SYMBOL_POS_LEFT : NostoCurrencySymbol::SYMBOL_POS_RIGHT;
         // Remove all other characters than "0", "#", "." and ",",
         $format = preg_replace('/[^0\\#\\.,]/', '', $format);
         // Calculate the decimal precision.
         $precision = 0;
         if (($decimalPos = strpos($format, '.')) !== false) {
             $precision = strlen($format) - (strrpos($format, '.') + 1);
         } else {
             $decimalPos = strlen($format);
         }
         $decimalFormat = substr($format, $decimalPos);
         if (($pos = strpos($decimalFormat, '#')) !== false) {
             $precision = strlen($decimalFormat) - $pos - $precision;
         }
         // Calculate the group length.
         if (strrpos($format, ',') !== false) {
             $groupLength = $decimalPos - strrpos($format, ',') - 1;
         } else {
             $groupLength = strrpos($format, '.');
         }
         // If the symbol is missing for the current locale, use the ISO code.
         $currencySymbol = $zendCurrency->getSymbol();
         if (is_null($currencySymbol)) {
             $currencySymbol = $currencyCode;
         }
         return new NostoCurrency(new NostoCurrencyCode($currencyCode), new NostoCurrencySymbol($currencySymbol, $symbolPosition), new NostoCurrencyFormat($symbols['group'], $groupLength, $symbols['decimal'], $precision));
     } catch (Zend_Exception $e) {
         throw new NostoInvalidArgumentException($e);
     }
 }
示例#6
0
 /**
  * test getSign
  */
 public function testGetSign()
 {
     $locale = new Zend_Locale('ar_EG');
     $currency = new Zend_Currency('ar_EG');
     $this->assertSame('ج.م.‏', $currency->getSymbol('EGP', 'ar_EG'));
     $this->assertSame('€', $currency->getSymbol('EUR', 'de_AT'));
     $this->assertSame('ج.م.‏', $currency->getSymbol('ar_EG'));
     $this->assertSame('€', $currency->getSymbol('de_AT'));
     $this->assertSame('ج.م.‏', $currency->getSymbol());
     try {
         $currency->getSymbol('EGP', 'de_XX');
         $this->fail("exception expected");
     } catch (Zend_Currency_Exception $e) {
         // success
     }
 }
示例#7
0
 /**
  * test getSign
  */
 public function testGetSign()
 {
     $this->assertSame(Zend_Currency::getSymbol('EGP', 'ar_EG'), 'ج.م.‏');
     $this->assertSame(Zend_Currency::getSymbol('ar_EG'), 'ج.م.‏');
 }
示例#8
0
 public static function getCountriesList()
 {
     if (is_null(self::$_countries_list)) {
         self::$_countries_list = array();
         $locale = Zend_Registry::get('Zend_Locale');
         $currency = new Zend_Currency();
         foreach (Zend_Locale::getTranslationList('Territory', null, 2) as $ter => $name) {
             $country_code = Zend_Locale::getLocaleToTerritory($ter);
             if (!is_null($country_code)) {
                 try {
                     $symbol = $currency->getSymbol($country_code);
                     if (!empty($symbol)) {
                         $countries[$country_code] = array('code' => $country_code, 'name' => $name, 'symbol' => $symbol);
                     }
                 } catch (Exception $e) {
                 }
             }
         }
         uasort($countries, 'cmp');
         foreach ($countries as $currency) {
             self::$_countries_list[] = new Core_Model_Default($currency);
         }
     }
     return self::$_countries_list;
 }
示例#9
0
    /**
     * test getSign
     */
    public function testGetSign()
    {
        $locale = new Zend_Locale('ar_EG');

        $this->assertSame(Zend_Currency::getSymbol('EGP','ar_EG'), 'ج.م.‏');
        $this->assertSame(Zend_Currency::getSymbol('ar_EG'), 'ج.م.‏');
        $this->assertSame(Zend_Currency::getSymbol('ar_EG'), 'ج.م.‏');
        try {
            $this->assertSame(is_string(Zend_Currency::getSymbol('EGP')), true);
        } catch (Zend_Currency_Exception $e) {
            // Systems without locale are expected to be ok from the testbed
            $this->assertSame($e->getMessage(), "Locale 'root' is no valid locale");
        }

        try {
            Zend_Currency::getSymbol('EGP', 'de_XX');
            $this->fail();
        } catch (Zend_Currency_Exception $e) {
            // success
        }
    }
示例#10
0
 /**
  * Returns the configured default currency symbol.
  *
  * @return string
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 25.10.2013
  */
 public static function DefaultCurrencySymbol()
 {
     if (is_null(self::$defaultCurrencySymbol)) {
         $zend_currency = new Zend_Currency(null, i18n::default_locale());
         self::$defaultCurrencySymbol = $zend_currency->getSymbol(self::DefaultCurrency(), i18n::get_locale());
     }
     return self::$defaultCurrencySymbol;
 }