Skip to content

Commit

Permalink
typo
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Oct 11, 2023
1 parent 1d212e3 commit 0f303b0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Expand Up @@ -7,3 +7,4 @@ phpstan-baseline.neon export-ignore
tests export-ignore
*.sh eol=lf
LICENSE export-ignore
examples/
21 changes: 16 additions & 5 deletions README.md
Expand Up @@ -31,13 +31,20 @@ For example define own exchange rates:
- 20 CZK = 1 USD

```php
use h4kuna\Exchange;
use h4kuna\CriticalCache;use h4kuna\Exchange;

$cacheFactory = new CriticalCache\CacheFactory('exchange');

$exchangeFactory = new Exchange\ExchangeFactory('eur', 'usd', '/tmp/exchange', [
$exchangeFactory = new Exchange\ExchangeFactory(
from: 'eur',
to: 'usd',
allowedCurrencies: [
'CZK',
'USD',
'eur', // lower case will be changed to upper case
]);
],
cacheFactory: $cacheFactory
);

$exchange = $exchangeFactory->create();

Expand All @@ -54,14 +61,18 @@ echo $exchange->change(100, 'USD', 'CZK'); // USD -> CZK = 2000.0
Download history exchange rates. Make new instance of Exchange with history rate.

```php
$exchange = $exchangeFactory->create(new \Datetime('2000-12-30'));
use h4kuna\Exchange\RatingList;
use h4kuna\Exchange;

$exchangePast = $exchange->modify(cacheEntity: new RatingList\CacheEntity(new \Datetime('2000-12-30'), Exchange\Driver\Cnb\Day::class));
$exchangePast->change(100);
```

### Access and iterator

```php
/* @var $property Exchange\Currenry\Property */
$property = $exchange->getRatingList()['EUR'];
$property = $exchange['EUR'];
var_dump($property);


Expand Down
46 changes: 46 additions & 0 deletions examples/index.php
@@ -0,0 +1,46 @@
<?php declare(strict_types=1);

require_once __DIR__ . '/../vendor/autoload.php';

use h4kuna\CriticalCache;
use h4kuna\Exchange;
use h4kuna\Exchange\RatingList;

$cacheFactory = new CriticalCache\CacheFactory('exchange');

$exchangeFactory = new Exchange\ExchangeFactory(
from: 'eur',
to: 'usd',
allowedCurrencies: [
'CZK',
'USD',
'eur', // lower case will be changed to upper case
],
cacheFactory: $cacheFactory
);

$exchange = $exchangeFactory->create();

echo $exchange->change(100) . PHP_EOL; // EUR -> USD = 125.0

// use only upper case
echo $exchange->change(100, 'CZK') . PHP_EOL; // CZK -> USD = 5.0
echo $exchange->change(100, null, 'CZK') . PHP_EOL; // EUR -> CZK = 2500.0
echo $exchange->change(100, 'USD', 'CZK') . PHP_EOL; // USD -> CZK = 2000.0
echo PHP_EOL;

// History
$exchangePast = $exchange->modify(cacheEntity: new RatingList\CacheEntity(new \Datetime('2000-12-30'), Exchange\Driver\Cnb\Day::class));
echo $exchangePast->change(100) . PHP_EOL;
echo PHP_EOL;

// Array access
$property = $exchange['EUR'];
var_dump($property);
echo PHP_EOL;

// Iterator
foreach ($exchange as $code => $property) {
/* @var $property Exchange\Currency\Property */
var_dump($code, $property);
}

0 comments on commit 0f303b0

Please sign in to comment.