Download the PHP package tomwright/currency-php without Composer
On this page you can find all versions of the php package tomwright/currency-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tomwright/currency-php
More information about tomwright/currency-php
Files in tomwright/currency-php
Package currency-php
Short Description A small package to facilitate currency conversions in PHP.
License
Informations about the package currency-php
CurrencyPHP
Installation
Usage
CurrencyPHP is just a basic wrapper. It cannot do conversions out of the box... Saying that... you only need to provide it with the conversion rates.
Rate Fetchers
Rate Fetchers are what CurrencyPHP
uses to get conversion rates. Any Rate Fetcher you create should implement ConversionRateFetcherInterface
.
Existing Rate Fetchers
If you have created your own Rate Fetcher and want it included here, please submit a pull request.
Creating Your Own
The following Rate Fetcher gives you some fixed exchange rates:
- GBP to USD
- USD to GBP
- GBP to CAD
- CAD to USD
Handling unknown conversion rates
One way conversion rates
The above Rate Fetcher has rates for both GBP to USD, and USD to GBP and this works great... but you'll also notice that it has CAD to USD, but no USD to CAD conversion rates. There is some logic implemented so that you only need to store 1 way conversion rates and it will automatically invert the rate if required.
Thanks to this logic, you can run a USD to CAD conversion using the above Rate Fetcher with no problems. The full list of conversion that the above can handle is as follows:
- GBP to USD
- USD to GBP
- GBP to CAD
- CAD to GBP
- CAD to USD
- USD to CAD
Missing conversion rates
If no conversion rate exists at all between the 2 currencies, an UnhandledConversionRate
Exception will be thrown.