Пример #1
0
 /**
  * @ZF-9519
  */
 public function testSetValueWithoutLocale()
 {
     $currency = new Currency\Currency('RUB', 'ru_RU');
     require_once __DIR__ . '/ExchangeTest.php';
     $this->assertEquals(null, $currency->getService());
     $currency->setService(new ExchangeTest());
     $this->assertTrue($currency->getService() instanceof Currency\CurrencyService);
     $currency->setValue(100, 'USD');
     $this->assertEquals(50, $currency->getValue());
     $this->assertEquals('RUB', $currency->getShortName());
 }
Пример #2
0
    /**
     * Internal method which calculates the exchanges currency
     *
     * @param float|integer|Currency $value    Compares the currency with this value
     * @param string|Currency        $currency The currency to compare this value from
     * @return float
     */
    protected function _exchangeCurrency($value, $currency)
    {
        if ($value instanceof Currency) {
            $currency = $value->getShortName();
            $value    = $value->getValue();
        } else {
            $currency = $this->getShortName($currency, $this->getLocale());
        }

        $rate = 1;
        if ($currency !== $this->getShortName()) {
            $service = $this->getService();
            if (!($service instanceof CurrencyService)) {
                throw new Exception\RuntimeException('No exchange service applied');
            }

            $rate = $service->getRate($currency, $this->getShortName());
        }

        $value *= $rate;
        return $value;
    }