*
* @return string
* formatted monetary amount
- *
- * @throws \CRM_Core_Exception
*/
function smarty_modifier_crmMoney($amount, ?string $currency = NULL): string {
- return Civi::format()->money($amount, $currency);
+ try {
+ return Civi::format()->money($amount, $currency);
+ }
+ catch (CRM_Core_Exception $e) {
+ // @todo escalate this to a deprecation notice. It turns out to be depressingly
+ // common for us to double process amount strings - if they are > 1000 then
+ // they wind up throwing an exception in the money function.
+ // It would be more correct to format in the smarty layer, only.
+ Civi::log()->warning('Invalid amount passed in as money - {money}', ['money' => $amount]);
+ return $amount;
+ }
}
*
* @return string
*
+ * @throws \CRM_Core_Exception
+ *
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/
* add any padding.
*
* @return string
+ * @throws \CRM_Core_Exception
*/
public function number($amount, ?string $locale = NULL, array $attributes = [
NumberFormatter::MIN_FRACTION_DIGITS => 0,
}
// Verify the amount is a number or numeric string/object.
// We cast to string because it can be a BigDecimal object.
- elseif ($amount === TRUE || !is_numeric((string) $amount)) {
+ if ($amount === TRUE || !is_numeric((string) $amount)) {
throw new \CRM_Core_Exception('Invalid value for type money');
}
return (string) $amount;