示例#1
0
 /**
  * Check Currency types is supported or not.
  *
  * @param string $from
  * @param string $to
  * @return boolean
  * @throws \Hexcores\Currency\Exceptions\NotSupportedTypeException If currency type is not support.
  **/
 protected function checkCurrenyType($from, $to)
 {
     if (!Type::isSupported($from)) {
         throw new NotSupportedTypeException($from);
     }
     if (!Type::isSupported($to)) {
         throw new NotSupportedTypeException($to);
     }
     return true;
 }
示例#2
0
 public function testTypeIsNotSupported()
 {
     $this->assertFalse(Type::isSupported('ABC'));
 }
示例#3
0
 /**
  * PHP magic method call for "convertTo{TYPE}".
  * 
  * @param  string $method
  * @param  array $param
  * @return string
  * @throws \Hexcores\Currency\Exceptions\NotSupportedTypeException
  */
 public function __call($method, $param)
 {
     if (preg_match('/^convertTo(\\w+)$/', $method, $matches)) {
         $type = strtoupper($matches[1]);
         if (Type::isSupported($type)) {
             if (isset($param[0])) {
                 $val = (double) $param[0];
             } else {
                 $val = $this->original_value;
             }
             return $this->makeConverting($val, $this->from, $type);
         }
         throw new NotSupportedTypeException($type);
     }
 }