svk-digital/laravel-currency
Composer 安装命令:
composer require svk-digital/laravel-currency
包简介
Extensible Laravel package for working with fiat and crypto currency exchange rates.
README 文档
README
svk-digital/laravel-currency is an extensible Laravel package for working with fiat and crypto currency exchange rates. Out of the box it ships with adapters for the Central Bank of Russia DailyInfo web-service, CurrencyFreaks API, and ExchangeRateHost API, but you can plug in any provider via configuration or custom adapters.
Requirements
- PHP ^8.1
- Laravel 9.x, 10.x, 11.x or 12.x
Quick Start
use DateTimeImmutable; use SvkDigital\Currency\Contracts\CurrencyServiceContract; use SvkDigital\Currency\Facades\Currency; use SvkDigital\Currency\ValueObjects\FiatCurrency; final class RatesController { public function __construct(private CurrencyServiceContract $currencyService) {} public function __invoke() { $date = new DateTimeImmutable('2024-11-30'); // Via dependency injection $rate = $this->currencyService ->rate() ->base(new FiatCurrency('RUB')) ->quote(new FiatCurrency('USD')) ->date($date) ->get(); // Or via facade $rate = Currency::rate() ->base(new FiatCurrency('RUB')) ->quote(new FiatCurrency('USD')) ->date($date) ->get(); } }
Installation
composer require svk-digital/laravel-currency
The service provider and facade are auto-discovered by Laravel. Publish the configuration:
php artisan vendor:publish --tag=currency-config
For advanced usage, you can also publish and customize the service provider:
php artisan vendor:publish --tag=currency-provider
Documentation
Full documentation is available in the docs/ directory:
- Getting Started - Installation and basic usage
- Configuration - Package configuration options
- Built-in Adapters - Available adapters (CBR, CurrencyFreaks, ExchangeRateHost)
- Testing - Test your code with fake exchange rates
- Custom Adapters - Create your own adapter and override provider selection
Features
- ✅ Multiple built-in adapters (CBR, CurrencyFreaks, ExchangeRateHost)
- ✅ Support for fiat currencies via ISO-4217 value objects
- ✅ Crypto currency support (via custom adapters)
- ✅ Automatic caching with configurable TTL
- ✅ Custom adapter support
- ✅ Dynamic provider selection
- ✅ Comprehensive error handling
- ✅ Multiple quote currencies in a single request
Built-in Adapters
CBR Adapter
- Central Bank of Russia SOAP service
- RUB base currency only
- Historical rates support
CurrencyFreaks Adapter
- REST API integration
- Any base currency support
- API key required
ExchangeRateHost Adapter
- REST API integration
- Any base currency support
- Optional access key
See Built-in Adapters for detailed information.
Custom Adapters
You can create custom adapters to integrate with any currency provider. The package also allows you to override the service provider to implement dynamic provider selection logic without modifying configuration files.
See Custom Adapters Guide for complete instructions.
Testing
The package provides a fake() method on the Currency facade that allows you to mock exchange rates in your tests without making real API calls, similar to Laravel's Http::fake().
use DateTimeImmutable; use SvkDigital\Currency\Facades\Currency; use SvkDigital\Currency\ValueObjects\FiatCurrency; // In your test setup Currency::fake() ->setRateValue( new FiatCurrency('RUB'), new FiatCurrency('USD'), new DateTimeImmutable('2024-01-01'), 90.5 ); // Now your code will use the fake adapter $rate = Currency::rate() ->base(new FiatCurrency('RUB')) ->quote(new FiatCurrency('USD')) ->date(new DateTimeImmutable('2024-01-01')) ->get();
License
MIT © Internet Design Studio.
svk-digital/laravel-currency 适用场景与选型建议
svk-digital/laravel-currency 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 222 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 12 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「xml」 「soap」 「currency」 「crypto」 「laravel」 「exchange-rates」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 svk-digital/laravel-currency 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 svk-digital/laravel-currency 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 svk-digital/laravel-currency 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
cURL and cURL based Soap-Client for PHP
A PHP client for the Salesforce SOAP API
Load DOM document safety
A Yii2 component for working with TurboSMS.ua SOAP service
Fixer.io data provider for Peso
Zend Framework 1 Soap package
统计信息
- 总下载量: 222
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-02