mirror of
https://github.com/archtechx/money.git
synced 2025-12-12 11:24:03 +00:00
Initial commit
This commit is contained in:
commit
8847454577
33 changed files with 2435 additions and 0 deletions
31
src/helpers.php
Normal file
31
src/helpers.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return currencies()->getCurrent();
|
||||
}
|
||||
|
||||
/** Get the CurrencyManager instance. */
|
||||
function currencies(): CurrencyManager
|
||||
{
|
||||
return app(CurrencyManager::class);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue