@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - require __DIR__ .'/vendor/autoload.php'; |
|
| 3 | + require __DIR__.'/vendor/autoload.php'; |
|
| 4 | 4 | |
| 5 | 5 | $value = new CConverter\Converter('YOUR_API_KEY'); |
| 6 | 6 | echo $value->cconv('EUR', 'USD'); |
@@ -5,15 +5,15 @@ |
||
| 5 | 5 | interface CalculateInterface |
| 6 | 6 | { |
| 7 | 7 | /** |
| 8 | - * currency conversion, cache check and fixer.io api connection |
|
| 9 | - * |
|
| 10 | - * @param string|array $getFrom |
|
| 8 | + * currency conversion, cache check and fixer.io api connection |
|
| 9 | + * |
|
| 10 | + * @param string|array $getFrom |
|
| 11 | 11 | * @param string|array $getTo |
| 12 | 12 | * @param float $amount |
| 13 | 13 | * @param int $short |
| 14 | 14 | * @param bool $isCache |
| 15 | 15 | * @param int $cacheTime |
| 16 | - * @return string|array |
|
| 17 | - */ |
|
| 16 | + * @return string|array |
|
| 17 | + */ |
|
| 18 | 18 | public function getValues($from, $to, $amount, $short, $isCache, $cacheTime); |
| 19 | 19 | } |
@@ -7,21 +7,21 @@ discard block |
||
| 7 | 7 | class Calculate implements CalculateInterface |
| 8 | 8 | { |
| 9 | 9 | /** |
| 10 | - * @var contains fixer.io api key string |
|
| 11 | - */ |
|
| 10 | + * @var contains fixer.io api key string |
|
| 11 | + */ |
|
| 12 | 12 | protected $api_key; |
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | - * @const contains fixer.io API URL |
|
| 16 | - */ |
|
| 15 | + * @const contains fixer.io API URL |
|
| 16 | + */ |
|
| 17 | 17 | const API_URL = "http://data.fixer.io/api/latest"; |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * get api key |
|
| 21 | - * |
|
| 22 | - * @param string $key |
|
| 23 | - * @return bool |
|
| 24 | - */ |
|
| 20 | + * get api key |
|
| 21 | + * |
|
| 22 | + * @param string $key |
|
| 23 | + * @return bool |
|
| 24 | + */ |
|
| 25 | 25 | public function __construct($key) |
| 26 | 26 | { |
| 27 | 27 | $this->api_key = $key; |
@@ -30,12 +30,12 @@ discard block |
||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | - * change or not float decimals |
|
| 34 | - * |
|
| 35 | - * @param float $calc |
|
| 33 | + * change or not float decimals |
|
| 34 | + * |
|
| 35 | + * @param float $calc |
|
| 36 | 36 | * @param int $short |
| 37 | - * @return float |
|
| 38 | - */ |
|
| 37 | + * @return float |
|
| 38 | + */ |
|
| 39 | 39 | public static function roundValue($calc, $short) |
| 40 | 40 | { |
| 41 | 41 | if($short){ $number = 2; }else{ $number = 5; } |
@@ -45,16 +45,16 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | - * currency conversion, cache check and fixer.io api connection |
|
| 49 | - * |
|
| 50 | - * @param string|array $getFrom |
|
| 48 | + * currency conversion, cache check and fixer.io api connection |
|
| 49 | + * |
|
| 50 | + * @param string|array $getFrom |
|
| 51 | 51 | * @param string|array $getTo |
| 52 | 52 | * @param float $amount |
| 53 | 53 | * @param int $short |
| 54 | 54 | * @param bool $isCache |
| 55 | 55 | * @param int $cacheTime |
| 56 | - * @return string|array |
|
| 57 | - */ |
|
| 56 | + * @return string|array |
|
| 57 | + */ |
|
| 58 | 58 | public function getValues($getFrom, $getTo, $amount, $short, $isCache, $cacheTime) |
| 59 | 59 | { |
| 60 | 60 | if($isCache && CacheFile::isCacheDir()){ |
@@ -118,11 +118,11 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * validate errors in conncection with fixer.io api |
| 121 | - * |
|
| 121 | + * |
|
| 122 | 122 | * @param string|array $data |
| 123 | - * @return bool |
|
| 123 | + * @return bool |
|
| 124 | 124 | * @throws Exception\InvalidArgumentException |
| 125 | - */ |
|
| 125 | + */ |
|
| 126 | 126 | public function validateErrors($data) |
| 127 | 127 | { |
| 128 | 128 | if(!$data->success){ |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public static function roundValue($calc, $short) |
| 40 | 40 | { |
| 41 | - if($short){ $number = 2; }else{ $number = 5; } |
|
| 41 | + if ($short) { $number = 2; }else { $number = 5; } |
|
| 42 | 42 | $output = round($calc, $number); |
| 43 | 43 | |
| 44 | 44 | return $output; |
@@ -57,60 +57,60 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function getValues($getFrom, $getTo, $amount, $short, $isCache, $cacheTime) |
| 59 | 59 | { |
| 60 | - if($isCache && CacheFile::isCacheDir()){ |
|
| 61 | - if(CacheFile::isFile()){ |
|
| 60 | + if ($isCache && CacheFile::isCacheDir()) { |
|
| 61 | + if (CacheFile::isFile()) { |
|
| 62 | 62 | $file = CacheFile::getFileName(); |
| 63 | - if(CacheFile::isCurrent($file)){ |
|
| 63 | + if (CacheFile::isCurrent($file)) { |
|
| 64 | 64 | $data = CacheFile::getCache($file); |
| 65 | - }else{ |
|
| 65 | + }else { |
|
| 66 | 66 | $data = file_get_contents(self::API_URL."?access_key=".$this->api_key); |
| 67 | 67 | CacheFile::setNewCacheFile($file, $data, $cacheTime); |
| 68 | 68 | } |
| 69 | - }else{ |
|
| 69 | + }else { |
|
| 70 | 70 | $data = file_get_contents(self::API_URL."?access_key=".$this->api_key); |
| 71 | 71 | CacheFile::setNewCacheFile(false, $data, $cacheTime); |
| 72 | 72 | } |
| 73 | - }else{ |
|
| 73 | + }else { |
|
| 74 | 74 | $data = file_get_contents(self::API_URL."?access_key=".$this->api_key); |
| 75 | 75 | } |
| 76 | 76 | $data = json_decode($data); |
| 77 | 77 | |
| 78 | - if($this->validateErrors($data)){ |
|
| 79 | - if(is_array($getFrom) || is_array($getTo)){ |
|
| 78 | + if ($this->validateErrors($data)) { |
|
| 79 | + if (is_array($getFrom) || is_array($getTo)) { |
|
| 80 | 80 | $newArray = array(); |
| 81 | 81 | |
| 82 | - if(is_array($getFrom)){ |
|
| 83 | - if(is_array($getTo)){ |
|
| 84 | - foreach($getFrom as $currency){ |
|
| 82 | + if (is_array($getFrom)) { |
|
| 83 | + if (is_array($getTo)) { |
|
| 84 | + foreach ($getFrom as $currency) { |
|
| 85 | 85 | $getA = $data->rates->$currency; |
| 86 | - foreach($getTo as $currency2){ |
|
| 86 | + foreach ($getTo as $currency2) { |
|
| 87 | 87 | $getB = $data->rates->$currency2; |
| 88 | - $calc = Calculate::roundValue(($amount * $getB)/$getA, $short); |
|
| 88 | + $calc = Calculate::roundValue(($amount*$getB)/$getA, $short); |
|
| 89 | 89 | array_push($newArray, array($currency, array($currency2 => $calc))); |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | - }else{ |
|
| 93 | - foreach($getFrom as $currency){ |
|
| 92 | + }else { |
|
| 93 | + foreach ($getFrom as $currency) { |
|
| 94 | 94 | $getA = $data->rates->$currency; |
| 95 | 95 | $getB = $data->rates->$getTo; |
| 96 | - $calc = Calculate::roundValue(($amount * $getB)/$getA, $short); |
|
| 96 | + $calc = Calculate::roundValue(($amount*$getB)/$getA, $short); |
|
| 97 | 97 | array_push($newArray, array($currency, array($getTo => $calc))); |
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | - }else{ |
|
| 101 | - foreach($getTo as $currency){ |
|
| 100 | + }else { |
|
| 101 | + foreach ($getTo as $currency) { |
|
| 102 | 102 | $getA = $data->rates->$getFrom; |
| 103 | 103 | $getB = $data->rates->$currency; |
| 104 | - $calc = Calculate::roundValue(($amount * $getB)/$getA, $short); |
|
| 104 | + $calc = Calculate::roundValue(($amount*$getB)/$getA, $short); |
|
| 105 | 105 | array_push($newArray, array($getFrom, array($currency => $calc))); |
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | $output = $newArray; |
| 109 | - }else{ |
|
| 109 | + }else { |
|
| 110 | 110 | $getA = $data->rates->$getFrom; |
| 111 | 111 | $getB = $data->rates->$getTo; |
| 112 | 112 | |
| 113 | - $output = Calculate::roundValue(($amount * $getB)/$getA, $short); |
|
| 113 | + $output = Calculate::roundValue(($amount*$getB)/$getA, $short); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | return $output; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public function validateErrors($data) |
| 127 | 127 | { |
| 128 | - if(!$data->success){ |
|
| 128 | + if (!$data->success) { |
|
| 129 | 129 | $getErrorCode = $data->error->code; |
| 130 | 130 | $getErrorInfo = $data->error->info; |
| 131 | 131 | throw new \InvalidArgumentException("[$getErrorCode] $getErrorInfo"); |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public static function roundValue($calc, $short) |
| 40 | 40 | { |
| 41 | - if($short){ $number = 2; }else{ $number = 5; } |
|
| 41 | + if($short){ $number = 2; } else{ $number = 5; } |
|
| 42 | 42 | $output = round($calc, $number); |
| 43 | 43 | |
| 44 | 44 | return $output; |
@@ -62,15 +62,15 @@ discard block |
||
| 62 | 62 | $file = CacheFile::getFileName(); |
| 63 | 63 | if(CacheFile::isCurrent($file)){ |
| 64 | 64 | $data = CacheFile::getCache($file); |
| 65 | - }else{ |
|
| 65 | + } else{ |
|
| 66 | 66 | $data = file_get_contents(self::API_URL."?access_key=".$this->api_key); |
| 67 | 67 | CacheFile::setNewCacheFile($file, $data, $cacheTime); |
| 68 | 68 | } |
| 69 | - }else{ |
|
| 69 | + } else{ |
|
| 70 | 70 | $data = file_get_contents(self::API_URL."?access_key=".$this->api_key); |
| 71 | 71 | CacheFile::setNewCacheFile(false, $data, $cacheTime); |
| 72 | 72 | } |
| 73 | - }else{ |
|
| 73 | + } else{ |
|
| 74 | 74 | $data = file_get_contents(self::API_URL."?access_key=".$this->api_key); |
| 75 | 75 | } |
| 76 | 76 | $data = json_decode($data); |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | array_push($newArray, array($currency, array($currency2 => $calc))); |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | - }else{ |
|
| 92 | + } else{ |
|
| 93 | 93 | foreach($getFrom as $currency){ |
| 94 | 94 | $getA = $data->rates->$currency; |
| 95 | 95 | $getB = $data->rates->$getTo; |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | array_push($newArray, array($currency, array($getTo => $calc))); |
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | - }else{ |
|
| 100 | + } else{ |
|
| 101 | 101 | foreach($getTo as $currency){ |
| 102 | 102 | $getA = $data->rates->$getFrom; |
| 103 | 103 | $getB = $data->rates->$currency; |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | $output = $newArray; |
| 109 | - }else{ |
|
| 109 | + } else{ |
|
| 110 | 110 | $getA = $data->rates->$getFrom; |
| 111 | 111 | $getB = $data->rates->$getTo; |
| 112 | 112 | |
@@ -7,124 +7,124 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Converter implements ConverterInterface |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @var fixer.io api key string |
|
| 12 | - */ |
|
| 13 | - protected $api_key; |
|
| 14 | - |
|
| 15 | - /** |
|
| 16 | - * sortage api key lenght |
|
| 17 | - * |
|
| 18 | - * @var int |
|
| 19 | - */ |
|
| 20 | - public $api_length = 32; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * sortage cache or not |
|
| 24 | - * |
|
| 25 | - * @var bool |
|
| 26 | - */ |
|
| 27 | - public $isCache = false; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * contains storage cache in minutes |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 34 | - public $cacheTime = 60; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * connect with API fixer.io |
|
| 38 | - * |
|
| 39 | - * @param string $api_key |
|
| 40 | - * @return bool |
|
| 41 | - */ |
|
| 42 | - public function __construct($api_key) |
|
| 43 | - { |
|
| 44 | - if(strlen($api_key)==$this->api_length){ |
|
| 45 | - $this->api_key = $api_key; |
|
| 46 | - }else{ |
|
| 47 | - throw new Exception\InvalidArgumentException('Invalid length of API KEY'); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - return true; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * initial currency conversion |
|
| 55 | - * |
|
| 56 | - * @param string|array $from |
|
| 57 | - * @param string|array $to |
|
| 58 | - * @param float $amount |
|
| 59 | - * @param bool|int $short |
|
| 60 | - * @return string|array |
|
| 61 | - */ |
|
| 62 | - public function cconv($from, $to, $amount = 1, $short = false) |
|
| 63 | - { |
|
| 64 | - $getFrom = $this->checkInput($from); |
|
| 65 | - $getTo = $this->checkInput($to); |
|
| 66 | - |
|
| 67 | - $calculate = new Calculate($this->api_key); |
|
| 68 | - |
|
| 69 | - $output = $calculate->getValues($getFrom, $getTo, $amount, $short, $this->isCache, $this->cacheTime); |
|
| 70 | - |
|
| 71 | - return $output; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * validate input data |
|
| 76 | - * |
|
| 77 | - * @param string $data |
|
| 78 | - * @return bool |
|
| 79 | - */ |
|
| 80 | - public function validateInput($data) |
|
| 81 | - { |
|
| 82 | - if(strlen($data)==2 || strlen($data)==3){ |
|
| 83 | - $output = ConverterCurrency::getCurrency($data); |
|
| 84 | - }else{ |
|
| 85 | - $output = false; |
|
| 86 | - } |
|
| 87 | - return $output; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * initial cache or not |
|
| 92 | - * |
|
| 93 | - * @param bool $is |
|
| 94 | - * @param int $time |
|
| 95 | - * @return bool |
|
| 96 | - */ |
|
| 97 | - public function cache($is = false, $time = 60) |
|
| 98 | - { |
|
| 99 | - $parm = Cache::setCache($is, $time); |
|
| 100 | - $this->isCache = $parm; |
|
| 101 | - $this->cacheTime = $time; |
|
| 102 | - |
|
| 103 | - return true; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * check input data for validator |
|
| 108 | - * |
|
| 109 | - * @param string|array $data |
|
| 110 | - * @return string|array |
|
| 111 | - * @throws Exception\InvalidArgumentException |
|
| 112 | - */ |
|
| 113 | - protected function checkInput($data) |
|
| 114 | - { |
|
| 115 | - if(is_string($data)){ |
|
| 116 | - $value = $this->validateInput($data); |
|
| 117 | - if($value==false) throw new Exception\InvalidArgumentException('Invalid data. Please enter a valid country or currency name'); |
|
| 118 | - }else if(is_array($data)){ |
|
| 119 | - $value = array(); |
|
| 120 | - foreach($data as $single){ |
|
| 121 | - $opt = $this->validateInput($single); |
|
| 122 | - if($opt==false) throw new Exception\InvalidArgumentException('Invalid data. Please enter array with a valid country or currency names'); |
|
| 123 | - array_push($value, $opt); |
|
| 124 | - } |
|
| 125 | - }else{ |
|
| 126 | - throw new Exception\InvalidArgumentException('Invalid data. Please use string or array value'); |
|
| 127 | - } |
|
| 128 | - return $value; |
|
| 129 | - } |
|
| 10 | + /** |
|
| 11 | + * @var fixer.io api key string |
|
| 12 | + */ |
|
| 13 | + protected $api_key; |
|
| 14 | + |
|
| 15 | + /** |
|
| 16 | + * sortage api key lenght |
|
| 17 | + * |
|
| 18 | + * @var int |
|
| 19 | + */ |
|
| 20 | + public $api_length = 32; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * sortage cache or not |
|
| 24 | + * |
|
| 25 | + * @var bool |
|
| 26 | + */ |
|
| 27 | + public $isCache = false; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * contains storage cache in minutes |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | + public $cacheTime = 60; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * connect with API fixer.io |
|
| 38 | + * |
|
| 39 | + * @param string $api_key |
|
| 40 | + * @return bool |
|
| 41 | + */ |
|
| 42 | + public function __construct($api_key) |
|
| 43 | + { |
|
| 44 | + if(strlen($api_key)==$this->api_length){ |
|
| 45 | + $this->api_key = $api_key; |
|
| 46 | + }else{ |
|
| 47 | + throw new Exception\InvalidArgumentException('Invalid length of API KEY'); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + return true; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * initial currency conversion |
|
| 55 | + * |
|
| 56 | + * @param string|array $from |
|
| 57 | + * @param string|array $to |
|
| 58 | + * @param float $amount |
|
| 59 | + * @param bool|int $short |
|
| 60 | + * @return string|array |
|
| 61 | + */ |
|
| 62 | + public function cconv($from, $to, $amount = 1, $short = false) |
|
| 63 | + { |
|
| 64 | + $getFrom = $this->checkInput($from); |
|
| 65 | + $getTo = $this->checkInput($to); |
|
| 66 | + |
|
| 67 | + $calculate = new Calculate($this->api_key); |
|
| 68 | + |
|
| 69 | + $output = $calculate->getValues($getFrom, $getTo, $amount, $short, $this->isCache, $this->cacheTime); |
|
| 70 | + |
|
| 71 | + return $output; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * validate input data |
|
| 76 | + * |
|
| 77 | + * @param string $data |
|
| 78 | + * @return bool |
|
| 79 | + */ |
|
| 80 | + public function validateInput($data) |
|
| 81 | + { |
|
| 82 | + if(strlen($data)==2 || strlen($data)==3){ |
|
| 83 | + $output = ConverterCurrency::getCurrency($data); |
|
| 84 | + }else{ |
|
| 85 | + $output = false; |
|
| 86 | + } |
|
| 87 | + return $output; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * initial cache or not |
|
| 92 | + * |
|
| 93 | + * @param bool $is |
|
| 94 | + * @param int $time |
|
| 95 | + * @return bool |
|
| 96 | + */ |
|
| 97 | + public function cache($is = false, $time = 60) |
|
| 98 | + { |
|
| 99 | + $parm = Cache::setCache($is, $time); |
|
| 100 | + $this->isCache = $parm; |
|
| 101 | + $this->cacheTime = $time; |
|
| 102 | + |
|
| 103 | + return true; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * check input data for validator |
|
| 108 | + * |
|
| 109 | + * @param string|array $data |
|
| 110 | + * @return string|array |
|
| 111 | + * @throws Exception\InvalidArgumentException |
|
| 112 | + */ |
|
| 113 | + protected function checkInput($data) |
|
| 114 | + { |
|
| 115 | + if(is_string($data)){ |
|
| 116 | + $value = $this->validateInput($data); |
|
| 117 | + if($value==false) throw new Exception\InvalidArgumentException('Invalid data. Please enter a valid country or currency name'); |
|
| 118 | + }else if(is_array($data)){ |
|
| 119 | + $value = array(); |
|
| 120 | + foreach($data as $single){ |
|
| 121 | + $opt = $this->validateInput($single); |
|
| 122 | + if($opt==false) throw new Exception\InvalidArgumentException('Invalid data. Please enter array with a valid country or currency names'); |
|
| 123 | + array_push($value, $opt); |
|
| 124 | + } |
|
| 125 | + }else{ |
|
| 126 | + throw new Exception\InvalidArgumentException('Invalid data. Please use string or array value'); |
|
| 127 | + } |
|
| 128 | + return $value; |
|
| 129 | + } |
|
| 130 | 130 | } |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function __construct($api_key) |
| 43 | 43 | { |
| 44 | - if(strlen($api_key)==$this->api_length){ |
|
| 44 | + if (strlen($api_key)==$this->api_length) { |
|
| 45 | 45 | $this->api_key = $api_key; |
| 46 | - }else{ |
|
| 46 | + }else { |
|
| 47 | 47 | throw new Exception\InvalidArgumentException('Invalid length of API KEY'); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function validateInput($data) |
| 81 | 81 | { |
| 82 | - if(strlen($data)==2 || strlen($data)==3){ |
|
| 82 | + if (strlen($data)==2 || strlen($data)==3) { |
|
| 83 | 83 | $output = ConverterCurrency::getCurrency($data); |
| 84 | - }else{ |
|
| 84 | + }else { |
|
| 85 | 85 | $output = false; |
| 86 | 86 | } |
| 87 | 87 | return $output; |
@@ -112,17 +112,17 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | protected function checkInput($data) |
| 114 | 114 | { |
| 115 | - if(is_string($data)){ |
|
| 115 | + if (is_string($data)) { |
|
| 116 | 116 | $value = $this->validateInput($data); |
| 117 | - if($value==false) throw new Exception\InvalidArgumentException('Invalid data. Please enter a valid country or currency name'); |
|
| 118 | - }else if(is_array($data)){ |
|
| 117 | + if ($value==false) throw new Exception\InvalidArgumentException('Invalid data. Please enter a valid country or currency name'); |
|
| 118 | + }else if (is_array($data)) { |
|
| 119 | 119 | $value = array(); |
| 120 | - foreach($data as $single){ |
|
| 120 | + foreach ($data as $single) { |
|
| 121 | 121 | $opt = $this->validateInput($single); |
| 122 | - if($opt==false) throw new Exception\InvalidArgumentException('Invalid data. Please enter array with a valid country or currency names'); |
|
| 122 | + if ($opt==false) throw new Exception\InvalidArgumentException('Invalid data. Please enter array with a valid country or currency names'); |
|
| 123 | 123 | array_push($value, $opt); |
| 124 | 124 | } |
| 125 | - }else{ |
|
| 125 | + }else { |
|
| 126 | 126 | throw new Exception\InvalidArgumentException('Invalid data. Please use string or array value'); |
| 127 | 127 | } |
| 128 | 128 | return $value; |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | { |
| 44 | 44 | if(strlen($api_key)==$this->api_length){ |
| 45 | 45 | $this->api_key = $api_key; |
| 46 | - }else{ |
|
| 46 | + } else{ |
|
| 47 | 47 | throw new Exception\InvalidArgumentException('Invalid length of API KEY'); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | { |
| 82 | 82 | if(strlen($data)==2 || strlen($data)==3){ |
| 83 | 83 | $output = ConverterCurrency::getCurrency($data); |
| 84 | - }else{ |
|
| 84 | + } else{ |
|
| 85 | 85 | $output = false; |
| 86 | 86 | } |
| 87 | 87 | return $output; |
@@ -114,15 +114,19 @@ discard block |
||
| 114 | 114 | { |
| 115 | 115 | if(is_string($data)){ |
| 116 | 116 | $value = $this->validateInput($data); |
| 117 | - if($value==false) throw new Exception\InvalidArgumentException('Invalid data. Please enter a valid country or currency name'); |
|
| 118 | - }else if(is_array($data)){ |
|
| 117 | + if($value==false) { |
|
| 118 | + throw new Exception\InvalidArgumentException('Invalid data. Please enter a valid country or currency name'); |
|
| 119 | + } |
|
| 120 | + } else if(is_array($data)){ |
|
| 119 | 121 | $value = array(); |
| 120 | 122 | foreach($data as $single){ |
| 121 | 123 | $opt = $this->validateInput($single); |
| 122 | - if($opt==false) throw new Exception\InvalidArgumentException('Invalid data. Please enter array with a valid country or currency names'); |
|
| 124 | + if($opt==false) { |
|
| 125 | + throw new Exception\InvalidArgumentException('Invalid data. Please enter array with a valid country or currency names'); |
|
| 126 | + } |
|
| 123 | 127 | array_push($value, $opt); |
| 124 | 128 | } |
| 125 | - }else{ |
|
| 129 | + } else{ |
|
| 126 | 130 | throw new Exception\InvalidArgumentException('Invalid data. Please use string or array value'); |
| 127 | 131 | } |
| 128 | 132 | return $value; |
@@ -4,202 +4,202 @@ |
||
| 4 | 4 | |
| 5 | 5 | class ConverterCurrency |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * country code and currency code contains gold, silver and bitcoin currency |
|
| 9 | - * |
|
| 10 | - * @var array |
|
| 11 | - */ |
|
| 12 | - protected static $countrys = array( |
|
| 13 | - 'AED' => 'AE', |
|
| 14 | - 'AFN' => 'AF', |
|
| 15 | - 'ALL' => 'AL', |
|
| 16 | - 'AMD' => 'AM', |
|
| 17 | - 'ANG' => 'AN', |
|
| 18 | - 'AOA' => 'AO', |
|
| 19 | - 'ARS' => 'AR', |
|
| 20 | - 'AUD' => 'AU', |
|
| 21 | - 'AWG' => 'AW', |
|
| 22 | - 'AZN' => 'AZ', |
|
| 23 | - 'BAM' => 'BA', |
|
| 24 | - 'BBD' => 'BB', |
|
| 25 | - 'BDT' => 'BD', |
|
| 26 | - 'BGN' => 'BG', |
|
| 27 | - 'BHD' => 'BH', |
|
| 28 | - 'BIF' => 'BI', |
|
| 29 | - 'BMD' => 'BM', |
|
| 30 | - 'BND' => 'BN', |
|
| 31 | - 'BOB' => 'BO', |
|
| 32 | - 'BRL' => 'BR', |
|
| 33 | - 'BSD' => 'BS', |
|
| 34 | - 'BTC' => 'BTC', |
|
| 35 | - 'BTN' => 'BT', |
|
| 36 | - 'BWP' => 'BW', |
|
| 37 | - 'BYN' => 'BY', |
|
| 38 | - 'BYR' => 'BY', |
|
| 39 | - 'BZD' => 'BZ', |
|
| 40 | - 'CAD' => 'CA', |
|
| 41 | - 'CDF' => 'CD', |
|
| 42 | - 'CHF' => 'LI', |
|
| 43 | - 'CLF' => 'CL', |
|
| 44 | - 'CLP' => 'CL', |
|
| 45 | - 'CNY' => 'CN', |
|
| 46 | - 'COP' => 'CO', |
|
| 47 | - 'CRC' => 'CR', |
|
| 48 | - 'CUC' => 'CU', |
|
| 49 | - 'CUP' => 'CU', |
|
| 50 | - 'CVE' => 'CV', |
|
| 51 | - 'CZK' => 'CZ', |
|
| 52 | - 'DJF' => 'DJ', |
|
| 53 | - 'DKK' => 'DK', |
|
| 54 | - 'DOP' => 'DO', |
|
| 55 | - 'DZD' => 'DZ', |
|
| 56 | - 'EGP' => 'EG', |
|
| 57 | - 'ERN' => 'ER', |
|
| 58 | - 'ETB' => 'ET', |
|
| 59 | - 'EUR' => 'AD', |
|
| 60 | - 'FJD' => 'FJ', |
|
| 61 | - 'FKP' => 'FK', |
|
| 62 | - 'GBP' => 'IO', |
|
| 63 | - 'GEL' => 'GE', |
|
| 64 | - 'GGP' => 'GG', |
|
| 65 | - 'GHS' => 'GH', |
|
| 66 | - 'GIP' => 'GI', |
|
| 67 | - 'GMD' => 'GM', |
|
| 68 | - 'GNF' => 'GN', |
|
| 69 | - 'GTQ' => 'GT', |
|
| 70 | - 'GYD' => 'GY', |
|
| 71 | - 'HKD' => 'HK', |
|
| 72 | - 'HNL' => 'HN', |
|
| 73 | - 'HRK' => 'HR', |
|
| 74 | - 'HTG' => 'HT', |
|
| 75 | - 'HUF' => 'HU', |
|
| 76 | - 'IDR' => 'ID', |
|
| 77 | - 'ILS' => 'IL', |
|
| 78 | - 'IMP' => 'IM', |
|
| 79 | - 'INR' => 'IN', |
|
| 80 | - 'IQD' => 'IQ', |
|
| 81 | - 'IRR' => 'IR', |
|
| 82 | - 'ISK' => 'IS', |
|
| 83 | - 'JEP' => 'JE', |
|
| 84 | - 'JMD' => 'JM', |
|
| 85 | - 'JOD' => 'JO', |
|
| 86 | - 'JPY' => 'JP', |
|
| 87 | - 'KES' => 'KE', |
|
| 88 | - 'KGS' => 'KG', |
|
| 89 | - 'KHR' => 'KH', |
|
| 90 | - 'KMF' => 'KM', |
|
| 91 | - 'KPW' => 'KP', |
|
| 92 | - 'KRW' => 'KR', |
|
| 93 | - 'KWD' => 'KW', |
|
| 94 | - 'KYD' => 'KY', |
|
| 95 | - 'KZT' => 'KZ', |
|
| 96 | - 'LAK' => 'LA', |
|
| 97 | - 'LBP' => 'LB', |
|
| 98 | - 'LKR' => 'LK', |
|
| 99 | - 'LRD' => 'LR', |
|
| 100 | - 'LSL' => 'LS', |
|
| 101 | - 'LTL' => 'LT', |
|
| 102 | - 'LVL' => 'LV', |
|
| 103 | - 'LYD' => 'LY', |
|
| 104 | - 'MAD' => 'MA', |
|
| 105 | - 'MDL' => 'MD', |
|
| 106 | - 'MGA' => 'MG', |
|
| 107 | - 'MKD' => 'MK', |
|
| 108 | - 'MMK' => 'MM', |
|
| 109 | - 'MNT' => 'MN', |
|
| 110 | - 'MOP' => 'MO', |
|
| 111 | - 'MRO' => 'MR', |
|
| 112 | - 'MUR' => 'MU', |
|
| 113 | - 'MVR' => 'MV', |
|
| 114 | - 'MWK' => 'MW', |
|
| 115 | - 'MXN' => 'MX', |
|
| 116 | - 'MYR' => 'MY', |
|
| 117 | - 'MZN' => 'MZ', |
|
| 118 | - 'NAD' => 'NA', |
|
| 119 | - 'NGN' => 'NG', |
|
| 120 | - 'NIO' => 'NI', |
|
| 121 | - 'NOK' => 'AQ', |
|
| 122 | - 'NPR' => 'NP', |
|
| 123 | - 'NZD' => 'CK', |
|
| 124 | - 'OMR' => 'OM', |
|
| 125 | - 'PAB' => 'PA', |
|
| 126 | - 'PEN' => 'PE', |
|
| 127 | - 'PGK' => 'PG', |
|
| 128 | - 'PHP' => 'PH', |
|
| 129 | - 'PKR' => 'PK', |
|
| 130 | - 'PLN' => 'PL', |
|
| 131 | - 'PYG' => 'PY', |
|
| 132 | - 'QAR' => 'QA', |
|
| 133 | - 'RON' => 'RO', |
|
| 134 | - 'RSD' => 'RS', |
|
| 135 | - 'RUB' => 'RU', |
|
| 136 | - 'RWF' => 'RW', |
|
| 137 | - 'SAR' => 'SA', |
|
| 138 | - 'SBD' => 'SB', |
|
| 139 | - 'SCR' => 'SC', |
|
| 140 | - 'SDG' => 'SD', |
|
| 141 | - 'SEK' => 'SE', |
|
| 142 | - 'SGD' => 'SG', |
|
| 143 | - 'SHP' => 'SH', |
|
| 144 | - 'SLL' => 'SL', |
|
| 145 | - 'SOS' => 'SO', |
|
| 146 | - 'SRD' => 'SR', |
|
| 147 | - 'STD' => 'ST', |
|
| 148 | - 'SVC' => 'SV', |
|
| 149 | - 'SYP' => 'SY', |
|
| 150 | - 'SZL' => 'SZ', |
|
| 151 | - 'THB' => 'TH', |
|
| 152 | - 'TJS' => 'TJ', |
|
| 153 | - 'TMT' => 'TM', |
|
| 154 | - 'TND' => 'TN', |
|
| 155 | - 'TOP' => 'TO', |
|
| 156 | - 'TRY' => 'TR', |
|
| 157 | - 'TTD' => 'TT', |
|
| 158 | - 'TWD' => 'TW', |
|
| 159 | - 'TZS' => 'TZ', |
|
| 160 | - 'UAH' => 'UA', |
|
| 161 | - 'UGX' => 'UG', |
|
| 162 | - 'USD' => 'AS', |
|
| 163 | - 'UYU' => 'UY', |
|
| 164 | - 'UZS' => 'UZ', |
|
| 165 | - 'VEF' => 'VE', |
|
| 166 | - 'VND' => 'VN', |
|
| 167 | - 'VUV' => 'VU', |
|
| 168 | - 'WST' => 'WS', |
|
| 169 | - 'XAF' => 'BJ', |
|
| 170 | - 'XAG' => 'XAG', |
|
| 171 | - 'XAU' => 'XAU', |
|
| 172 | - 'XCD' => 'AI', |
|
| 173 | - 'XDR' => 'TB', |
|
| 174 | - 'XOF' => 'NE', |
|
| 175 | - 'XPF' => 'PF', |
|
| 176 | - 'YER' => 'YE', |
|
| 177 | - 'ZAR' => 'ZA', |
|
| 178 | - 'ZMK' => 'ZM', |
|
| 179 | - 'ZMW' => 'ZM', |
|
| 180 | - 'ZWL' => 'ZW'); |
|
| 7 | + /** |
|
| 8 | + * country code and currency code contains gold, silver and bitcoin currency |
|
| 9 | + * |
|
| 10 | + * @var array |
|
| 11 | + */ |
|
| 12 | + protected static $countrys = array( |
|
| 13 | + 'AED' => 'AE', |
|
| 14 | + 'AFN' => 'AF', |
|
| 15 | + 'ALL' => 'AL', |
|
| 16 | + 'AMD' => 'AM', |
|
| 17 | + 'ANG' => 'AN', |
|
| 18 | + 'AOA' => 'AO', |
|
| 19 | + 'ARS' => 'AR', |
|
| 20 | + 'AUD' => 'AU', |
|
| 21 | + 'AWG' => 'AW', |
|
| 22 | + 'AZN' => 'AZ', |
|
| 23 | + 'BAM' => 'BA', |
|
| 24 | + 'BBD' => 'BB', |
|
| 25 | + 'BDT' => 'BD', |
|
| 26 | + 'BGN' => 'BG', |
|
| 27 | + 'BHD' => 'BH', |
|
| 28 | + 'BIF' => 'BI', |
|
| 29 | + 'BMD' => 'BM', |
|
| 30 | + 'BND' => 'BN', |
|
| 31 | + 'BOB' => 'BO', |
|
| 32 | + 'BRL' => 'BR', |
|
| 33 | + 'BSD' => 'BS', |
|
| 34 | + 'BTC' => 'BTC', |
|
| 35 | + 'BTN' => 'BT', |
|
| 36 | + 'BWP' => 'BW', |
|
| 37 | + 'BYN' => 'BY', |
|
| 38 | + 'BYR' => 'BY', |
|
| 39 | + 'BZD' => 'BZ', |
|
| 40 | + 'CAD' => 'CA', |
|
| 41 | + 'CDF' => 'CD', |
|
| 42 | + 'CHF' => 'LI', |
|
| 43 | + 'CLF' => 'CL', |
|
| 44 | + 'CLP' => 'CL', |
|
| 45 | + 'CNY' => 'CN', |
|
| 46 | + 'COP' => 'CO', |
|
| 47 | + 'CRC' => 'CR', |
|
| 48 | + 'CUC' => 'CU', |
|
| 49 | + 'CUP' => 'CU', |
|
| 50 | + 'CVE' => 'CV', |
|
| 51 | + 'CZK' => 'CZ', |
|
| 52 | + 'DJF' => 'DJ', |
|
| 53 | + 'DKK' => 'DK', |
|
| 54 | + 'DOP' => 'DO', |
|
| 55 | + 'DZD' => 'DZ', |
|
| 56 | + 'EGP' => 'EG', |
|
| 57 | + 'ERN' => 'ER', |
|
| 58 | + 'ETB' => 'ET', |
|
| 59 | + 'EUR' => 'AD', |
|
| 60 | + 'FJD' => 'FJ', |
|
| 61 | + 'FKP' => 'FK', |
|
| 62 | + 'GBP' => 'IO', |
|
| 63 | + 'GEL' => 'GE', |
|
| 64 | + 'GGP' => 'GG', |
|
| 65 | + 'GHS' => 'GH', |
|
| 66 | + 'GIP' => 'GI', |
|
| 67 | + 'GMD' => 'GM', |
|
| 68 | + 'GNF' => 'GN', |
|
| 69 | + 'GTQ' => 'GT', |
|
| 70 | + 'GYD' => 'GY', |
|
| 71 | + 'HKD' => 'HK', |
|
| 72 | + 'HNL' => 'HN', |
|
| 73 | + 'HRK' => 'HR', |
|
| 74 | + 'HTG' => 'HT', |
|
| 75 | + 'HUF' => 'HU', |
|
| 76 | + 'IDR' => 'ID', |
|
| 77 | + 'ILS' => 'IL', |
|
| 78 | + 'IMP' => 'IM', |
|
| 79 | + 'INR' => 'IN', |
|
| 80 | + 'IQD' => 'IQ', |
|
| 81 | + 'IRR' => 'IR', |
|
| 82 | + 'ISK' => 'IS', |
|
| 83 | + 'JEP' => 'JE', |
|
| 84 | + 'JMD' => 'JM', |
|
| 85 | + 'JOD' => 'JO', |
|
| 86 | + 'JPY' => 'JP', |
|
| 87 | + 'KES' => 'KE', |
|
| 88 | + 'KGS' => 'KG', |
|
| 89 | + 'KHR' => 'KH', |
|
| 90 | + 'KMF' => 'KM', |
|
| 91 | + 'KPW' => 'KP', |
|
| 92 | + 'KRW' => 'KR', |
|
| 93 | + 'KWD' => 'KW', |
|
| 94 | + 'KYD' => 'KY', |
|
| 95 | + 'KZT' => 'KZ', |
|
| 96 | + 'LAK' => 'LA', |
|
| 97 | + 'LBP' => 'LB', |
|
| 98 | + 'LKR' => 'LK', |
|
| 99 | + 'LRD' => 'LR', |
|
| 100 | + 'LSL' => 'LS', |
|
| 101 | + 'LTL' => 'LT', |
|
| 102 | + 'LVL' => 'LV', |
|
| 103 | + 'LYD' => 'LY', |
|
| 104 | + 'MAD' => 'MA', |
|
| 105 | + 'MDL' => 'MD', |
|
| 106 | + 'MGA' => 'MG', |
|
| 107 | + 'MKD' => 'MK', |
|
| 108 | + 'MMK' => 'MM', |
|
| 109 | + 'MNT' => 'MN', |
|
| 110 | + 'MOP' => 'MO', |
|
| 111 | + 'MRO' => 'MR', |
|
| 112 | + 'MUR' => 'MU', |
|
| 113 | + 'MVR' => 'MV', |
|
| 114 | + 'MWK' => 'MW', |
|
| 115 | + 'MXN' => 'MX', |
|
| 116 | + 'MYR' => 'MY', |
|
| 117 | + 'MZN' => 'MZ', |
|
| 118 | + 'NAD' => 'NA', |
|
| 119 | + 'NGN' => 'NG', |
|
| 120 | + 'NIO' => 'NI', |
|
| 121 | + 'NOK' => 'AQ', |
|
| 122 | + 'NPR' => 'NP', |
|
| 123 | + 'NZD' => 'CK', |
|
| 124 | + 'OMR' => 'OM', |
|
| 125 | + 'PAB' => 'PA', |
|
| 126 | + 'PEN' => 'PE', |
|
| 127 | + 'PGK' => 'PG', |
|
| 128 | + 'PHP' => 'PH', |
|
| 129 | + 'PKR' => 'PK', |
|
| 130 | + 'PLN' => 'PL', |
|
| 131 | + 'PYG' => 'PY', |
|
| 132 | + 'QAR' => 'QA', |
|
| 133 | + 'RON' => 'RO', |
|
| 134 | + 'RSD' => 'RS', |
|
| 135 | + 'RUB' => 'RU', |
|
| 136 | + 'RWF' => 'RW', |
|
| 137 | + 'SAR' => 'SA', |
|
| 138 | + 'SBD' => 'SB', |
|
| 139 | + 'SCR' => 'SC', |
|
| 140 | + 'SDG' => 'SD', |
|
| 141 | + 'SEK' => 'SE', |
|
| 142 | + 'SGD' => 'SG', |
|
| 143 | + 'SHP' => 'SH', |
|
| 144 | + 'SLL' => 'SL', |
|
| 145 | + 'SOS' => 'SO', |
|
| 146 | + 'SRD' => 'SR', |
|
| 147 | + 'STD' => 'ST', |
|
| 148 | + 'SVC' => 'SV', |
|
| 149 | + 'SYP' => 'SY', |
|
| 150 | + 'SZL' => 'SZ', |
|
| 151 | + 'THB' => 'TH', |
|
| 152 | + 'TJS' => 'TJ', |
|
| 153 | + 'TMT' => 'TM', |
|
| 154 | + 'TND' => 'TN', |
|
| 155 | + 'TOP' => 'TO', |
|
| 156 | + 'TRY' => 'TR', |
|
| 157 | + 'TTD' => 'TT', |
|
| 158 | + 'TWD' => 'TW', |
|
| 159 | + 'TZS' => 'TZ', |
|
| 160 | + 'UAH' => 'UA', |
|
| 161 | + 'UGX' => 'UG', |
|
| 162 | + 'USD' => 'AS', |
|
| 163 | + 'UYU' => 'UY', |
|
| 164 | + 'UZS' => 'UZ', |
|
| 165 | + 'VEF' => 'VE', |
|
| 166 | + 'VND' => 'VN', |
|
| 167 | + 'VUV' => 'VU', |
|
| 168 | + 'WST' => 'WS', |
|
| 169 | + 'XAF' => 'BJ', |
|
| 170 | + 'XAG' => 'XAG', |
|
| 171 | + 'XAU' => 'XAU', |
|
| 172 | + 'XCD' => 'AI', |
|
| 173 | + 'XDR' => 'TB', |
|
| 174 | + 'XOF' => 'NE', |
|
| 175 | + 'XPF' => 'PF', |
|
| 176 | + 'YER' => 'YE', |
|
| 177 | + 'ZAR' => 'ZA', |
|
| 178 | + 'ZMK' => 'ZM', |
|
| 179 | + 'ZMW' => 'ZM', |
|
| 180 | + 'ZWL' => 'ZW'); |
|
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * check currency code and transform country code to currency code |
|
| 184 | - * |
|
| 185 | - * @param string $data |
|
| 186 | - * @return string|bool |
|
| 187 | - */ |
|
| 188 | - public static function getCurrency($data) |
|
| 189 | - { |
|
| 190 | - $output = false; |
|
| 191 | - $base = array_flip(self::$countrys); |
|
| 192 | - if(strlen($data)==2){ |
|
| 193 | - if(array_key_exists($data, $base)) { |
|
| 194 | - foreach($base as $key => $value){ |
|
| 195 | - if($key==$data) $output = $value; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - }else{ |
|
| 199 | - foreach($base as $key => $value){ |
|
| 200 | - if($value==$data) $output = $value; |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - return $output; |
|
| 204 | - } |
|
| 182 | + /** |
|
| 183 | + * check currency code and transform country code to currency code |
|
| 184 | + * |
|
| 185 | + * @param string $data |
|
| 186 | + * @return string|bool |
|
| 187 | + */ |
|
| 188 | + public static function getCurrency($data) |
|
| 189 | + { |
|
| 190 | + $output = false; |
|
| 191 | + $base = array_flip(self::$countrys); |
|
| 192 | + if(strlen($data)==2){ |
|
| 193 | + if(array_key_exists($data, $base)) { |
|
| 194 | + foreach($base as $key => $value){ |
|
| 195 | + if($key==$data) $output = $value; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + }else{ |
|
| 199 | + foreach($base as $key => $value){ |
|
| 200 | + if($value==$data) $output = $value; |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + return $output; |
|
| 204 | + } |
|
| 205 | 205 | } |
@@ -189,15 +189,15 @@ |
||
| 189 | 189 | { |
| 190 | 190 | $output = false; |
| 191 | 191 | $base = array_flip(self::$countrys); |
| 192 | - if(strlen($data)==2){ |
|
| 193 | - if(array_key_exists($data, $base)) { |
|
| 194 | - foreach($base as $key => $value){ |
|
| 195 | - if($key==$data) $output = $value; |
|
| 192 | + if (strlen($data)==2) { |
|
| 193 | + if (array_key_exists($data, $base)) { |
|
| 194 | + foreach ($base as $key => $value) { |
|
| 195 | + if ($key==$data) $output = $value; |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | - }else{ |
|
| 199 | - foreach($base as $key => $value){ |
|
| 200 | - if($value==$data) $output = $value; |
|
| 198 | + }else { |
|
| 199 | + foreach ($base as $key => $value) { |
|
| 200 | + if ($value==$data) $output = $value; |
|
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | return $output; |
@@ -192,12 +192,16 @@ |
||
| 192 | 192 | if(strlen($data)==2){ |
| 193 | 193 | if(array_key_exists($data, $base)) { |
| 194 | 194 | foreach($base as $key => $value){ |
| 195 | - if($key==$data) $output = $value; |
|
| 195 | + if($key==$data) { |
|
| 196 | + $output = $value; |
|
| 197 | + } |
|
| 196 | 198 | } |
| 197 | 199 | } |
| 198 | - }else{ |
|
| 200 | + } else{ |
|
| 199 | 201 | foreach($base as $key => $value){ |
| 200 | - if($value==$data) $output = $value; |
|
| 202 | + if($value==$data) { |
|
| 203 | + $output = $value; |
|
| 204 | + } |
|
| 201 | 205 | } |
| 202 | 206 | } |
| 203 | 207 | return $output; |
@@ -4,14 +4,14 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface ConverterInterface |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * initial currency conversion |
|
| 9 | - * |
|
| 10 | - * @param string|array $from |
|
| 11 | - * @param string|array $to |
|
| 12 | - * @param float $amount |
|
| 13 | - * @param bool $short |
|
| 14 | - * @return string|array |
|
| 15 | - */ |
|
| 16 | - public function cconv($from, $to, $amount); |
|
| 7 | + /** |
|
| 8 | + * initial currency conversion |
|
| 9 | + * |
|
| 10 | + * @param string|array $from |
|
| 11 | + * @param string|array $to |
|
| 12 | + * @param float $amount |
|
| 13 | + * @param bool $short |
|
| 14 | + * @return string|array |
|
| 15 | + */ |
|
| 16 | + public function cconv($from, $to, $amount); |
|
| 17 | 17 | } |
@@ -4,101 +4,101 @@ |
||
| 4 | 4 | |
| 5 | 5 | class CacheFile |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * check if is cache dir |
|
| 9 | - * |
|
| 10 | - * @return bool |
|
| 11 | - */ |
|
| 12 | - public static function isCacheDir() |
|
| 13 | - { |
|
| 14 | - if(!is_dir(__DIR__ .'/cache/')) mkdir(__DIR__ ."/cache/", 0700); |
|
| 15 | - |
|
| 16 | - return true; |
|
| 17 | - } |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * check if cache file exists |
|
| 21 | - * |
|
| 22 | - * @return bool |
|
| 23 | - */ |
|
| 24 | - public static function isFile() |
|
| 25 | - { |
|
| 26 | - $files = glob(__DIR__ .'/cache/*.txt'); |
|
| 27 | - $count = count($files); |
|
| 28 | - if($count>0){ |
|
| 29 | - $output = true; |
|
| 30 | - }else{ |
|
| 31 | - $output = false; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - return $output; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * get name of cache file |
|
| 39 | - * |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - public static function getFileName() |
|
| 43 | - { |
|
| 44 | - $files = glob(__DIR__ .'/cache/*.txt'); |
|
| 45 | - $file = $files[0]; |
|
| 46 | - $fileName = explode("/cache/", $file); |
|
| 47 | - $fileName = $fileName[1]; |
|
| 48 | - |
|
| 49 | - return $fileName; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * check if cache file is needed to update |
|
| 54 | - * |
|
| 55 | - * @return bool |
|
| 56 | - */ |
|
| 57 | - public static function isCurrent($file) |
|
| 58 | - { |
|
| 59 | - $getSourceName = explode(".", $file); |
|
| 60 | - $getSourceName = $getSourceName[0]; |
|
| 61 | - |
|
| 62 | - $current_time = time(); |
|
| 63 | - if($current_time>$getSourceName){ |
|
| 64 | - $output = false; |
|
| 65 | - }else{ |
|
| 66 | - $output = true; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - return $output; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * create new cache file |
|
| 74 | - * |
|
| 75 | - * @param string|bool $file |
|
| 76 | - * @param array|string $data |
|
| 77 | - * @param int $time |
|
| 78 | - * @return bool |
|
| 79 | - */ |
|
| 80 | - public static function setNewCacheFile($file, $data, $time) |
|
| 81 | - { |
|
| 82 | - if($file) unlink(__DIR__ .'/cache/'.$file); |
|
| 83 | - |
|
| 84 | - $current_time = time(); |
|
| 85 | - $new_time = $current_time + $time*60; |
|
| 86 | - |
|
| 87 | - $file_name = $new_time.".txt"; |
|
| 88 | - file_put_contents(__DIR__ .'/cache/'.$file_name, $data); |
|
| 89 | - |
|
| 90 | - return true; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * get cache data |
|
| 95 | - * |
|
| 96 | - * @return string |
|
| 97 | - */ |
|
| 98 | - public static function getCache($file) |
|
| 99 | - { |
|
| 100 | - $data = file_get_contents(__DIR__ .'/cache/'.$file); |
|
| 101 | - |
|
| 102 | - return $data; |
|
| 103 | - } |
|
| 7 | + /** |
|
| 8 | + * check if is cache dir |
|
| 9 | + * |
|
| 10 | + * @return bool |
|
| 11 | + */ |
|
| 12 | + public static function isCacheDir() |
|
| 13 | + { |
|
| 14 | + if(!is_dir(__DIR__ .'/cache/')) mkdir(__DIR__ ."/cache/", 0700); |
|
| 15 | + |
|
| 16 | + return true; |
|
| 17 | + } |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * check if cache file exists |
|
| 21 | + * |
|
| 22 | + * @return bool |
|
| 23 | + */ |
|
| 24 | + public static function isFile() |
|
| 25 | + { |
|
| 26 | + $files = glob(__DIR__ .'/cache/*.txt'); |
|
| 27 | + $count = count($files); |
|
| 28 | + if($count>0){ |
|
| 29 | + $output = true; |
|
| 30 | + }else{ |
|
| 31 | + $output = false; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + return $output; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * get name of cache file |
|
| 39 | + * |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + public static function getFileName() |
|
| 43 | + { |
|
| 44 | + $files = glob(__DIR__ .'/cache/*.txt'); |
|
| 45 | + $file = $files[0]; |
|
| 46 | + $fileName = explode("/cache/", $file); |
|
| 47 | + $fileName = $fileName[1]; |
|
| 48 | + |
|
| 49 | + return $fileName; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * check if cache file is needed to update |
|
| 54 | + * |
|
| 55 | + * @return bool |
|
| 56 | + */ |
|
| 57 | + public static function isCurrent($file) |
|
| 58 | + { |
|
| 59 | + $getSourceName = explode(".", $file); |
|
| 60 | + $getSourceName = $getSourceName[0]; |
|
| 61 | + |
|
| 62 | + $current_time = time(); |
|
| 63 | + if($current_time>$getSourceName){ |
|
| 64 | + $output = false; |
|
| 65 | + }else{ |
|
| 66 | + $output = true; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + return $output; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * create new cache file |
|
| 74 | + * |
|
| 75 | + * @param string|bool $file |
|
| 76 | + * @param array|string $data |
|
| 77 | + * @param int $time |
|
| 78 | + * @return bool |
|
| 79 | + */ |
|
| 80 | + public static function setNewCacheFile($file, $data, $time) |
|
| 81 | + { |
|
| 82 | + if($file) unlink(__DIR__ .'/cache/'.$file); |
|
| 83 | + |
|
| 84 | + $current_time = time(); |
|
| 85 | + $new_time = $current_time + $time*60; |
|
| 86 | + |
|
| 87 | + $file_name = $new_time.".txt"; |
|
| 88 | + file_put_contents(__DIR__ .'/cache/'.$file_name, $data); |
|
| 89 | + |
|
| 90 | + return true; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * get cache data |
|
| 95 | + * |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 98 | + public static function getCache($file) |
|
| 99 | + { |
|
| 100 | + $data = file_get_contents(__DIR__ .'/cache/'.$file); |
|
| 101 | + |
|
| 102 | + return $data; |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | public static function isCacheDir() |
| 13 | 13 | { |
| 14 | - if(!is_dir(__DIR__ .'/cache/')) mkdir(__DIR__ ."/cache/", 0700); |
|
| 14 | + if (!is_dir(__DIR__.'/cache/')) mkdir(__DIR__."/cache/", 0700); |
|
| 15 | 15 | |
| 16 | 16 | return true; |
| 17 | 17 | } |
@@ -23,11 +23,11 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public static function isFile() |
| 25 | 25 | { |
| 26 | - $files = glob(__DIR__ .'/cache/*.txt'); |
|
| 26 | + $files = glob(__DIR__.'/cache/*.txt'); |
|
| 27 | 27 | $count = count($files); |
| 28 | - if($count>0){ |
|
| 28 | + if ($count>0) { |
|
| 29 | 29 | $output = true; |
| 30 | - }else{ |
|
| 30 | + }else { |
|
| 31 | 31 | $output = false; |
| 32 | 32 | } |
| 33 | 33 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public static function getFileName() |
| 43 | 43 | { |
| 44 | - $files = glob(__DIR__ .'/cache/*.txt'); |
|
| 44 | + $files = glob(__DIR__.'/cache/*.txt'); |
|
| 45 | 45 | $file = $files[0]; |
| 46 | 46 | $fileName = explode("/cache/", $file); |
| 47 | 47 | $fileName = $fileName[1]; |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | $getSourceName = $getSourceName[0]; |
| 61 | 61 | |
| 62 | 62 | $current_time = time(); |
| 63 | - if($current_time>$getSourceName){ |
|
| 63 | + if ($current_time>$getSourceName) { |
|
| 64 | 64 | $output = false; |
| 65 | - }else{ |
|
| 65 | + }else { |
|
| 66 | 66 | $output = true; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -79,13 +79,13 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public static function setNewCacheFile($file, $data, $time) |
| 81 | 81 | { |
| 82 | - if($file) unlink(__DIR__ .'/cache/'.$file); |
|
| 82 | + if ($file) unlink(__DIR__.'/cache/'.$file); |
|
| 83 | 83 | |
| 84 | 84 | $current_time = time(); |
| 85 | 85 | $new_time = $current_time + $time*60; |
| 86 | 86 | |
| 87 | 87 | $file_name = $new_time.".txt"; |
| 88 | - file_put_contents(__DIR__ .'/cache/'.$file_name, $data); |
|
| 88 | + file_put_contents(__DIR__.'/cache/'.$file_name, $data); |
|
| 89 | 89 | |
| 90 | 90 | return true; |
| 91 | 91 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public static function getCache($file) |
| 99 | 99 | { |
| 100 | - $data = file_get_contents(__DIR__ .'/cache/'.$file); |
|
| 100 | + $data = file_get_contents(__DIR__.'/cache/'.$file); |
|
| 101 | 101 | |
| 102 | 102 | return $data; |
| 103 | 103 | } |
@@ -11,7 +11,9 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | public static function isCacheDir() |
| 13 | 13 | { |
| 14 | - if(!is_dir(__DIR__ .'/cache/')) mkdir(__DIR__ ."/cache/", 0700); |
|
| 14 | + if(!is_dir(__DIR__ .'/cache/')) { |
|
| 15 | + mkdir(__DIR__ ."/cache/", 0700); |
|
| 16 | + } |
|
| 15 | 17 | |
| 16 | 18 | return true; |
| 17 | 19 | } |
@@ -27,7 +29,7 @@ discard block |
||
| 27 | 29 | $count = count($files); |
| 28 | 30 | if($count>0){ |
| 29 | 31 | $output = true; |
| 30 | - }else{ |
|
| 32 | + } else{ |
|
| 31 | 33 | $output = false; |
| 32 | 34 | } |
| 33 | 35 | |
@@ -62,7 +64,7 @@ discard block |
||
| 62 | 64 | $current_time = time(); |
| 63 | 65 | if($current_time>$getSourceName){ |
| 64 | 66 | $output = false; |
| 65 | - }else{ |
|
| 67 | + } else{ |
|
| 66 | 68 | $output = true; |
| 67 | 69 | } |
| 68 | 70 | |
@@ -79,7 +81,9 @@ discard block |
||
| 79 | 81 | */ |
| 80 | 82 | public static function setNewCacheFile($file, $data, $time) |
| 81 | 83 | { |
| 82 | - if($file) unlink(__DIR__ .'/cache/'.$file); |
|
| 84 | + if($file) { |
|
| 85 | + unlink(__DIR__ .'/cache/'.$file); |
|
| 86 | + } |
|
| 83 | 87 | |
| 84 | 88 | $current_time = time(); |
| 85 | 89 | $new_time = $current_time + $time*60; |
@@ -4,20 +4,20 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Cache implements CacheInterface |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * change cache parameter |
|
| 9 | - * |
|
| 10 | - * @param bool $is |
|
| 11 | - * @param int $time |
|
| 12 | - * @return bool |
|
| 13 | - */ |
|
| 14 | - public static function setCache($is, $time) |
|
| 15 | - { |
|
| 16 | - if($is==true && is_numeric($time) && is_int($time)){ |
|
| 17 | - $output = true; |
|
| 18 | - }else{ |
|
| 19 | - $output = false; |
|
| 20 | - } |
|
| 21 | - return $output; |
|
| 22 | - } |
|
| 7 | + /** |
|
| 8 | + * change cache parameter |
|
| 9 | + * |
|
| 10 | + * @param bool $is |
|
| 11 | + * @param int $time |
|
| 12 | + * @return bool |
|
| 13 | + */ |
|
| 14 | + public static function setCache($is, $time) |
|
| 15 | + { |
|
| 16 | + if($is==true && is_numeric($time) && is_int($time)){ |
|
| 17 | + $output = true; |
|
| 18 | + }else{ |
|
| 19 | + $output = false; |
|
| 20 | + } |
|
| 21 | + return $output; |
|
| 22 | + } |
|
| 23 | 23 | } |
@@ -13,9 +13,9 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public static function setCache($is, $time) |
| 15 | 15 | { |
| 16 | - if($is==true && is_numeric($time) && is_int($time)){ |
|
| 16 | + if ($is==true && is_numeric($time) && is_int($time)) { |
|
| 17 | 17 | $output = true; |
| 18 | - }else{ |
|
| 18 | + }else { |
|
| 19 | 19 | $output = false; |
| 20 | 20 | } |
| 21 | 21 | return $output; |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | { |
| 16 | 16 | if($is==true && is_numeric($time) && is_int($time)){ |
| 17 | 17 | $output = true; |
| 18 | - }else{ |
|
| 18 | + } else{ |
|
| 19 | 19 | $output = false; |
| 20 | 20 | } |
| 21 | 21 | return $output; |
@@ -4,12 +4,12 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface CacheInterface |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * change cache parameter |
|
| 9 | - * |
|
| 10 | - * @param bool $is |
|
| 11 | - * @param int $time |
|
| 12 | - * @return bool |
|
| 13 | - */ |
|
| 14 | - public static function setCache($is, $time); |
|
| 7 | + /** |
|
| 8 | + * change cache parameter |
|
| 9 | + * |
|
| 10 | + * @param bool $is |
|
| 11 | + * @param int $time |
|
| 12 | + * @return bool |
|
| 13 | + */ |
|
| 14 | + public static function setCache($is, $time); |
|
| 15 | 15 | } |