-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExchangeRateTrait.php
More file actions
54 lines (45 loc) · 1.53 KB
/
ExchangeRateTrait.php
File metadata and controls
54 lines (45 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
include "ExchangeRateLoader.php";
trait ExchangeRateTrait{
public function getDataByCountry(string $name): array{
$json = $this->toJSON();
if ($json["result"] !== self::RESULT_SUCCESS) {
return ["Error" => $this->toErrorConvert($json["result"])];
}
foreach ($json as $arr) {
foreach ($arr as $key => $value) {
if ($key !== "cur_nm")
continue;
if (strpos($value, $name) !== false)
return $arr[$key];
}
}
return ["Error" => "Not Found Country Data."];
}
/**
* 나라 데이터에서 원하는 데이터를 출력합니다.
*
* @param string $name
* @param string $key
* @return int|string|null
*/
public function getSearchKeyByCountryData(string $name, string $key) {
$data = $this->getDataByCountry($name);
try {
if (isset($data["Error"])) {
throw new ExchangeRateException($data["Error"]);
}
} catch (ExchangeRateException $exception) {
$ref = new ReflectionClass(ExchangeRateLoader::class);
$logger = false;
if ($ref->hasProperty("logger")) {
$logger = $ref->getProperty("logger")->getValue();
}
if ($logger) {
echo $exception->getMessage();
}
} finally {
return $data[$key] ?? null;
}
}
}