ExchangeRateProviderDecorator.php in Currency 8.3
File
src/Plugin/Currency/ExchangeRateProvider/ExchangeRateProviderDecorator.php
View source
<?php
namespace Drupal\currency\Plugin\Currency\ExchangeRateProvider;
use Commercie\CurrencyExchange\ExchangeRateProviderInterface as GenericExchangeRateProviderInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\currency\ExchangeRate;
class ExchangeRateProviderDecorator extends PluginBase implements ExchangeRateProviderInterface {
protected $exchangeRateProvider;
public function __construct(array $configuration, $plugin_id, $plugin_definition, GenericExchangeRateProviderInterface $exchange_rate_provider) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->exchangeRateProvider = $exchange_rate_provider;
}
public function load($source_currency_code, $destination_currency_code) {
$exchange_rate = $this->exchangeRateProvider
->load($source_currency_code, $destination_currency_code);
return ExchangeRate::createFromExchangeRate($exchange_rate, $this
->getPluginId());
}
public function loadMultiple(array $currency_codes) {
$exchange_rates = [];
foreach ($this->exchangeRateProvider
->loadMultiple($currency_codes) as $source_currency_code => $destinations) {
foreach ($destinations as $destination_currency_code => $exchange_rate) {
$exchange_rates[$source_currency_code][$destination_currency_code] = ExchangeRate::createFromExchangeRate($exchange_rate, $this
->getPluginId());
}
}
return $exchange_rates;
}
}