mirror of
https://github.com/archtechx/money.git
synced 2025-12-12 19:34:02 +00:00
Add function_exists() checks
This commit is contained in:
parent
739f8f8af0
commit
efe697b051
1 changed files with 25 additions and 19 deletions
|
|
@ -6,26 +6,32 @@ use ArchTech\Money\Currency;
|
||||||
use ArchTech\Money\CurrencyManager;
|
use ArchTech\Money\CurrencyManager;
|
||||||
use ArchTech\Money\Money;
|
use ArchTech\Money\Money;
|
||||||
|
|
||||||
/** Create a Money instance. */
|
if (! function_exists('money')) {
|
||||||
function money(int $amount, Currency|string $currency = null): Money
|
/** Create a Money instance. */
|
||||||
{
|
function money(int $amount, Currency|string $currency = null): Money
|
||||||
return new Money($amount, $currency ?? currencies()->getDefault());
|
{
|
||||||
}
|
return new Money($amount, $currency ?? currencies()->getDefault());
|
||||||
|
|
||||||
/** Fetch a currency. If no argument is provided, the current currency will be returned. */
|
|
||||||
function currency(Currency|string $currency = null): Currency
|
|
||||||
{
|
|
||||||
if ($currency) {
|
|
||||||
return $currency instanceof Currency
|
|
||||||
? $currency
|
|
||||||
: currencies()->get($currency);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return currencies()->getCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the CurrencyManager instance. */
|
if (! function_exists('currency')) {
|
||||||
function currencies(): CurrencyManager
|
/** Fetch a currency. If no argument is provided, the current currency will be returned. */
|
||||||
{
|
function currency(Currency|string $currency = null): Currency
|
||||||
return app(CurrencyManager::class);
|
{
|
||||||
|
if ($currency) {
|
||||||
|
return $currency instanceof Currency
|
||||||
|
? $currency
|
||||||
|
: currencies()->get($currency);
|
||||||
|
}
|
||||||
|
|
||||||
|
return currencies()->getCurrent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! function_exists('currencies')) {
|
||||||
|
/** Get the CurrencyManager instance. */
|
||||||
|
function currencies(): CurrencyManager
|
||||||
|
{
|
||||||
|
return app(CurrencyManager::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue