PHPackages                             viaaurea/currency - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. viaaurea/currency

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

viaaurea/currency
=================

Cross-currency money comparison and exchange tool.

2.3.2(1y ago)19.9k↓20%MITPHPPHP ^8 || ^7.4

Since Jan 24Pushed 1y ago3 watchersCompare

[ Source](https://github.com/viaaurea/currency)[ Packagist](https://packagist.org/packages/viaaurea/currency)[ RSS](/packages/viaaurea-currency/feed)WikiDiscussions trunk Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (7)Used By (0)

Currency
========

[](#currency)

[![Test Suite](https://github.com/viaaurea/currency/actions/workflows/php-test.yml/badge.svg)](https://github.com/viaaurea/currency/actions/workflows/php-test.yml)[![PHP from Packagist](https://camo.githubusercontent.com/6156f65d66bba93db2c8f225b2d148405a4026d66b4da0d0335f2d8afd757d0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f76696161757265612f63757272656e6379)](https://camo.githubusercontent.com/6156f65d66bba93db2c8f225b2d148405a4026d66b4da0d0335f2d8afd757d0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f76696161757265612f63757272656e6379)[![Powered by](https://camo.githubusercontent.com/ef58b3a2f258dffa991971f774630b0eebe18ebbfc586e19f4fe99a31fd01f0e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f62792d56696125323041757265612d6f72616e6765)](https://www.viaaurea.cz/)

**Cross-currency money comparison and exchange tool.** Framework agnostic.

> 💿 `composer require viaaurea/currency`
>
> 📖 [Czech/Slovak readme version](readme_cs.md).

Use this package to do comparison arithmetic or aggregations on values in different currencies or exchange money in one currency to another.

```
// resolve the service / get an instance
$cs = $container->get(VA\Currency\CurrencyService::class);

// create a money value object (3 equivalent ways)
$cs->create(100, 'USD');
new Money(100, 'USD');
Money::USD(100);

// exchange / conversion
$valueInUsd = Money::USD(100);
$valueInEur = $cs->exchange($valueInUsd, 'EUR');
$valueInEur->amount();

// comparison arithmetic
// <  >= == !=
$cs->greaterThan($valueInUsd, $valueInForeignCurrency); // or $cs->gt( ... )

// diff mixed currencies
$diff = $cs->diff($valueInEur, $valueInForeignCurrency);

// aggregate an array of Money objects with unknown or mixed currencies:
// sum, average, max or min value
$money = [ $valueInEur, $valueInUsd, $valueInForeignCurrency, ... ];
$sum = $cs->sum($money);
$max = $cs->max($money);
$min = $cs->min($money);
$avg = $cs->avg($money);
```

> 💡
> This package is meant as a **lightweight tool** to exchange, compare and aggregate money value objects.
> For a fully fledged robust solution consider using [Money for PHP](https://moneyphp.org/en/stable/).

Currency Service
----------------

[](#currency-service)

`CurrencyService` is the main service class used for conversions and arithmetics. Its main dependency is an implementation of an **exchange rate provider**.
During comparison operations or aggregations between money objects with different currencies exchange to one of the currencies must happen.
The provider provides exchange rates for these conversions as well as for explicit conversions using `CurrencyService::exchange` method.

Currently only one implementation is delivered with this package - the `StaticExchange`, however, it is trivial to provide your own implementation according to your needs (database, third party API fetches etc.).

Configuration
-------------

[](#configuration)

The exchange rates are defined and passed to the `StaticExchange` class, which is then used by the `CurrencyService`. You can also provide your own exchange rate provider simply by implementing the `ExchangeRateProviderInterface` interface.

The rates are defined in relation to a reference/base/local currency.

For *directly* quoted reference currencies (USD, CAD, JPY, CZK, ...):

```
$container->register(CurrencyService::class, function(){
    $rates = [
        'EUR' => 0.9,
        'JPY' => 100,
        'AUD' => 1.5,
    ];
    $provider = new StaticExchange('USD', $rates, StaticExchange::RATE_DIRECT);
    return new CurrencyService($provider);
});
```

For *indirectly* quoted reference currencies (EUR, GBP, AUD, ...):

```
$container->register(CurrencyService::class, function(){
    $rates = [
        'USD' => 1.1,
        'JPY' => 120,
        'AUD' => 1.6,
    ];
    $provider = new StaticExchange('EUR', $rates, StaticExchange::RATE_INDIRECT);
    return new CurrencyService($provider);
});
```

> 💡 You are not required to use a service container, in which case just assign the instance to a variable...

It is possible to specify amount of units with the rate. It can be used for currencies where the difference to the base currency is very high (certain African currencies, Bitcoin, etc.). To do that, pass in an array with the rate and amount:

```
$rates = [
    // rate for Bitcoin may be specified in micro-Bitcoins:
    'XBT' => [0.5, 0.001],
];
```

Usage
-----

[](#usage)

See the examples at the beginning of this file above and see the [source code of `CurrencyService` class](src/CurrencyService.php) for full list of available methods.

Fine-grain exchanges
--------------------

[](#fine-grain-exchanges)

The `exchange` method, as well as every comparison or aggregation method of `CurrencyService` accepts a **variadic list of arguments** that is passed down to the calls to underlying exchange rate provider. This can be leveraged to enable calculation of historic currency values, buy/sell/middle rates and so on.

Examples:

```
$cs->exchange(
    $cs->create(100, 'EUR'),
    'USD',
    Carbon::parse('last saturday')
);

$cs->diff(
    $cs->create(100, 'EUR'),
    $cs->create(100, 'USD'),
    Carbon::parse('2017-11-23'),
    'buy'
);
```

To use this functionality, a custom provider needs to be implemented, example:

```
class DatabaseRateProvider implements ExchangeRateProviderInterface {

    function getExchangeRate(
        Currency $target,
        Currency $from,
        DateTimeInterface $at,
        string $direction = 'middle'
    ){
        // your logic here
        // return exchange rate at a given point in time and for the specified direction
    }

}
```

> Tip: use the `ExchangeHelper` class to easily implement a custom provider.

Nette DI extension
------------------

[](#nette-di-extension)

Contains an extension for the Nette framework. See the [Czech/Slovak readme version](readme_cs.md).

Contributions
-------------

[](#contributions)

... are welcome.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~352 days

Recently: every ~327 days

Total

6

Last Release

542d ago

PHP version history (2 changes)2.0PHP ^7.1

2.1PHP ^8 || ^7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/0bd7fa945013e9c0dcd65693575276bf5fcb9b9de13e1123e9f2c4a0a4c0fb6b?d=identicon)[dakujem](/maintainers/dakujem)

---

Top Contributors

[![dakujem](https://avatars.githubusercontent.com/u/443067?v=4)](https://github.com/dakujem "dakujem (19 commits)")

### Embed Badge

![Health badge](/badges/viaaurea-currency/health.svg)

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

PHPackages © 2026

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