| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
***** DO NOT CALL ANY FUNCTIONS DIRECTLY FROM THIS FILE ****** |
| 5 |
* |
| 6 |
* This file will be loaded even before the framework is loaded |
| 7 |
* so the $app is not available here, only declare functions here. |
| 8 |
*/ |
| 9 |
|
| 10 |
defined( 'ABSPATH' ) || exit; |
| 11 |
|
| 12 |
if ($app->config->get('app.env') == 'dev') { |
| 13 |
|
| 14 |
$fluentBookingGlobalsDevFile = __DIR__ . '/globals_dev.php'; |
| 15 |
|
| 16 |
is_readable($fluentBookingGlobalsDevFile) && include $fluentBookingGlobalsDevFile; |
| 17 |
} |
| 18 |
|
| 19 |
if (!function_exists('dd')) { |
| 20 |
function dd() // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 21 |
{ |
| 22 |
foreach (func_get_args() as $fluentBookingArg) { |
| 23 |
echo "<pre>"; |
| 24 |
print_r($fluentBookingArg); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r |
| 25 |
echo "</pre>"; |
| 26 |
} |
| 27 |
die(); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
function fluentbookingFormattedAmount($amountInCents, $currencySettings) |
| 32 |
{ |
| 33 |
$default = [ |
| 34 |
'currency_sign' => '', |
| 35 |
'currency_position' => 'left', |
| 36 |
'number_format' => 'comma_separated', // dot_separated |
| 37 |
'decimal_points' => 2, |
| 38 |
]; |
| 39 |
|
| 40 |
$currencySettings = array_merge($default, $currencySettings); |
| 41 |
|
| 42 |
$symbol = $currencySettings['currency_sign']; |
| 43 |
$position = $currencySettings['currency_position']; |
| 44 |
$decimalPoints = $currencySettings['decimal_points']; |
| 45 |
$thousandSeparator = $currencySettings['number_format'] === 'comma_separated' ? ',' : '.'; |
| 46 |
$decimalSeparator = $currencySettings['number_format'] === 'comma_separated' ? '.' : ','; |
| 47 |
|
| 48 |
$amount = number_format($amountInCents / 100, $decimalPoints, $decimalSeparator, $thousandSeparator); |
| 49 |
|
| 50 |
$formats = [ |
| 51 |
'left' => fn() => $symbol . $amount, |
| 52 |
'left_space' => fn() => $symbol . ' ' . $amount, |
| 53 |
'right' => fn() => $amount . $symbol, |
| 54 |
'right_space' => fn() => $amount . ' ' . $symbol, |
| 55 |
]; |
| 56 |
|
| 57 |
return isset($formats[$position]) ? $formats[$position]() : $amount; |
| 58 |
} |
| 59 |
|