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


PHP Money::getCurrency方法代码示例

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


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

示例1: convert

 public function convert(Money $money, $currency)
 {
     if (!$currency instanceof Currency) {
         $currency = new Currency($currency);
     }
     if ($money->getCurrency()->equals($currency)) {
         return $money;
     }
     $rates = $this->getRates($money->getCurrency());
     if (!isset($rates[$currency->getName()])) {
         throw new RuntimeException(sprintf('Could not get rate for currency %s', $currency->getName()));
     }
     $pair = new CurrencyPair($money->getCurrency(), $currency, $rates[$currency->getName()]);
     return $pair->convert($money);
 }
开发者ID:pekkis,项目名称:currency-converter,代码行数:15,代码来源:CurrencyConverter.php

示例2: getAmountInBaseUnits

 public function getAmountInBaseUnits(Money $money)
 {
     $iso = $this->iso4217->getByAlpha3($money->getCurrency()->getName());
     $decimals = $iso['exp'];
     $dividend = pow(10, $decimals);
     return $money->getAmount() / $dividend;
 }
开发者ID:jordicasadevall,项目名称:MoneyFormatter,代码行数:7,代码来源:MoneyFormatter.php

示例3: convert

 /**
  * @param \Money\Money $money
  * @param        $rounding_mode
  * @return \Money\Money
  * @expectedException InvalidArgumentException
  */
 public function convert(Money $money, RoundingMode $rounding_mode = null)
 {
     if (!$money->getCurrency()->equals($this->baseCurrency)) {
         throw new InvalidArgumentException("The Money has the wrong currency");
     }
     $rounding_mode = $rounding_mode ?: RoundingMode::halfUp();
     return new Money((int) round($money->getAmount() * $this->ratio, 0, $rounding_mode->getRoundingMode()), $this->counterCurrency);
 }
开发者ID:srtfisher,项目名称:money,代码行数:14,代码来源:CurrencyPair.php

示例4: convert

 public function convert(Money $money, $target)
 {
     if (!$target instanceof MoneyCurrency) {
         throw new InvalidArgumentException(sprintf('Second argument must be Currency, %s given.', gettype($target)));
     }
     $rate = $this->swap->quote(new CurrencyPair($money->getCurrency(), $target));
     return new Money($money->multiply((double) $rate->getValue())->getAmount(), $target);
 }
开发者ID:umpirsky,项目名称:locurro,代码行数:8,代码来源:Currency.php

示例5: testHydratorHydratesAsExpected

 public function testHydratorHydratesAsExpected()
 {
     $hydrator = new MoneyHydrator();
     $data = ['amount' => 500, 'currency' => 'BRL'];
     $money = new Money(500, new Currency('BRL'));
     $object = $hydrator->hydrate($data, new \stdClass());
     $this->assertEquals($money->getAmount(), $object->getAmount());
     $this->assertEquals($money->getCurrency(), $object->getCurrency());
 }
开发者ID:zfbrasil,项目名称:doctrine-money-module,代码行数:9,代码来源:MoneyHydratorTest.php

示例6: format

 /**
  * {@inheritdoc}
  */
 public function format(Money $money)
 {
     $currencyCode = $money->getCurrency()->getCode();
     if (isset($this->formatters[$currencyCode])) {
         return $this->formatters[$currencyCode]->format($money);
     }
     if (isset($this->formatters['*'])) {
         return $this->formatters['*']->format($money);
     }
     throw new FormatterException('No formatter found for currency ' . $currencyCode);
 }
开发者ID:squigg,项目名称:money,代码行数:14,代码来源:AggregateMoneyFormatter.php

示例7: format

 /**
  * {@inheritdoc}
  */
 public function format(Money $money)
 {
     $valueBase = (string) $money->getAmount();
     $negative = false;
     if ($valueBase[0] === '-') {
         $negative = true;
         $valueBase = substr($valueBase, 1);
     }
     $subunit = $this->currencies->subunitFor($money->getCurrency());
     $valueLength = strlen($valueBase);
     if ($valueLength > $subunit) {
         $formatted = substr($valueBase, 0, $valueLength - $subunit) . '.';
         $formatted .= substr($valueBase, $valueLength - $subunit);
     } else {
         $formatted = '0.' . str_pad('', $subunit - $valueLength, '0') . $valueBase;
     }
     if ($negative === true) {
         $formatted = '-' . $formatted;
     }
     return $this->formatter->formatCurrency($formatted, $money->getCurrency()->getCode());
 }
开发者ID:squigg,项目名称:money,代码行数:24,代码来源:IntlMoneyFormatter.php

示例8: Rate

 function it_converts_money_using_swap(SwapInterface $swap, Money $money, Money $converted, Currency $from, Currency $to)
 {
     $money->getAmount()->willReturn(100);
     $money->getCurrency()->willReturn($from);
     $money->multiply(120.3971)->willReturn($converted);
     $converted->getAmount()->willReturn(12039);
     $converted->getCurrency()->willReturn($to);
     $from->__toString()->willReturn('EUR');
     $to->__toString()->willReturn('RSD');
     $rate = new Rate(120.3971);
     $swap->quote('EUR/RSD')->shouldBeCalled()->willReturn($rate);
     $this->convert($money, $to)->getAmount()->shouldBe(12039);
 }
开发者ID:umpirsky,项目名称:locurro,代码行数:13,代码来源:CurrencySpec.php

示例9: __construct

 /**
  * Create a new Product
  *
  * @param string $sku
  * @param string $name
  * @param Money $price
  * @param TaxRate $rate
  * @return void
  */
 public function __construct($sku, $name, Money $price, TaxRate $rate)
 {
     $this->sku = $sku;
     $this->name = $name;
     $this->price = $price;
     $this->rate = $rate;
     $this->quantity = 1;
     $this->freebie = false;
     $this->taxable = true;
     $this->delivery = new Money(0, $price->getCurrency());
     $this->coupons = new Collection();
     $this->tags = new Collection();
 }
开发者ID:janusnic,项目名称:basket,代码行数:22,代码来源:Product.php

示例10: format

 /**
  * {@inheritdoc}
  */
 public function format(Money $money)
 {
     if (BitcoinCurrencies::CODE !== $money->getCurrency()->getCode()) {
         throw new FormatterException('Bitcoin Formatter can only format Bitcoin currency');
     }
     $valueBase = $money->getAmount();
     $negative = false;
     if ('-' === $valueBase[0]) {
         $negative = true;
         $valueBase = substr($valueBase, 1);
     }
     $subunit = $this->currencies->subunitFor($money->getCurrency());
     $valueBase = Number::roundMoneyValue($valueBase, $this->fractionDigits, $subunit);
     $valueLength = strlen($valueBase);
     if ($valueLength > $subunit) {
         $formatted = substr($valueBase, 0, $valueLength - $subunit);
         if ($subunit) {
             $formatted .= '.';
             $formatted .= substr($valueBase, $valueLength - $subunit);
         }
     } else {
         $formatted = '0.' . str_pad('', $subunit - $valueLength, '0') . $valueBase;
     }
     if ($this->fractionDigits === 0) {
         $formatted = substr($formatted, 0, strpos($formatted, '.'));
     } elseif ($this->fractionDigits > $subunit) {
         $formatted .= str_pad('', $this->fractionDigits - $subunit, '0');
     } elseif ($this->fractionDigits < $subunit) {
         $lastDigit = strpos($formatted, '.') + $this->fractionDigits + 1;
         $formatted = substr($formatted, 0, $lastDigit);
     }
     $formatted = BitcoinCurrencies::SYMBOL . $formatted;
     if (true === $negative) {
         $formatted = '-' . BitcoinCurrencies::SYMBOL . $formatted;
     }
     return $formatted;
 }
开发者ID:squigg,项目名称:money,代码行数:40,代码来源:BitcoinMoneyFormatter.php

示例11: testGetVarCleanVar

 /**
  * @covers Xoops\Core\Kernel\Dtype\DtypeMoney::getVar
  * @covers Xoops\Core\Kernel\Dtype\DtypeMoney::cleanVar
  */
 public function testGetVarCleanVar()
 {
     $testValue = new Money(10000, new Currency('USD'));
     $key = 'money_test';
     $this->xObject[$key] = $testValue;
     $this->xObject[$key] = $this->object->cleanVar($this->xObject, $key);
     $value = $this->xObject->getVar($key, Dtype::FORMAT_NONE);
     $this->assertInstanceOf('\\Money\\Money', $value);
     $this->assertEquals($testValue->getAmount(), $value->getAmount());
     $this->assertEquals($testValue->getCurrency(), $value->getCurrency());
     $this->assertNotSame($value, $testValue);
     $value2 = $this->xObject->getVar($key, Dtype::FORMAT_SHOW);
     $this->assertInstanceOf('\\Money\\Money', $value2);
     $this->assertEquals($testValue->getAmount(), $value2->getAmount());
     $this->assertEquals($testValue->getCurrency(), $value2->getCurrency());
     $this->assertNotSame($value, $value2);
 }
开发者ID:ming-hai,项目名称:XoopsCore,代码行数:21,代码来源:DtypeMoneyTest.php

示例12: format

 /**
  * {@inheritdoc}
  */
 public function format(Money $money)
 {
     $valueBase = (string) $money->getAmount();
     $negative = false;
     if (substr($valueBase, 0, 1) === '-') {
         $negative = true;
         $valueBase = substr($valueBase, 1);
     }
     $fractionDigits = $this->formatter->getAttribute(\NumberFormatter::FRACTION_DIGITS);
     $valueLength = strlen($valueBase);
     if ($valueLength > $fractionDigits) {
         $subunits = substr($valueBase, 0, $valueLength - $fractionDigits) . '.';
         $subunits .= substr($valueBase, $valueLength - $fractionDigits);
     } else {
         $subunits = '0.' . str_pad('', $fractionDigits - $valueLength, '0') . $valueBase;
     }
     if ($negative === true) {
         $subunits = '-' . $subunits;
     }
     return $this->formatter->formatCurrency($subunits, $money->getCurrency()->getCode());
 }
开发者ID:barryvdh,项目名称:money,代码行数:24,代码来源:IntlMoneyFormatter.php

示例13: testGetters

 public function testGetters()
 {
     $m = new Money(100, $euro = new Currency('EUR'));
     $this->assertEquals(100, $m->getAmount());
     $this->assertEquals($euro, $m->getCurrency());
 }
开发者ID:hemeragestao,项目名称:money,代码行数:6,代码来源:MoneyTest.php

示例14: serializeMoney

 /**
  * @param \JMS\Serializer\VisitorInterface $visitor
  * @param Money $money
  * @param mixed[] $type
  * @param \JMS\Serializer\Context $context
  * @return string
  */
 public function serializeMoney(VisitorInterface $visitor, Money $money, array $type, Context $context)
 {
     return (string) $money->getAmount() . ' ' . $money->getCurrency()->getName();
 }
开发者ID:hellofresh,项目名称:engine,代码行数:11,代码来源:MoneyHandler.php

示例15: formatMoney

 /**
  * @param Money $money
  * @return string
  */
 public function formatMoney(Money $money)
 {
     return "\${$this->formatMoneyAmount(round($money->getAmount() / 100, 2))} {$money->getCurrency()}";
 }
开发者ID:zoek1,项目名称:php-testing-tools,代码行数:8,代码来源:MemberFormatter.php


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