itrack / cursbnr
Librarie PHP pentru preluarea cursului valutar din Romania
v2.0.1
2026-07-21 10:42 UTC
Requires
- php: ^7.1 || ^8.0
- ext-libxml: *
- ext-simplexml: *
Requires (Dev)
- phpunit/phpunit: ^7.5.20 || ^8.5 || ^9.6
This package is not auto-updated.
Last update: 2026-07-21 12:14:56 UTC
README
PHP library for fetching the official exchange rates published by BNR (the National Bank of Romania).
Requirements
- PHP 7.1+ (tested up to PHP 8.5)
- the
simplexmlextension
Installation
composer require itrack/cursbnr
Usage
use Itrack\CursBNR\CursBNR; $curs = new CursBNR(); // downloads https://www.bnr.ro/nbrfxrates.xml echo $curs->getCurs('EUR'); // the value as published by BNR, e.g. 4.975 echo $curs->getRate('HUF'); // per-unit rate (takes the multiplier into account) echo $curs->getMultiplier('HUF'); // 100 echo $curs->getDate(); // publishing date, e.g. 2026-07-21 $curs->hasCurrency('USD'); // true $curs->getCurrencies(); // ['AED', 'AUD', ... 'EUR', ...]
You can also build the object from an already fetched XML document (e.g. from a cache), without any HTTP request:
$curs = CursBNR::fromXml($xmlString);
Exceptions
All errors throw exceptions from the Itrack\CursBNR namespace:
CursBNRException- connection problems or invalid XML responseUnknownCurrencyException- the requested currency is not part of the BNR feed (extendsCursBNRException)
Both extend \RuntimeException, so an existing catch (\Exception $e)
keeps working.
Tests
composer install
composer test
The tests run against a local XML fixture, without network access. To also run the test against the live BNR feed:
CURSBNR_NETWORK_TESTS=1 composer test