protected function searchCurrency($currencyCodeOrCountryCode) { // search first in the on-the-fly added currencies $currency = $this->searchAddedCurrencies($currencyCodeOrCountryCode); if (false !== $currency) { $this->addedCurrencies[$currencyCodeOrCountryCode] = $currency; //add to "addedCurrencies" will speed up the next search return $currency; } // search first in additional configured currencies (since those are likely important to the end user of the Bundle $currency = $this->searchAdditionalConfiguredCurrencies($currencyCodeOrCountryCode); if (false !== $currency) { $this->addedCurrencies[$currencyCodeOrCountryCode] = $currency; //add to "addedCurrencies" will speed up the next search return $currency; } // not present in the user configured currencies, look it up in the default XML based currency configuration $currencyNode = $this->getCurrencyNodeData($currencyCodeOrCountryCode); // not found in default XML; unsupported if (!$currencyNode) { throw new InvalidArgumentException("Currency or country code '{$currencyCodeOrCountryCode}' is not supported: no matching code found in file '{$this->currencyConfigurationFilename}'."); } // need to cast to int, since XML is string by default $currency = new Currency($currencyNode->getAttribute('code'), (int) $currencyNode->getAttribute('calculationPrecision'), (int) $currencyNode->getAttribute('displayPrecision')); $symbol = $currencyNode->getAttribute('symbol'); if ($symbol) { $currency->setSymbol($symbol); } $this->addedCurrencies[$currencyCodeOrCountryCode] = $currency; //add to "addedCurrencies" will speed up the next search return $currency; }
public function test__toString() { $usd = new Currency('USD', 2, 2, '$'); $this->assertEquals('USD', $usd->__toString()); $this->assertEquals('USD', (string) $usd); }