Exchange
Exchange is PHP script works with currencies. You can convert price, format add VAT or only render exchange rates.
Here is changelog.
Extension for framework
Installation via composer
$ composer require h4kuna/exchange
How to use
Init object Exchange by ExchangeFactory. Default Driver for read is Cnb, here are others.
For example define own exchange rates:
- 25 CZK = 1 EUR
- 20 CZK = 1 USD
use h4kuna\Exchange;
$exchangeFactory = new Exchange\ExchangeFactory('eur', 'usd', '/tmp/exchange', [
'CZK',
'USD',
'eur', // lower case will be changed to upper case
]);
$exchange = $exchangeFactory->create();
echo $exchange->change(100); // EUR -> USD = 125.0
// use only upper case
echo $exchange->change(100, 'CZK'); // CZK -> USD = 5.0
echo $exchange->change(100, NULL, 'CZK'); // EUR -> CZK = 2500.0
echo $exchange->change(100, 'USD', 'CZK'); // USD -> CZK = 2000.0
Change driver and date
Download history exchange rates. Make new instance of Exchange with history rate.
$exchange = $exchangeFactory->create(new \Datetime('2000-12-30'));
Access and iterator
/* @var $property Exchange\Currenry\Property */
$property = $exchange->getRatingList()['EUR'];
var_dump($property);
foreach ($exchange as $code => $property) {
/* @var $property Exchange\Currenry\Property */
var_dump($property);
}