The Currency Provider allows you to grab all the known Currencies. It also has
query method to pass in
CurrencyProviderQuerys to return various results.
Loop over Currencies
Check if Provider has a Currency
Getting Currency from the Provider
// You can get a Currency like this. If the Currency does not exist // it will throw an exception. // @var CurrencyInterface $currency $currency = $provider->getCurrency('USD'); $code = $currency->getCurrencyCode(); // "USD" $numCode = $currency->getNumericCode(); // 840 $minorUnit = $currency->getMinorUnit(); // 2
CurrencyProvider is usually the one that you will be using most of the
time. It provides most of the ISO 4217 currencies.
XCurrencyProvider gives you access to all of the "X" Currencies. For
example, this provider is where you will find the Currency "XTS" which is
reserved for use in testing.
ChainCurrencyProvider lets you use multiple Currency Providers together at
once. It does not provide any currencies itself.
<?php use SonsOfPHP\Component\Money\CurrencyProvider\ChainCurrencyProvider; use SonsOfPHP\Component\Money\CurrencyProvider\CurrencyProvider; use SonsOfPHP\Component\Money\CurrencyProvider\XCurrencyProvider; $provider = new ChainCurrencyProvider([ new CurrencyProvider(), new XCurrencyProvider(), ]); // You can add additional providers as well $provider->addProvier(new MyCustomCurrencyProvider());