本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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());
}
示例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);
}
示例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();
}
示例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;
}
示例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);
}
示例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());
}
示例13: testGetters
public function testGetters()
{
$m = new Money(100, $euro = new Currency('EUR'));
$this->assertEquals(100, $m->getAmount());
$this->assertEquals($euro, $m->getCurrency());
}
示例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();
}
示例15: formatMoney
/**
* @param Money $money
* @return string
*/
public function formatMoney(Money $money)
{
return "\${$this->formatMoneyAmount(round($money->getAmount() / 100, 2))} {$money->getCurrency()}";
}