imitronov / cbrf-currency-rate
Installs: 78
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/imitronov/cbrf-currency-rate
Requires
- php: >=7.1.3||^8.0
- ext-bcmath: *
- ext-simplexml: *
- symfony/http-client: >=4.4
README
Данная библиотека забирает данные о курсе валют от Центрального Банка РФ.
Доки ЦБ РФ по используемой XML: https://cbr.ru/development/SXML/
Установка
composer require imitronov/cbrf-currency-rate
Использование
<?php // ... use Imitronov\CbrfCurrencyRate\Client; $cbrf = new Client(); $currencyRates = $cbrf->getCurrencyRates(); /** * Перебор всех доступных валют */ foreach ($currencyRates as $currencyRate) { echo sprintf( '1 %s = %s RUB' . PHP_EOL, $currencyRate->getCharCode(), $currencyRate->getRate() ); } /** * Получение курса по нужной валюте */ $usdCurrencyRate = $cbrf->getCurrencyRateByCharCode('USD'); echo sprintf( '1 %s = %s RUB', $usdCurrencyRate->getCharCode(), $usdCurrencyRate->getRate(), );