<?php
 namespace App\CurrencyExchange; class System_NbpPL extends SystemAbstract { protected $referenceCurrency='PLN'; protected $systemAddress='http://www.nbp.pl/kursy/xml/LastA.xml'; public function getRates() { $responseString=$this->systemResponse(); $responseXml = simplexml_load_string($responseString); if (!$responseXml) throw new Exception("The external system's  reply was not a well formed XML."); $result=[]; if ($responseXml->pozycja) { foreach ($responseXml->pozycja as $thisCurrXml) { $curr = (String)$thisCurrXml->kod_waluty; $rate = (Float)str_replace(',', '.', (String)$thisCurrXml->kurs_sredni); $mul = (float)$thisCurrXml->przelicznik; if ($mul>1) $realRate = $rate/$mul; else $realRate=$rate; if ($curr and $realRate>0) { $result[$curr]=$realRate; } } } return $result; } } 