Skip to content

Commit 6d1bfeb

Browse files
authored
do not crash on php-intl missing (#3807)
1 parent b27b6c5 commit 6d1bfeb

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

app/Models/Configs.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,27 @@ public function sanity(?string $candidate_value, ?string $message_template = nul
153153
}
154154
break;
155155
case ConfigType::CURRENCY->value:
156-
$bundle = \ResourceBundle::create('en', 'ICUDATA-curr');
157-
$currencies = $bundle->get('Currencies');
158-
$found = false;
159-
foreach ($currencies as $code => $data) {
160-
$found = ($code === $candidate_value);
161-
if ($found) {
162-
break; // we found it, stop searching
156+
try {
157+
$bundle = \ResourceBundle::create('en', 'ICUDATA-curr');
158+
$currencies = $bundle->get('Currencies');
159+
$found = false;
160+
foreach ($currencies as $code => $data) {
161+
$found = ($code === $candidate_value);
162+
if ($found) {
163+
break; // we found it, stop searching
164+
}
165+
}
166+
if (!$found) {
167+
$message = sprintf($message_template, 'a valid ISO 4217 currency code');
168+
break;
163169
}
164-
}
165-
if (!$found) {
166-
$message = sprintf($message_template, 'a valid ISO 4217 currency code');
167170
break;
171+
} catch (\Throwable) {
172+
// @codeCoverageIgnoreStart
173+
$message = 'php-intl extension is missing. Cannot validate currency code.';
174+
break;
175+
// @codeCoverageIgnoreEnd
168176
}
169-
break;
170177
case ConfigType::MAP_PROVIDER->value:
171178
if (MapProviders::tryFrom($candidate_value) === null) {
172179
$message = sprintf($message_template, 'a valid map provider');

0 commit comments

Comments
 (0)