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(7mo ago)2442.9k↓33.3%131MITPHPPHP &gt;=8.2CI passing

Since Oct 12Pushed 7mo 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 1mo 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

57

—

FairBetter than 98% of packages

Maintenance65

Regular maintenance activity

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

215d 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

[getbrevo/brevo-php

Official Brevo provided RESTFul API V3 php library

963.1M35](/packages/getbrevo-brevo-php)[swisnl/json-api-client

A PHP package for mapping remote JSON:API resources to Eloquent like models and collections.

211473.2k12](/packages/swisnl-json-api-client)[wordpress/php-ai-client

A provider agnostic PHP AI client SDK to communicate with any generative AI models of various capabilities using a uniform API.

26236.6k14](/packages/wordpress-php-ai-client)[yoti/yoti-php-sdk

Yoti SDK for quickly integrating your PHP backend with Yoti

27539.9k1](/packages/yoti-yoti-php-sdk)[prokerala/astrology-sdk

Prokerala.com Astrology API Client Library for PHP.

2610.0k](/packages/prokerala-astrology-sdk)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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