This package provides some extensions for mathiasverraes/money.
Via Composer
$ composer require indigophp/moneySee the list of extensions bellow:
- DBAL type
- Exchange
The extensions are kept in the same namespace as the extended library (either Money or any third-party).
You can use this extension to create CurrencyPairs with conversion rate from a third party source.
use Money\Exchange;
use Money\Provider\Local;
use Money\Currency;
$exchange = new Exchange(new Local(['EUR' => ['USD' => 1.25]]));
$baseCurrency = new Currency('EUR');
$currencyCurrency = new Currency('USD');
$currencyPair = $exchange->getCurrencyPair($baseCurrency, $counterCurrency);
// returns 1.25
$currencyPair->getConversionRate();Currently (WIP) the following Providers are availaible:
- Local (array)
- Batch
- Yahoo Finance
- Open Exchange Rates
- Rate Exchange (Appspot)
- Currency API (Appspot)
- WebserviceX
- European Central Bank
Most of the providers use third party public APIs.
You can store conversion rates locally and use them as an array source using this provider. The array MUST be an associative array of base currencies containing an associative array of rates indexed by counter currencies. Rates MUST be numeric (CAN be string).
use Money\Provider\Local;
$provider = new Local(['EUR' => ['USD' => 1.25]]);General scheme for array representation:
[
'baseCurrency' => [
'counterCurrency1' => <rate1>,
'counterCurrency2' => <rate2>,
],
]Third party services are not always reliable. With Batch provider you can build up a stack of Providers and try getting the appropriate rate until one is returned.
use Money\Provider\Batch;
use Money\Provider\Local;
$provider = new Batch;
$provider->addProvider(new Local(['EUR' => ['USD' => 1.25]]));$ phpspec runPlease see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.