PHPackages                             h4kuna/exchange - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. h4kuna/exchange

ActiveLibrary[API Development](/categories/api)

h4kuna/exchange
===============

Exchange between currencies.

v7.1.5(8mo ago)2444.0k↓26.4%131MITPHPPHP &gt;=8.2CI passing

Since Oct 12Pushed 8mo ago5 watchersCompare

[ Source](https://github.com/h4kuna/exchange)[ Packagist](https://packagist.org/packages/h4kuna/exchange)[ Docs](https://github.com/h4kuna/exchange)[ Fund](https://revolut.me/milan2m/czk1000/exchange)[ GitHub Sponsors](https://github.com/h4kuna)[ RSS](/packages/h4kuna-exchange/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (9)Dependencies (15)Versions (48)Used By (1)

Exchange
--------

[](#exchange)

[![Downloads this Month](https://camo.githubusercontent.com/2c3669b2a487539b22a0f2d7f9874ea6ffd3b285272ac63286304068bbdd2b8e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f68346b756e612f65786368616e67652e737667)](https://packagist.org/packages/h4kuna/exchange)[![Latest Stable Version](https://camo.githubusercontent.com/605585dbda7228ac33d6cb6a73f1e659e3a2b5dbaf37db24e76770cab26dbe8a/68747470733a2f2f706f7365722e707567782e6f72672f68346b756e612f65786368616e67652f762f737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/h4kuna/exchange)[![Coverage Status](https://camo.githubusercontent.com/9f94e2f7231bfed7ad85e7d59596a51ace2a1eb1596ce246b01bf2e80c6a6950/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f68346b756e612f65786368616e67652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/h4kuna/exchange?branch=master)[![Total Downloads](https://camo.githubusercontent.com/a9fa0642c6ea72a805d43d303625989ede12f50ea50c6ae4524a7d329711186e/68747470733a2f2f706f7365722e707567782e6f72672f68346b756e612f65786368616e67652f646f776e6c6f6164733f666f726d61743d666c6174)](https://packagist.org/packages/h4kuna/exchange)[![License](https://camo.githubusercontent.com/bc62578fe22602a2a62b25a705f893b0f1013b7c3fc87a47f81c09831afcf946/68747470733a2f2f706f7365722e707567782e6f72672f68346b756e612f65786368616e67652f6c6963656e73653f666f726d61743d666c6174)](https://packagist.org/packages/h4kuna/exchange)

Exchange is PHP script works with currencies. You can convert price.

Here is [changelog](changelog.md).

Extension for framework
-----------------------

[](#extension-for-framework)

- [Nette extension](//github.com/h4kuna/exchange-nette)

Installation via composer
-------------------------

[](#installation-via-composer)

```
$ composer require h4kuna/exchange
```

Optional packages

```
$ composer require malkusch/lock guzzlehttp/guzzle guzzlehttp/psr7 h4kuna/dir nette/caching
```

Support PSR-6 for cache.

How to use
----------

[](#how-to-use)

Init object [Exchange](src/Exchange.php) by [ExchangeFactory](src/ExchangeFactory.php). Default Driver for read is [Cnb](src/Driver/Cnb/Day.php), [here are others](src/Driver).

For example define own exchange rates:

- 25 CZK = 1 EUR
- 20 CZK = 1 USD

```
use h4kuna\Exchange\Currency\Property;
use h4kuna\Exchange\Driver\Cnb\Day;
use h4kuna\Exchange\Exchange;
use h4kuna\Exchange\ExchangeFactory;
use h4kuna\Exchange\RatingList\CacheEntity;
use h4kuna\Exchange\RatingList\RatingList;

{ # by factory
	$exchangeFactory = new ExchangeFactory(
		from: 'eur',
		to: 'usd',
		allowedCurrencies: [
			'CZK',
			'USD',
			'eur', // lower case will be changed to upper case
		],
	);

	$exchange = $exchangeFactory->create();
}

{ # custom RatingList
	$ratingList = new RatingList(new DateTimeImmutable(), new DateTimeImmutable(), null, [
		'EUR' => new Property(1, 25.0, 'EUR'),
		'USD' => new Property(1, 20.0, 'USD'),
		'CZK' => new Property(1, 1.0, 'CZK'),
	]);
	$exchange = new Exchange('EUR', $ratingList, 'USD');
}

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
```

### Change driver and date

[](#change-driver-and-date)

Download history exchange rates. Make new instance of Exchange with history rate.

```
use h4kuna\Exchange\RatingList;
use h4kuna\Exchange;

$exchangePast = $exchangeFactory->create(cacheEntity: new CacheEntity(new Datetime('2000-12-30'), new Day));
echo $exchangePast->change(100) . PHP_EOL;
```

### Access and iterator

[](#access-and-iterator)

```
use h4kuna\Exchange\Currency\Property;
/* @var $property Property */
$property = $exchange['EUR'];
var_dump($property);
echo PHP_EOL;

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

Caching
-------

[](#caching)

The cache invalid automatic at some time, defined by property `SourceData::$refresh`. From this property is counted time to live. Little better is invalid cache by cron. Because one request on server does not lock other requests. Let's run cron max. 29 minutes before invalidate cache.

```
use h4kuna\Exchange\RatingList\RatingListCache;
use h4kuna\Exchange\RatingList\CacheEntity;
use h4kuna\Exchange\Driver\Cnb\Day;

/** @var RatingListCache $ratingListCache */
$ratingListCache->rebuild(new CacheEntity(null, new Day));
```

In example, is used `h4kuna\Exchange\Driver\Cnb\Day::$refresh` is defined at 14:30 + 30 minute the cache is valid. Run cron 14:32 every day.

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance59

Moderate activity, may be stable

Popularity40

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity88

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 98.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~103 days

Recently: every ~112 days

Total

47

Last Release

261d ago

Major Versions

v3.3.4 → v4.0.12013-10-08

v4.2.2 → v5.0.02017-08-14

v5.0.2 → v6.0.02019-02-21

v6.0.5 → v7.0.02022-12-22

PHP version history (4 changes)v3.1.0PHP &gt;=5.3.2

v6.0.0PHP &gt;=7.1

v7.0.0PHP &gt;=8.0

v7.1.4PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/54b4efb9b89167fa3598b1a41477b20387390f4a0fb65b447bd6bb7c30a49020?d=identicon)[h4kuna](/maintainers/h4kuna)

---

Top Contributors

[![h4kuna](https://avatars.githubusercontent.com/u/335722?v=4)](https://github.com/h4kuna "h4kuna (169 commits)")[![foxycode](https://avatars.githubusercontent.com/u/1284781?v=4)](https://github.com/foxycode "foxycode (2 commits)")

---

Tags

apibankcnbecbexchange

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/h4kuna-exchange/health.svg)

```
[![Health](https://phpackages.com/badges/h4kuna-exchange/health.svg)](https://phpackages.com/packages/h4kuna-exchange)
```

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[mollie/mollie-api-php

Mollie API client library for PHP. Mollie is a European Payment Service provider and offers international payment methods such as Mastercard, VISA, American Express and PayPal, and local payment methods such as iDEAL, Bancontact, SOFORT Banking, SEPA direct debit, Belfius Direct Net, KBC Payment Button and various gift cards such as Podiumcadeaukaart and fashioncheque.

60216.0M85](/packages/mollie-mollie-api-php)[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[getbrevo/brevo-php

Official Brevo provided RESTFul API V3 php library

1003.9M50](/packages/getbrevo-brevo-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
