alimranahmed/ecb-exchange
Composer 安装命令:
composer require alimranahmed/ecb-exchange
包简介
PHP package for ECB currency exchange rates with fluent API and SOLID architecture
README 文档
README
ECB Exchange Rate PHP Package
A modern, fluent PHP package for accessing European Central Bank (ECB) exchange rate data API
Features
- ECB Schedule Aware - Handles ECB's 16:00 CET update schedule
- Multiple Data Formats - Single rates, collections, and time series
- Automatic Fallbacks - Smart date handling for weekends and holidays
Installation
composer require alimranahmed/ecb-exchange
Quick Start
Basic Usage
use EcbExchange\Ecb; // Get a single exchange rate $rate = Ecb::exchange() ->fromCurrency('USD') ->toCurrency('EUR') ->date('2025-09-01') ->updatedAfter('2009-05-15T14:15:00+01:00') ->get(); echo $rate; // "1 USD = 0.85 EUR (on 2025-09-01)" // Convert amount $amount = $rate->convert(100); // 85.0
Multiple Currencies
// Get multiple exchange rates at once $rates = Ecb::exchange() ->fromCurrency('EUR') ->toCurrencies(['USD', 'GBP', 'JPY', 'CHF']) ->date('2025-09-01') ->get(); foreach ($rates as $rate) { echo $rate . "\n"; }
Using EUR as Base (Default)
// When no fromCurrency is specified, EUR is used as base $rate = Ecb::exchange() ->toCurrency('USD') ->date('2025-09-01') ->get(); // Same as above $rate = Ecb::exchange() ->fromCurrency('EUR') ->toCurrency('USD') ->date('2025-09-01') ->get();
Time Series Data
// Get historical data $timeSeries = Ecb::getTimeSeries('2025-01-01', '2025-01-31', ['USD', 'GBP']); foreach ($timeSeries as $date => $rates) { echo "Date: $date\n"; foreach ($rates as $currency => $rate) { echo " 1 EUR = $rate $currency\n"; } }
Get Supported Currencies
$currencies = Ecb::getSupportedCurrencies(); // Returns: ['AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'SEK', 'USD']
ECB Schedule Awareness
This package is aware of the ECB's update schedule:
- Update Time: Exchange rates are updated around 16:00 CET every working day
- Concentration Procedure: Based on daily concertation between central banks around 14:10 CET
- TARGET Days: No updates on TARGET closing days
- Weekend Handling: Automatically uses the last working day's data for weekend requests
The package automatically handles:
- Weekend and holiday fallbacks
- Time zone considerations
- Effective date calculations based on update times
Error Handling
The package throws Exception for various error conditions:
try { $rate = Ecb::exchange() ->fromCurrency('USD') ->toCurrency('EUR') ->date('2025-09-01') ->get(); } catch (Exception $e) { echo "Error: " . $e->getMessage(); }
Common error scenarios:
- Invalid currency codes
- Network connectivity issues
- API response parsing errors
- Date availability issues
Testing
composer test
Requirements
- PHP 7.3 or higher
- Internet connection for API access
License
MIT License. See LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
Changelog
1.0.0
- Initial release with basic functionality
Support
For issues and questions, please use the GitHub issue tracker.
Disclaimer
This package is for informational purposes only. The ECB reference rates are published for information purposes only, and using the rates for transaction purposes is strongly discouraged.
alimranahmed/ecb-exchange 适用场景与选型建议
alimranahmed/ecb-exchange 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 alimranahmed/ecb-exchange 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alimranahmed/ecb-exchange 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-09