当前位置: 首页>>代码示例>>PHP>>正文


PHP Currency::getCode方法代码示例

本文整理汇总了PHP中Currency::getCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Currency::getCode方法的具体用法?PHP Currency::getCode怎么用?PHP Currency::getCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Currency的用法示例。


在下文中一共展示了Currency::getCode方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getConversionMultiplier

 /**
  * @param Currency $from
  * @param Currency $to
  * @return string
  * @throws \RuntimeException
  */
 public function getConversionMultiplier(Currency $from, Currency $to)
 {
     $rates = $this->getConversionRatesTable($from);
     if (!isset($rates[$to->getCode()])) {
         throw new \RuntimeException(sprintf('The target currency "%s" is not present in the conversion rates table.', $to->getCode()));
     }
     return $rates[$to->getCode()];
 }
开发者ID:superbalist,项目名称:php-money,代码行数:14,代码来源:BaseCurrencyConversionService.php

示例2: contains

 /**
  * {@inheritdoc}
  */
 public function contains(Currency $currency)
 {
     if (null === self::$currencies) {
         self::$currencies = $this->requireCurrencies();
     }
     return array_key_exists($currency->getCode(), self::$currencies);
 }
开发者ID:barryvdh,项目名称:money,代码行数:10,代码来源:ISOCurrencies.php

示例3: edit

 /**
  * Update existing route
  *
  * @param void
  * @return null
  */
 function edit()
 {
     if ($this->active_currency->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $currency_data = $this->request->post('currency');
     if (!is_array($currency_data)) {
         $currency_data = array('name' => $this->active_currency->getName(), 'code' => $this->active_currency->getCode(), 'default_rate' => $this->active_currency->getDefaultRate());
     }
     // if
     $this->smarty->assign('currency_data', $currency_data);
     if ($this->request->isSubmitted()) {
         $this->active_currency->setAttributes($currency_data);
         $save = $this->active_currency->save();
         if ($save && !is_error($save)) {
             flash_success('Currency ":name" has been updated', array('name' => $this->active_currency->getName()));
             $this->redirectTo('admin_currencies');
         } else {
             $this->smarty->assign('errors', $save);
         }
         // if
     }
     // if
 }
开发者ID:NaszvadiG,项目名称:activecollab_loc,代码行数:31,代码来源:CurrenciesAdminController.class.php

示例4: getConversionRatesTable

 /**
  * @param Currency $currency
  * @return array
  */
 public function getConversionRatesTable(Currency $currency)
 {
     switch ($currency->getCode()) {
         case 'USD':
             return array('USD' => '1', 'ZAR' => '12.07682');
         default:
             // ZAR
             return array('USD' => '0.082776', 'ZAR' => '1');
     }
 }
开发者ID:superbalist,项目名称:php-money,代码行数:14,代码来源:MockCurrencyConversionService.php

示例5: compare

 /**
  * @param Money|string|int|float $money
  * @return int
  * @throws CurrencyMismatchException
  */
 public function compare($money)
 {
     if ($money instanceof Money) {
         if (!$this->isSameCurrencyAs($money)) {
             throw new CurrencyMismatchException(sprintf('The monetary values being compared must be of the same currency (%s !== %s).', $this->currency->getCode(), $money->getCurrency()->getCode()));
         }
     }
     $amount = Utils::toStringAmount($money);
     return bccomp($this->amount, $amount, $this->scaleFactor);
 }
开发者ID:superbalist,项目名称:php-money,代码行数:15,代码来源:Money.php

示例6: getConversionRatesTable

 /**
  * @param Currency $currency
  * @return array
  * @throws \RuntimeException
  */
 public function getConversionRatesTable(Currency $currency)
 {
     $ch = curl_init();
     $url = sprintf('http://openexchangerates.org/api/latest.json?app_id=%s', $this->appId);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $response = curl_exec($ch);
     if ($response === false) {
         throw new \RuntimeException(sprintf('An error occurred querying %s for conversion rates - (%s - %d)', $url, curl_error($ch), curl_errno($ch)));
     }
     $result = json_decode($response, true);
     if (is_array($result) && isset($result['rates'])) {
         $rates = $result['rates'];
         // the free plan only supports a base currency of 'usd'
         // we therefore need to convert the table to our own base currency
         // first, our own base must be present in the conversion table
         if (!isset($rates[$currency->getCode()])) {
             return array();
             // nothing more to do
         }
         $usd2base = (string) $rates[$currency->getCode()];
         $table = array();
         foreach ($rates as $code => $rate) {
             if ($code === 'USD') {
                 $table[$code] = '1';
             } else {
                 $rate = (string) $rate;
                 $multiplier = bcdiv('1', $usd2base, 6);
                 $table[$code] = bcmul($rate, $multiplier, 6);
             }
         }
         return $table;
     } else {
         return array();
         // response isn't what we expected / missing rates
     }
 }
开发者ID:superbalist,项目名称:php-money,代码行数:42,代码来源:OpenExchangeRatesCurrencyConversionService.php

示例7: testConstruct

 /**
  * @depends testSetCode
  * @depends testSetCodeWithExceptionThrown
  */
 public function testConstruct()
 {
     $currency = new Currency('usd');
     $this->assertSame('USD', $currency->getCode());
 }
开发者ID:Invision70,项目名称:php-bitpay-client,代码行数:9,代码来源:CurrencyTest.php

示例8: getRateFromXML

 public function getRateFromXML(Currency $from, Currency $to, SimpleXMLElement $xml)
 {
     $item = $xml->xpath('/rss/channel/item[title="' . $to->getCode() . '/' . $from->getCode() . '"]');
     $item = is_array($item) ? current($item) : false;
     if ($item instanceof SimpleXMLElement) {
         preg_match('/= ([0-9]+\\.?[0-9]*) /', $item->description, $matches);
     }
     return isset($matches[1]) ? $matches[1] : false;
 }
开发者ID:asaraf28,项目名称:CurrencyConverter,代码行数:9,代码来源:actions.class.php

示例9: compareCurrency

 /**
  * @param Money $otherMoney
  *
  * @throws CurrencyMismatchException
  */
 private function compareCurrency(Money $otherMoney)
 {
     if ($this->currency->compareTo($otherMoney->getCurrency()) !== 0) {
         throw CurrencyMismatchException::currenciesNotMatching($this->currency->getCode(), $otherMoney->getCurrency()->getCode());
     }
 }
开发者ID:jonasdekeukelaere,项目名称:money,代码行数:11,代码来源:Money.php

示例10: equals

 /**
  * Whether this and another currency are the same. Uses only the code to determine identity.
  *
  * @param Currency $currency the currency to compare to
  *
  * @return boolean true if the currency codes match, false otherwise
  */
 public function equals(Currency $currency)
 {
     return $this->code == $currency->getCode();
 }
开发者ID:Junyue,项目名称:zidisha2,代码行数:11,代码来源:Currency.php

示例11: findOneByFromCodeAndToCode

 public function findOneByFromCodeAndToCode(Currency $from, Currency $to)
 {
     return Doctrine_Query::create()->from('CurrencyRate')->where('from_code = ?', $from->getCode())->andWhere('to_code = ?', $to->getCode())->fetchOne();
 }
开发者ID:asaraf28,项目名称:CurrencyConverter,代码行数:4,代码来源:CurrencyRateTable.class.php

示例12: compareTo

 /**
  * @param Currency $otherCurrency
  *
  * @return int
  */
 public function compareTo(Currency $otherCurrency)
 {
     return strcmp($this->code, $otherCurrency->getCode());
 }
开发者ID:jonasdekeukelaere,项目名称:money,代码行数:9,代码来源:Currency.php

示例13: isEqualTo

 /**
  * @param Currency $currency
  *
  * @return bool
  */
 public function isEqualTo(Currency $currency)
 {
     return $this->getCode() === $currency->getCode();
 }
开发者ID:ndeg,项目名称:monoid-poc,代码行数:9,代码来源:Currency.php

示例14: setCurrency

 /**
  * @param Currency $currency this field is required for partial refunds. 
  *      Do not use this field for full refunds.
  */
 public function setCurrency(Currency $currency)
 {
     $this->collection->setValue('CURRENCYCODE', $currency->getCode());
 }
开发者ID:rdeeb,项目名称:paypal,代码行数:8,代码来源:RefundTransaction.php


注:本文中的Currency::getCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。