You are here

class ExchangeRate in Currency 8.3

Provides an exchange rate.

Hierarchy

Expanded class hierarchy of ExchangeRate

4 files declare their use of ExchangeRate
CurrencyExchangeTest.php in tests/src/Unit/Plugin/Filter/CurrencyExchangeTest.php
ExchangeRateProviderDecorator.php in src/Plugin/Currency/ExchangeRateProvider/ExchangeRateProviderDecorator.php
ExchangeRateProviderDecoratorTest.php in tests/src/Unit/Plugin/Currency/ExchangeRateProvider/ExchangeRateProviderDecoratorTest.php
ExchangeRateTest.php in tests/src/Unit/ExchangeRateTest.php

File

src/ExchangeRate.php, line 13

Namespace

Drupal\currency
View source
class ExchangeRate extends GenericExchangeRate implements ExchangeRateInterface, RefinableCacheableDependencyInterface {
  use RefinableCacheableDependencyTrait;

  /**
   * The ID of the exchange rate provider that provided this rate.
   *
   * @return string|null
   */
  protected $exchangeRateProviderId;

  /**
   * Constructs a new instance.
   *
   * @param string $source_currency_code
   *   The code of the source currency.
   * @param string $destination_currency_code
   *   The code of the destination currency.
   * @param string $rate
   *   The exchange rate.
   * @param string $exchange_rate_provider_id
   *   The ID of the exchange rate provider that provided this rate.
   */
  public function __construct($source_currency_code, $destination_currency_code, $rate, $exchange_rate_provider_id) {
    parent::__construct($source_currency_code, $destination_currency_code, $rate);
    $this->exchangeRateProviderId = $exchange_rate_provider_id;
  }

  /**
   * Creates a new exchange rate based on another one.
   *
   * @param \Commercie\CurrencyExchange\ExchangerateInterface $other_exchange_rate
   *   The code of the source currency.
   * @param string $exchange_rate_provider_id
   *   The ID of the exchange rate provider that provided this rate.
   *
   * @return static
   */
  public static function createFromExchangeRate(GenericExchangerateInterface $other_exchange_rate, $exchange_rate_provider_id) {
    $exchange_rate = new static($other_exchange_rate
      ->getSourceCurrencyCode(), $other_exchange_rate
      ->getDestinationCurrencyCode(), $other_exchange_rate
      ->getRate(), $exchange_rate_provider_id);
    $exchange_rate
      ->setTimestamp($other_exchange_rate
      ->getTimestamp());
    return $exchange_rate;
  }

  /**
   * {@inheritdoc}
   */
  public function getExchangeRateProviderId() {
    return $this->exchangeRateProviderId;
  }

  /**
   * {@inheritdoc}
   */
  public function setExchangeRateProviderId($id) {
    $this->exchangeRateProviderId = $id;
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::getCacheContexts public function 3
CacheableDependencyTrait::getCacheMaxAge public function 3
CacheableDependencyTrait::getCacheTags public function 3
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
ExchangeRate::$exchangeRateProviderId protected property The ID of the exchange rate provider that provided this rate.
ExchangeRate::createFromExchangeRate public static function Creates a new exchange rate based on another one.
ExchangeRate::getExchangeRateProviderId public function Gets the plugin ID of the exchange rate provider that provided this rate. Overrides ExchangeRateInterface::getExchangeRateProviderId
ExchangeRate::setExchangeRateProviderId public function Sets the plugin ID of the exchange rate provider that provided this rate. Overrides ExchangeRateInterface::setExchangeRateProviderId
ExchangeRate::__construct public function Constructs a new instance.
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function