itrack/cursbnr

Librarie PHP pentru preluarea cursului valutar din Romania

Maintainers

Package info

github.com/itrack/CursBNR

pkg:composer/itrack/cursbnr

Transparency log

Statistics

Installs: 80

Dependents: 0

Suggesters: 0

Stars: 4

Open Issues: 0

v2.0.2 2026-08-07 07:50 UTC

This package is auto-updated.

Last update: 2026-08-07 07:59:58 UTC


README

CI

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 simplexml extension

Installation

composer require itrack/cursbnr

Usage

use Itrack\CursBNR\CursBNR;

$curs = new CursBNR(); // downloads https://curs.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 response
  • UnknownCurrencyException - the requested currency is not part of the BNR feed (extends CursBNRException)

Both extend \RuntimeException, so an existing catch (\Exception $e) keeps working.

Tests

composer install
composer test

By default the tests run against a local XML fixture, without network access. To also run the live tests against the BNR feed:

CURSBNR_NETWORK_TESTS=1 composer test

The live tests (tests/LiveFeedTest.php) check that the default URL still answers with 200 and XML without redirecting, that the document keeps its structure (Header/PublishingDate, Body/Cube/Rate, currency and multiplier attributes), that the publishing date is recent, and that the rates are plausible. They are what tells you BNR moved or changed the feed.