Skip to content

Commit 7ec1969

Browse files
committed
Accounting Format PHP Intl Extension and ICU version checks (minimum PHP 7.4.1 and ICU 53)
1 parent 777a230 commit 7ec1969

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/PhpSpreadsheet/Style/NumberFormat/Wizard/Accounting.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,31 @@ public function __construct(
3838
$this->setLocale($locale);
3939
}
4040

41+
/**
42+
* @throws Exception if the Intl extension and ICU version don't support Accounting formats
43+
*/
4144
protected function getLocaleFormat(): string
4245
{
46+
if (version_compare(PHP_VERSION, '7.4.1', '<')) {
47+
throw new Exception('The Intl extension does not support Accounting Formats below PHP 7.4.1');
48+
}
49+
50+
if ($this->icuVersion() < 53.0) {
51+
throw new Exception('The Intl extension does not support Accounting Formats without ICU 53');
52+
}
53+
4354
$formatter = new Locale($this->fullLocale, NumberFormatter::CURRENCY_ACCOUNTING); // @phpstan-ignore-line
4455

4556
return str_replace('¤', $this->formatCurrencyCode(), $formatter->format());
4657
}
4758

59+
private function icuVersion(): float
60+
{
61+
[$major, $minor] = explode('.', INTL_ICU_VERSION);
62+
63+
return (float) "{$major}.{$minor}";
64+
}
65+
4866
private function formatCurrencyCode(): string
4967
{
5068
if ($this->locale === null) {

0 commit comments

Comments
 (0)