定制 slonline/exchangerates 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

slonline/exchangerates

最新稳定版本:6.0.4

Composer 安装命令:

composer require slonline/exchangerates

包简介

Exchange rates - Module for SilverStripe 6

README 文档

README

Requirements

  • silverstripe/framework ~6.0

Installation

Add the following code to the require key in composer.json file:

composer require slonline/exchangerates

Add configuration into yml, like this:

SLONline\ExchangeRates\ExchangeRates:
  registered_processor: SLONline\ExchangeRates\Processor\ECB
  supported_currencies:
    - EUR
    - USD

Loading data

Data can be loaded via sake command

php vendor/silverstripe/framework/bin/sake process:exchangerates

or in script by calling

SLONline\ExchangeRates\ExchangeRates::create()->process();

or

SLONline\ExchangeRates\ExchangeRates::singleton()->process();

Converting amount from the basic currency to the second

  1. Getting the latest value
SLONline\ExchangeRates\ExchangeRates::singleton()->getExchangeRate('EUR','USD');
  1. Getting the value for specific date if exists
SLONline\ExchangeRates\ExchangeRates::singleton()->getExchangeRate('EUR','USD', '2025-10-30');

Calling it via singleton is recommended to avoid multiple loading of rates from database.

Conversion is available on DBMoney field via extension

First method for getting converted value from base currency to target currency.

$money = DBMoney::create('money')->setAmount( 100)->setCurrency('EUR');
Debug::dump($money->getAmountInCurrency('USD')); // will output amount converted to USD

Debug::dump($money->getInAllSupportedCurrencies()); // will output ArrayList with amounts in all supported currencies

Processors

Processor is main class for downloading, parsing and writing exchange rates from some source. Processed data are stored into data objects ExchangeRate

Available processors

  1. ECB - European Central Bank
SLONline\ExchangeRates\ExchangeRates:
  registered_processor: SLONline\ExchangeRates\Processor\ECB
  1. CNB - Czech National Bank
SLONline\ExchangeRates\ExchangeRates:
  registered_processor: SLONline\ExchangeRates\Processor\CNB

Adding new processor

If you want to add new source of rates, you can create new processor. Each processor should implement ProcessorInterface.

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2025-10-30