imitronov/cbrf-currency-rate

There is no license information available for the latest version (1.0.2) of this package.

1.0.2 2023-02-16 20:32 UTC

This package is auto-updated.

Last update: 2024-05-16 23:21:45 UTC


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(),
);