1 | <?php |
||
12 | final class CurrencyFactory implements CurrencyFactoryContract |
||
13 | { |
||
14 | const DEFAULT_DATA_PATH = __DIR__.'/Data/CurrencyTypes.php'; |
||
15 | |||
16 | /** @var array */ |
||
17 | private $data; |
||
18 | |||
19 | /** @var Currency[] */ |
||
20 | private $currencies; |
||
21 | |||
22 | 128 | private function __construct(array $data) |
|
27 | |||
28 | 128 | public static function fromDataPath(string $dataPath = self::DEFAULT_DATA_PATH): CurrencyFactory |
|
35 | |||
36 | 138 | public static function fromDataArray(array $data): CurrencyFactory |
|
42 | |||
43 | /** |
||
44 | * @param array $currenciesData |
||
45 | * |
||
46 | * @throws InvalidCurrenciesDataError |
||
47 | */ |
||
48 | 138 | private static function validateCurrenciesData(array $currenciesData) |
|
65 | |||
66 | 128 | private static function hasValidISOCode($ISOCode): bool |
|
70 | |||
71 | 128 | private static function hasValidSymbol(array $currencyData): bool |
|
78 | |||
79 | 128 | private static function hasValidSymbolPlacement(array $currencyData): bool |
|
80 | { |
||
81 | return |
||
82 | 128 | isset($currencyData['symbolPlacement']) |
|
83 | 128 | && \is_int($currencyData['symbolPlacement']) |
|
84 | 128 | && \in_array( |
|
85 | 128 | $currencyData['symbolPlacement'], |
|
86 | [ |
||
87 | 128 | CurrencyContract::BEFORE_PLACEMENT, |
|
88 | CurrencyContract::AFTER_PLACEMENT, |
||
89 | ] |
||
90 | ); |
||
91 | } |
||
92 | |||
93 | 128 | private static function hasValidNumFractionalDigits(array $currencyData): bool |
|
97 | |||
98 | 129 | public function buildFromISOCode(string $ISOCode): CurrencyContract |
|
118 | |||
119 | /** @return string[] */ |
||
120 | 1 | public function getSupportedCurrencyISOCodes(): array |
|
124 | } |
||
125 |