money icon indicating copy to clipboard operation
money copied to clipboard

Default Currency

Open soltmar opened this issue 1 year ago • 1 comments

Hi,

First of all, apologise for creating an issue as this is rather a question.

Is there a way to predefine / set default currency ?

I'm dealing only with a single currency and having to call Money::of() with currency parameter isn't needed in my situation.

Since class is final, I cannot obviously extend from it and I don't see any other option than set currency every time.

I believe that Money being currency agnostic might also be helpful for some people.

Any advice would be greatly appreciated.

Thanks

soltmar avatar Jun 28 '24 11:06 soltmar

What about a custom "static decoration"? Something like this:

final class DefaultMoney
{
    public static function of(
        BigNumber|int|float|string $amount,
        ?Context $context = null,
        RoundingMode $roundingMode = RoundingMode::UNNECESSARY,
    ): Money {
        return BrickMoney::of($amount, 'GBP', $context, $roundingMode);
    }
}

C3rb avatar Oct 23 '24 14:10 C3rb