Download the PHP package bentools/currency without Composer
On this page you can find all versions of the php package bentools/currency. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package currency
A very simple, framework-agnostic, PHP library to work with currencies.
Install
composer require bentools/currency:1.0.x-dev
Example use
bentools/currency
respects SOLID principles. So feel free to implement your own:
- CurrencyInterface (simple value object with a
getCode()
method) - ExchangeRateInterface (value object with source currency, target currency and ratio)
- ExchangeRateFactoryInterface (how to instanciate ExchangeRate objects)
- ExchangeRateProviderInterface (provide live or historical rates)
- CurrencyConverterInterface (to convert from one currency to another)
Online rate providers
We provide adapters for popular API providers:
- European Central Bank - free use without limit, EUR-based, ~32 currencies supported
- Fixer.io* - ~170 currencies supported, including cryptocurrencies, EUR-based in free plan
- CurrencyLayer.com* - ~170 currencies supported, including cryptocurrencies, USD-based in free plan
- OpenExchangeRates.org* - ~200 currencies supported, including cryptocurrencies, USD-based in free plan
* Only free plans are currently supported by the built-in adapters. Feel free to submit a PR for supporting paid plans.
Chained exchange rate provider
This provider allow you to chain providers. The 1st one which returns a result wins.
Average exchange rate provider
Get an average exchange rate from different providers. If you provide a tolerance, an exception will be thrown if the difference between the lowest and the highest rate exceeds it.
PSR-16 provider
Cache your exchange rates for the duration of your choice with the PSR-16 decorator:
Doctrine ORM provider
If you store your own exchange rates with Doctrine ORM, the built-in implementation may help:
Framework agnostic
bentools/currency
leverages HttpPlug to connect to the APIs. This means:
- You're free to use any HTTP client (Guzzle 5, Guzzle 6, React, Zend, Buzz, ...) already existing in your project
- By default,
bentools/currency
will automagically discover the client to use - You can enforce a specific client with its specific configuration in any
ExchangeRateProvider
.
Don't forget that most free plans limit to 1000 calls/month, so you'd better configure your Http Client to cache responses. If you use Guzzle 6+, have a look at kevinrob/guzzle-cache-middleware
Tests
./vendor/bin/phpunit
License
MIT
Disclaimer
This library is intended to be easy to use, and aims at covering most common needs. To achieve this, it uses floats
as type hints (but you're free to store as integers and convert back).
Keep in mind that working with floats can lead to inaccurate results when dealing with a big number of digits. Read this for further information.
In short, avoid dealing with big integers or a high number of decimals when using this library if precision matters.
All versions of currency with dependencies
bentools/querystring Version ^1.0
php-http/discovery Version ~1.0
php-http/httplug Version ~1.0|~2.0
php-http/message Version ~1.6
php-http/message-factory Version ~1.0
psr/simple-cache Version ^1.0