h4kuna / exchange
Exchange between currencies.
Installs: 29 711
Dependents: 1
Suggesters: 0
Security: 0
Stars: 22
Watchers: 6
Forks: 14
Open Issues: 1
Requires
- php: >=8.0
- h4kuna/critical-cache: ^0.1.2
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0 || ^2.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.0
- h4kuna/dir: ^0.1.2
- malkusch/lock: ^2.2
- nette/caching: ^3.2
- nette/tester: ^2.0
- phpstan/phpstan: ^1.0
- phpstan/phpstan-strict-rules: ^1.4
- tracy/tracy: ^2.0
Suggests
- ext-simplexml: If you want to use h4kuna\Exchange\Driver\Ecb.
- guzzlehttp/guzzle: As default implementation for PSR standards.
This package is auto-updated.
Last update: 2023-05-31 13:18:38 UTC
README
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); }