Ejemplo n.º 1
0
 protected function getRate($from, $to)
 {
     $this->currencyDao->setEntity(new \ArrayObject());
     $currencyList = $this->currencyDao->getList();
     $supportedFrom = false;
     $supportedTo = false;
     $toValue = 1;
     $fromValue = 1;
     if (is_int($from) && is_int($to)) {
         $field = 'id';
     } else {
         if (is_string($from) && is_string($to)) {
             $field = 'code';
         } else {
             throw new \Exception('Invalid argument passed to getRate()');
         }
     }
     foreach ($currencyList as $currency) {
         if (is_int($from) && is_int($to)) {
             $likeFromTo = (int) $currency[$field];
         } else {
             $likeFromTo = $currency[$field];
         }
         if ($likeFromTo === $from) {
             $supportedFrom = true;
             $fromValue = $currency['value'];
         }
         if ($likeFromTo === $to) {
             $supportedTo = true;
             $toValue = $currency['value'];
         }
         if ($supportedFrom && $supportedTo) {
             break;
         }
     }
     if (!$supportedFrom) {
         throw new \Exception('Unable to exchange from $from');
     }
     if (!$supportedTo) {
         throw new \Exception('Unable to exchange to $to');
     }
     return $toValue / $fromValue;
 }
Ejemplo n.º 2
0
 public function __invoke()
 {
     $currencyDao = new Currency($this->serviceLocator, 'ArrayObject');
     $currecnyList = $currencyDao->getCurrencyListForSite();
     return $currecnyList;
 }