示例#1
0
 /**
  * {@inheritdoc}
  */
 public function subunitFor(Currency $currency)
 {
     if ($currency->getCode() !== self::CODE) {
         throw new UnknownCurrencyException($currency->getCode() . ' is not bitcoin and is not supported by this currency repository');
     }
     return 8;
 }
示例#2
0
 /**
  * {@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);
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function subunitFor(Currency $currency)
 {
     if (null === self::$currencies) {
         self::$currencies = $this->loadCurrencies();
     }
     if (!isset(self::$currencies[$currency->getCode()])) {
         throw new UnknownCurrencyException('Cannot find ISO currency ' . $currency->getCode());
     }
     return self::$currencies[$currency->getCode()]['minorUnit'];
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function quote(Currency $baseCurrency, Currency $counterCurrency)
 {
     try {
         $rate = $this->swap->latest($baseCurrency->getCode() . '/' . $counterCurrency->getCode());
     } catch (ExchangerException $e) {
         throw UnresolvableCurrencyPairException::createFromCurrencies($baseCurrency, $counterCurrency);
     }
     return new CurrencyPair($baseCurrency, $counterCurrency, $rate->getValue());
 }
示例#5
0
 /**
  * {@inheritdoc}
  */
 public function getCurrencyPair(Currency $baseCurrency, Currency $counterCurrency)
 {
     $swapCurrencyPair = new SwapCurrencyPair($baseCurrency->getCode(), $counterCurrency->getCode());
     try {
         $rate = $this->swap->quote($swapCurrencyPair);
     } catch (SwapException $e) {
         throw UnresolvableCurrencyPairException::createFromCurrencies($baseCurrency, $counterCurrency);
     }
     return new CurrencyPair($baseCurrency, $counterCurrency, $rate->getValue());
 }
示例#6
0
 /**
  * {@inheritdoc}
  */
 public function subunitFor(Currency $currency)
 {
     $item = $this->pool->getItem('currency|subunit|' . $currency->getCode());
     if (false === $item->isHit()) {
         $item->set($this->currencies->subunitFor($currency));
         if ($item instanceof TaggableItemInterface) {
             $item->addTag('currency.subunit');
         }
         $this->pool->save($item);
     }
     return $item->get();
 }
 /**
  * Creates an exception from Currency objects.
  *
  * @param Currency $baseCurrency
  * @param Currency $counterCurrency
  *
  * @return UnresolvableCurrencyPairException
  */
 public static function createFromCurrencies(Currency $baseCurrency, Currency $counterCurrency)
 {
     $message = sprintf('Cannot resolve a currency pair for currencies: %s/%s', $baseCurrency->getCode(), $counterCurrency->getCode());
     return new self($message);
 }