����JFIF��x�x����'
Server IP : 66.29.137.217 / Your IP : 18.117.111.63 Web Server : LiteSpeed System : Linux premium294.web-hosting.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64 User : gltevjme ( 1095) PHP Version : 7.0.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/gltevjme/bofirm.gltechlimited.com/vendor/moneyphp/money/src/ |
Upload File : |
<?php declare(strict_types=1); namespace Money; use InvalidArgumentException; use function sprintf; /** * Provides a way to convert Money to Money in another Currency using an exchange rate. */ final class Converter { private Currencies $currencies; private Exchange $exchange; public function __construct(Currencies $currencies, Exchange $exchange) { $this->currencies = $currencies; $this->exchange = $exchange; } public function convert(Money $money, Currency $counterCurrency, int $roundingMode = Money::ROUND_HALF_UP): Money { return $this->convertAgainstCurrencyPair( $money, $this->exchange->quote( $money->getCurrency(), $counterCurrency ), $roundingMode ); } /** @return array{0: Money, 1: CurrencyPair} */ public function convertAndReturnWithCurrencyPair(Money $money, Currency $counterCurrency, int $roundingMode = Money::ROUND_HALF_UP): array { $pair = $this->exchange->quote( $money->getCurrency(), $counterCurrency ); return [$this->convertAgainstCurrencyPair($money, $pair, $roundingMode), $pair]; } public function convertAgainstCurrencyPair(Money $money, CurrencyPair $currencyPair, int $roundingMode = Money::ROUND_HALF_UP): Money { if (! $money->getCurrency()->equals($currencyPair->getBaseCurrency())) { throw new InvalidArgumentException( sprintf( 'Expecting to convert against base currency %s, but got %s instead', $money->getCurrency()->getCode(), $currencyPair->getBaseCurrency()->getCode() ) ); } $ratio = $currencyPair->getConversionRatio(); $baseCurrencySubunit = $this->currencies->subunitFor($currencyPair->getBaseCurrency()); $counterCurrencySubunit = $this->currencies->subunitFor($currencyPair->getCounterCurrency()); $subunitDifference = $baseCurrencySubunit - $counterCurrencySubunit; $ratio = Number::fromString($ratio) ->base10($subunitDifference) ->__toString(); $counterValue = $money->multiply($ratio, $roundingMode); return new Money($counterValue->getAmount(), $currencyPair->getCounterCurrency()); } }