コード例 #1
0
/**
 * Converts a Money value object to a string for the database reporting etc
 * @param \SebastianBergmann\Money\Money $value
 * @return string
 */
function convertMoneyToString(Money $value)
{
    return convertIntToString($value->getAmount(), $value->getCurrency());
}
コード例 #2
0
ファイル: IntlFormatter.php プロジェクト: nitro2010/money
 /**
  * Formats a Money object using PHP's built-in NumberFormatter.
  *
  * @param  \SebastianBergmann\Money\Money $money
  * @return string
  */
 public function format(Money $money)
 {
     return $this->numberFormatter->formatCurrency($money->getConvertedAmount(), $money->getCurrency()->getCurrencyCode());
 }
コード例 #3
0
 /**
  * gets currency name
  *
  * @param Money $money
  * @return null|string
  */
 public function formatCurrencyAsName(Money $money)
 {
     return Intl::getCurrencyBundle()->getCurrencyName($money->getCurrency()->getCurrencyCode());
 }
コード例 #4
0
ファイル: Money.php プロジェクト: Aerendir/PHPValueObjects
 /**
  * {@inheritdoc}
  */
 public function getCurrency()
 {
     return $this->valueObject->getCurrency();
 }
コード例 #5
0
 /**
  * @return string
  */
 public function Currency()
 {
     return $this->value->getCurrency()->getCurrencyCode();
 }
コード例 #6
0
 /**
  * @param  Money    $money
  * @param  Currency $to
  * @param  int      $roundingMode
  * @return Money
  */
 public function convert(Money $money, Currency $to, $roundingMode = PHP_ROUND_HALF_UP)
 {
     $new = new Money($money->getAmount(), $to);
     $conversionRate = $this->source->getRateBetween($money->getCurrency(), $to);
     return $new->multiply($conversionRate, $roundingMode);
 }
コード例 #7
0
 /**
  * Converts amount from one currency to another using the currency's identifier
  *
  * Warning this method can lose precision!
  *
  * @param  \SebastianBergmann\Money\Money $amount
  * @param  \Heystack\Core\Identifier\IdentifierInterface $to
  * @return \SebastianBergmann\Money\Money
  * @throws \InvalidArgumentException
  */
 public function convert(Money $amount, IdentifierInterface $to)
 {
     if (!($toCurrency = $this->getCurrency($to))) {
         throw new \InvalidArgumentException("Currency not supported");
     }
     /** @var \Heystack\Ecommerce\Currency\Interfaces\CurrencyInterface $fromCurrency */
     $fromCurrency = $amount->getCurrency();
     return $amount->multiply($toCurrency->getValue() / $fromCurrency->getValue());
 }