diff --git a/src/helpers.php b/src/helpers.php index 51ca81d..9fa6f61 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -6,26 +6,32 @@ use ArchTech\Money\Currency; use ArchTech\Money\CurrencyManager; use ArchTech\Money\Money; -/** Create a Money instance. */ -function money(int $amount, Currency|string $currency = null): Money -{ - 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); +if (! function_exists('money')) { + /** Create a Money instance. */ + function money(int $amount, Currency|string $currency = null): Money + { + return new Money($amount, $currency ?? currencies()->getDefault()); } - - return currencies()->getCurrent(); } -/** Get the CurrencyManager instance. */ -function currencies(): CurrencyManager -{ - return app(CurrencyManager::class); +if (! function_exists('currency')) { + /** 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(); + } +} + +if (! function_exists('currencies')) { + /** Get the CurrencyManager instance. */ + function currencies(): CurrencyManager + { + return app(CurrencyManager::class); + } }