Skip to content

Commit f639e81

Browse files
committed
Refactor Currency Map
1 parent 1da4388 commit f639e81

File tree

3 files changed

+2918
-2343
lines changed

3 files changed

+2918
-2343
lines changed

lib/Money/Currency.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ class Currency
1515
/** @var string */
1616
private $name;
1717

18-
/** @var array */
19-
private $map;
20-
2118
/** @var string */
2219
private $symbol;
2320

@@ -38,30 +35,22 @@ class Currency
3835
* @throws UnknownCurrencyException
3936
*/
4037
public function __construct($name)
41-
{
42-
43-
$json_data = file_get_contents(__DIR__.'/currencymap.json');
44-
$this->map = json_decode($json_data, true);
45-
46-
47-
$key = strtolower($name);
48-
49-
if (array_key_exists($key, $this->map))
38+
{
39+
if ($map = CurrencyMap::get($name))
5040
{
5141
$this->name = $name;
52-
$this->symbol = $this->map[$key]['symbol'];
53-
$this->multiplier = $this->map[$key]['subunit_to_unit'];
54-
$this->decimals = $this->map[$key]['decimal_mark'];
55-
$this->thousands = $this->map[$key]['thousands_separator'];
56-
$this->symbolFirst = $this->map[$key]['symbol_first'];
42+
$this->symbol = $map['symbol'];
43+
$this->multiplier = $map['subunit_to_unit'];
44+
$this->decimals = $map['decimal_mark'];
45+
$this->thousands = $map['thousands_separator'];
46+
$this->symbolFirst = $map['symbol_first'];
5747
}
5848
else
5949
{
6050
throw new UnknownCurrencyException($name);
6151
}
6252
}
6353

64-
6554
/**
6655
* @return string
6756
*/

0 commit comments

Comments
 (0)