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: 69

Dependents: 0

Suggesters: 0

Stars: 4

Open Issues: 0

v2.0.1 2026-07-21 10:42 UTC

This package is not auto-updated.

Last update: 2026-07-21 12:14:56 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://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 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

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