Skip to content

Commit ac9a767

Browse files
committed
Replace static Currencies.php with league/iso3166 package
Use league/iso3166 for country-to-currency mapping instead of maintaining a static array. This ensures currency data stays up-to-date via the well-maintained ISO 3166-1 package from The PHP League.
1 parent 33ebe46 commit ac9a767

3 files changed

Lines changed: 13 additions & 271 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"ext-curl": "*",
1717
"illuminate/cache": "^12.0 || ^13.0",
1818
"illuminate/console": "^12.0 || ^13.0",
19-
"illuminate/support": "^12.0 || ^13.0"
19+
"illuminate/support": "^12.0 || ^13.0",
20+
"league/iso3166": "^4.0"
2021
},
2122
"require-dev": {
2223
"friendsofphp/php-cs-fixer": "^3.50",

src/GeoIP.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Illuminate\Support\Arr;
88
use Illuminate\Cache\CacheManager;
9+
use League\ISO3166\Exception\OutOfBoundsException;
10+
use League\ISO3166\ISO3166;
911

1012
/**
1113
* @psalm-import-type LocationArray from \InteractionDesignFoundation\GeoIP\Location
@@ -19,13 +21,6 @@ class GeoIP
1921
*/
2022
protected $location = null;
2123

22-
/**
23-
* Currency data.
24-
*
25-
* @var array<string, string>|null
26-
*/
27-
protected $currencies = null;
28-
2924
/**
3025
* GeoIP service instance.
3126
*
@@ -162,11 +157,17 @@ private function find(?string $ip = null): Location
162157
*/
163158
public function getCurrency($iso)
164159
{
165-
if ($this->currencies === null && $this->config('include_currency', false)) {
166-
$this->currencies = include(__DIR__ . '/Support/Currencies.php');
160+
if (! $this->config('include_currency', false)) {
161+
return null;
167162
}
168163

169-
return Arr::get($this->currencies, $iso);
164+
try {
165+
$country = (new ISO3166())->alpha2($iso);
166+
167+
return $country['currency'][0] ?? null;
168+
} catch (OutOfBoundsException) {
169+
return null;
170+
}
170171
}
171172

172173
/**

src/Support/Currencies.php

Lines changed: 0 additions & 260 deletions
This file was deleted.

0 commit comments

Comments
 (0)