/** * @param Currency $currency * @return float * @throws Exception If error retrieving remote data */ public function getRate(Currency $currency) { $rates = $this->getRates(); $code = $currency->getCurrencyCode(); if (empty($rates[$code])) { throw new InvalidArgumentException(sprintf('%s (%s) is not supported by this source', $currency->getDisplayName(), $code)); } return (double) $rates[$code]; }
/** * @param Currency $currency * @return static */ public function setCurrency(Currency $currency) { $this->currency = $currency->getCurrencyCode(); return $this; }
/** * Specify data which should be serialized to JSON * * @return mixed data which can be serialized by <b>json_encode</b>, * @link http://php.net/manual/en/jsonserializable.jsonserialize.php */ public function jsonSerialize() { return ['amount' => $this->amount, 'currency' => $this->currency->getCurrencyCode()]; }
/** * @inheritdoc * @param Currency $object */ public function normalize($object, $format = null, array $context = []) { return $object->getCurrencyCode(); }