Comments (12)
Hi, I don't have a problem with introducing a CurrencyProviderInterface
, however I'm reluctant to inject it globally so that it can be used in Money::of()
as a default value. I'm against using any kind of global state here.
IMO, if you're using something else than ISO currencies, you should create your Monies from a factory that gets the provider injected, not from Money::of()
.
from money.
Absolutely I agree. I wouldn't want a secondary provider to come in through Money::of
either That makes no sense to me. However coupling the Provider of Currency to the Money object I think would be beneficial, which means there should be an easy way to override the default. As Money::of
is the general way of doing this, and there's no state to the Money object (agree there too). I think you're right in that a Factory would be the way to go, but would need a way to create a Money object that uses a different provider without maintaining state of that provider.
Any suggestions as to how such a factory might work? If Money::of
doesn't take the provider, but its the way to generate a new object, how does one switch the Provider out?
For my project, i have done the following, any alternative to this?:
function factoryFunc($amount, string $currency, $context, $roundingMode) {
// getCurrencyFromCode fetches `new Currency` from a Collection of a few different CurrencyProviders
$currency = $this->getCurrencyFromCode($currency);
return Money::of($amount, $currency, $context, $roundingMode);
}
from money.
Hi! Nice library, thanks.
However, version 0.8.0 completely removes HRK from the ISO currencies. While this is correct, we have legacy data in Croatian Kuna, and we use Laravel Nova which interfaces directly to Money::of or Money::ofMinor and does not allow us to hook into this and provide a custom new Currency(...) easily.
Is it possible to implement an extension to ISOCurrencyProvider such as addCurrency(new Currency(...)); which adds the new currency to $currencyData for the singleton? This would allow us (or anyone else) to add currencies at boot time and not have to hook deeper into the system.
Thanks for considering!
from money.
@puzzledmonkey I'm generally against adding any kind of global state configuration, as it may have side effects if several parts of your application use brick/money.
What exactly prevents Laravel Nova from using a factory to create Money instances?
from money.
Well I can't modify their code, so for now I've just made a small field class that extends their Currency field and overrides the method that uses Money::of.
I understand you're against any kind of global state configuration, but isn't that kind of what the ISOCurrentProvider singleton's currencyData provides? Of course it's up to you, but I just figured it would help people in our case where a legacy currency has been removed but needs supporting for the forseeable future too.
from money.
Note: for now I just overrode the Nova Currency field method and add the custom currency in as necessary. However I'm not sure this is the best method either because I'm creating a new Currency object for each call to the field. A global setting would only need to instantiate it once.
from money.
Related Issues (20)
- Simple rounding test failed HOT 2
- [feature request] Allow changing default rounding mode HOT 1
- Question: how is operator overloading seemingly working? HOT 5
- ExchangeRateProvider method parameters
- Ability to set default context and rounding mode HOT 3
- Adding/Subtracting Money objects, but can't Multiply/Divide HOT 2
- Laravel issue HOT 1
- Requesting a release for brick/math 0.10 compatibility HOT 3
- json serialization HOT 2
- Add a compareTo method HOT 2
- Missing a few country currencies HOT 5
- allocateWithRemainder() performs no allocation HOT 4
- Adding a `times()` alias
- what is the default value of null price? HOT 2
- Calculations without currency. HOT 1
- Allocate method not working as expected. HOT 2
- Support for lowercase currency
- Is it planned to support the distribution of funds by fractional ratios? HOT 1
- Round to nearsest HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from money.