<?php
/**
* BNR (National Bank of Romania) official rates
*
* Author: punctweb.com <mailto:hide@address.com>
* Version: 0.1
* Started: 12 Sep 2008 22:57
*
* Released under the terms of Creative Commons Attribution-Share Alike 3.0 licence
* http://creativecommons.org/licenses/by-sa/3.0/
*/
class Bnr {
private $data;
/**
* The original source
*/
const BNR_FEED = 'http://www.bnro.ro/nbrfxrates.xml';
/**
* Translate these values in your own language
*/
private $names = array('AUD' => 'Dolarul australian',
'BGN' => 'Leva bulgareasca',
'CAD' => 'Dolarul canadian',
'CHF' => 'Francul elvetian',
'CZK' => 'Coroana ceha',
'DKK' => 'Coroana daneza',
'EGP' => 'Lira egipteana',
'EUR' => 'Euro',
'GBP' => 'Lira sterlina',
'100 HUF' => '100 Forinti maghiari',
'100 JPY' => '100 Yeni japonezi',
'MDL' => 'Leul moldovenesc',
'NOK' => 'Coroana norvegiana',
'PLN' => 'Zlotul polonez',
'RUB' => 'Rubla rusesca',
'SEK' => 'Coroana suedeza',
'SKK' => 'Coroana slovaca',
'TRY' => 'Lira turceasca',
'USD' => 'Dolar SUA',
'XDR' => 'Drept sp. de tragere',
'XAU' => 'Gramul de aur');
public function __construct() {
$this->data = $this->parseFeed();
}
/**
* Parse and load the XML feed
* @return object
*/
private function parseFeed() {
$xml = simplexml_load_file(self::BNR_FEED);
return $xml->Body->Cube->Rate;
}
/**
* Get the currencies: symbols and values (multipliers, also, if it is the case)
* @return array
*/
public function getCurrencies() {
$result = array();
for($i = 0; $i < count($this->data); $i++) {
if((string) $this->data[$i]->attributes()->multiplier != '') {
$result[(string) $this->data[$i]->attributes()->multiplier.' '.(string) $this->data[$i]->attributes()->currency] = (string) $this->data[$i];
} else {
$result[(string) $this->data[$i]->attributes()->currency] = (string) $this->data[$i];
}
}
return $result;
}
/**
* Get the value of a single currency
* @return string
* @param $symbol string
*/
public function getCurrencyValue($symbol) {
$currencies = $this->getCurrencies();
return $currencies[$symbol];
}
/**
* Get the full name of a currency
* @return string | array
* @param $symbol string[optional]
*/
public function getCurrencyName($symbol = '') {
return $symbol != '' ? $this->names[$symbol] : $this->names;
}
}