本文整理匯總了PHP中Money::getCurrency方法的典型用法代碼示例。如果您正苦於以下問題:PHP Money::getCurrency方法的具體用法?PHP Money::getCurrency怎麽用?PHP Money::getCurrency使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Money
的用法示例。
在下文中一共展示了Money::getCurrency方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: convert
/**
* Converts Money from base to counter currency.
*
* @param Money $money
* @param int $roundingMode
*
* @return Money
*
* @throws \InvalidArgumentException If $money's currency is not equal to base currency
*/
public function convert(Money $money, $roundingMode = Money::ROUND_HALF_UP)
{
if (!$money->getCurrency()->equals($this->baseCurrency)) {
throw new \InvalidArgumentException('The Money has the wrong currency');
}
return $money->convert($this->counterCurrency, $this->conversionRatio, $roundingMode);
}
示例2: add
/**
* @param money $amount
* @return money
*/
public function add(Money $amount)
{
if (!$this->currency->equals($amount->getCurrency())) {
throw new \InvalidArgumentException('Currency mismatch');
}
return new Money($this->currency, $this->amount + $amount->getValue());
}
示例3: convert
/** @return Money */
public function convert(Money $money)
{
if (!$money->getCurrency()->equals($this->counterCurrency)) {
throw new InvalidArgumentException("The Money has the wrong currency");
}
// @todo add rounding mode?
return new Money((int) round($money->getAmount() * $this->ratio), $this->baseCurrency);
}
示例4: convert
/**
* @param Money $money
* @param Currency $counterCurrency
* @param int $roundingMode
*
* @return Money
*/
public function convert(Money $money, Currency $counterCurrency, $roundingMode = Money::ROUND_HALF_UP)
{
$baseCurrency = $money->getCurrency();
$ratio = $this->exchange->quote($baseCurrency, $counterCurrency)->getConversionRatio();
$baseCurrencySubunit = $this->currencies->subunitFor($baseCurrency);
$counterCurrencySubunit = $this->currencies->subunitFor($counterCurrency);
$subunitDifference = $baseCurrencySubunit - $counterCurrencySubunit;
$ratio = $ratio / pow(10, $subunitDifference);
$counterValue = $money->multiply($ratio, $roundingMode);
return new Money($counterValue->getAmount(), $counterCurrency);
}
示例5: subtract
/**
* Subtratcs the given money from this one (immutable) and returns the result.
*
* @param Money $money the money to subtract
*
* @return Money
*
* @throws CurrencyMismatchException if the Currencies do not match
*/
public function subtract(Money $money)
{
if (!$this->currency->equals($money->getCurrency())) {
throw new CurrencyMismatchException($this . ' does not match ' . $money);
}
$amount = bcsub($this->amount, $money->getAmount(), self::BCSCALE);
return self::valueOf($amount, $this->currency);
}
示例6: 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());
}
}
示例7: testSetValueAsMoney
function testSetValueAsMoney()
{
$m1 = new Money();
$m1->setValue(array('Currency' => 'EUR', 'Amount' => 3.44));
$m2 = new Money();
$m2->setValue($m1);
$this->assertEquals($m2->getCurrency(), 'EUR');
$this->assertEquals($m2->getAmount(), 3.44);
}
示例8: testCurrencyCanBeReturned
public function testCurrencyCanBeReturned()
{
$currency = new USD();
$money = new Money($currency, 1);
$this->assertEquals($currency, $money->getCurrency());
}
示例9: compareTo
/**
* Compares this instance with an other instance.
*
* @param Money $b The instance to which this instance is to be compared.
*
* @return int -1, 0 or 1 as this instance is less than, equal to, or greater than $b
*
* @throws \InvalidArgumentException When the currencies do not match
*/
public function compareTo(Money $b)
{
if ($this->getCurrency() != $b->getCurrency()) {
throw new \InvalidArgumentException('Can not compare different currencies');
}
if ($this->getAmount() < $b->getAmount()) {
return -1;
} elseif ($this->getAmount() == $b->getAmount()) {
return 0;
} else {
return 1;
}
}
示例10: getCurrency
/**
* Returns the currency.
*
* @return string
*/
public function getCurrency()
{
$currency = parent::getCurrency();
$this->extend('updateCurrency', $currency);
return $currency;
}
示例11: isSameCurrencyAs
/**
* @param Money $money
* @return bool
*/
public function isSameCurrencyAs(Money $money)
{
return $this->currency->equals($money->getCurrency());
}
示例12: compare
/**
* compare
*
* Compares two instances for equality. Returns a value suitable for a sort
* callback. i.e. 1 if $first is larger than $second, 0 if equal, and -1 if
* $first is smaller than $second.
*
* @param Money $first
* @param Money $second
* @return int -1, 0, or 1
*/
public function compare(Money $first, Money $second)
{
$secondValue = $first->getCurrency()->getCode() === $second->getCurrency()->getCode() ? $second->getValue() : $this->converter->convert($second, $first->getCurrency())->getValue();
return bccomp($first->getValue(), $secondValue, max([$first->getPrecision(), $second->getPrecision()]));
}
示例13: equalTo
/**
* Compare if the amount is equal to the given amount.
*
* @param Money $money
* @return bool
* @throws \InvalidArgumentException
*/
public function equalTo(Money $money)
{
if ($this->getCurrency() !== $money->getCurrency()) {
throw new \InvalidArgumentException("Argument one must be of same currency");
}
return $this->getAmount() === $money->getAmount();
}
示例14: equals
/**
* 等価性確認
*
* @param Money $money マネーオブジェクト
* @return bool 等価性(trueで等価)
*/
public function equals(Money $money)
{
return $this->_amount === $money->getAmount() && $this->_currency === $money->getCurrency();
}
示例15: assertSameCurrency
/**
* @param \SebastianBergmann\Money\Money $a
* @param \SebastianBergmann\Money\Money $b
* @throws \SebastianBergmann\Money\CurrencyMismatchException
*/
private function assertSameCurrency(Money $a, Money $b)
{
if ($a->getCurrency() != $b->getCurrency()) {
throw new CurrencyMismatchException();
}
}