Example #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;
 }
Example #2
0
 /**
  * {@inheritdoc}
  *
  **/
 public function make($value, $type, $decimals = 2, $symbol = true)
 {
     $type = strtoupper($type);
     $typedata = Type::getTypeData($type);
     $dec_point = $typedata['decimal_mark'];
     $thousands_sep = $typedata['thousand_marker'];
     $format = number_format($value, $decimals, $dec_point, $thousands_sep);
     $this->value = str_replace('{value}', $format, $typedata['format']);
     if ($symbol === false) {
         $this->value = str_replace($typedata['symbol'], '', $this->value);
     }
     return $this->value;
 }
Example #3
0
 /**
  * @expectedException \Hexcores\Currency\Exceptions\NotSupportedTypeException
  */
 public function testNotSupportedTypeException()
 {
     Type::getTypeData("RUH");
 }
Example #4
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);
     }
 }