new appraoch
This commit is contained in:
42
pancake/system/vendor/moneyphp/money/src/Exchange/FixedExchange.php
vendored
Executable file
42
pancake/system/vendor/moneyphp/money/src/Exchange/FixedExchange.php
vendored
Executable file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Money\Exchange;
|
||||
|
||||
use Money\Currency;
|
||||
use Money\CurrencyPair;
|
||||
use Money\Exception\UnresolvableCurrencyPairException;
|
||||
use Money\Exchange;
|
||||
|
||||
/**
|
||||
* Provides a way to get exchange rate from a static list (array).
|
||||
*
|
||||
* @author Frederik Bosch <f.bosch@genkgo.nl>
|
||||
*/
|
||||
final class FixedExchange implements Exchange
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $list;
|
||||
|
||||
public function __construct(array $list)
|
||||
{
|
||||
$this->list = $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function quote(Currency $baseCurrency, Currency $counterCurrency)
|
||||
{
|
||||
if (isset($this->list[$baseCurrency->getCode()][$counterCurrency->getCode()])) {
|
||||
return new CurrencyPair(
|
||||
$baseCurrency,
|
||||
$counterCurrency,
|
||||
$this->list[$baseCurrency->getCode()][$counterCurrency->getCode()]
|
||||
);
|
||||
}
|
||||
|
||||
throw UnresolvableCurrencyPairException::createFromCurrencies($baseCurrency, $counterCurrency);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user