Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CursBNR

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

About

Librarie PHP pentru preluarea cursului valutar din Romania

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages