Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Default currency template #20

Open
bVNyDUKE opened this issue Mar 25, 2021 · 0 comments
Open

Default currency template #20

bVNyDUKE opened this issue Mar 25, 2021 · 0 comments

Comments

@bVNyDUKE
Copy link

bVNyDUKE commented Mar 25, 2021

Current behavior throws a CurrencyException when the currency code is not found in the predefined templates.
Found this to be problematic when using together with danielme85/laravel-cconverter

I did not want to have to compile and format all the possible currencies I could encounter, so I altered the constructor to use a general template in case no predefined one is found.

public function __construct($code)
    {
        if (! $this->hasCurrency($code)) {
            //throw new CurrencyException("Currency not found: \"{$code}\""); - No longer needed
            $currency = [ 
            'code' => $code,
            'title' => '',
            'symbol' => null,
            'precision' => 2,
            'thousandSeparator' => ' ',
            'decimalSeparator' => ',',
            'symbolPlacement' => 'after'
            ];
        }else $currency = $this->getCurrency($code);
        foreach ($currency as $key => $value) {
            if (property_exists($this, $key)) {
                $this->$key = $value;
            }
        }
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant