imitronov/cbrf-currency-rate

此包最新版本(1.0.2)的许可证信息不可用。

1.0.2 2023-02-16 20:32 UTC

This package is auto-updated.

Last update: 2024-09-17 00:09:16 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(),
);