Remove legacy php money_format use, switch to brickmoney
Php 7.4 deprecated the money_format function and we need to move off it to fully support php 7.4 (which we are priortising now). We chose brickmoney as the replacement library.
The main usage is in the CRM_Utils_Money::format() library - this function has a lot of alternate functions depending on input params and we have been working to use more specific functions
I think in the end the main format function would support 3 parameters
- amount (as a float or number)
- currency (as a string)
- use site separators (bool)
The first 2 are pretty straight forward. The latter is the idea that if you are looking at a table of donations you want consistent thousand & decimal separators, currency independent. But if you are presenting data front end you want the selection of Norwegian Kroner to also trigger a switch to appropriate formatting on the page
Some discrete steps we can take are
- instead of calling the function with the only number param call the inner function directly
if ($onlyNumber) {
$amount = self::formatLocaleNumericRoundedByCurrency($amount, $currency);
return $amount;
}
-
do the same for calls that pass $format = '%a' - which has the same impact. (if currency is unknown formatLocaleNumericRoundedByPrecision is an option)
-
fully remove / hard-code the deprecated $moneyValueFormat setting and parameter
if (CRM_Core_Config::singleton()->moneyvalueformat !== '%!i') {
CRM_Core_Error::deprecatedWarning('Having a Money Value format other than !%i is deprecated, please report this on GitLab with the relevant moneyValueFormat you use.');
}
- actually replace the call to money_format.....