florianv / laravel-swap
Laravel 和 Lumen 的货币汇率库
2.3.0
2021-01-11 10:21 UTC
Requires
- php: ^7.1.3 || ^8.0
- florianv/swap: ^4.0
Requires (Dev)
- graham-campbell/testbench: ^5.3
- nyholm/psr7: ^1.0
- php-http/guzzle6-adapter: ^1.0
README
Swap 允许您从各种服务(如 Fixer、Currency Data 或 Exchange Rates Data)检索货币汇率,并可选地缓存结果。
赞助商
快速入门
安装
$ composer require php-http/curl-client nyholm/psr7 php-http/message florianv/laravel-swap
Laravel 5.7 或更早版本
如果您使用缓存,还需要添加 PSR-6 适配器和 PSR-16 桥接缓存依赖项
$ composer require cache/illuminate-adapter cache/simple-cache-bridge
这些依赖项在 Laravel 5.8 或更高版本中不是必需的,因为这些版本实现了 PSR-16。(查看实现详情)
Laravel 5.5+
如果您不使用自动发现,请将 ServiceProvider
添加到 config/app.php
中的 providers 数组中
// /config/app.php 'providers' => [ Swap\Laravel\SwapServiceProvider::class ],
如果您想使用外观来记录消息,请将以下内容添加到您的 app.php 中的 facades
'aliases' => [
'Swap' => Swap\Laravel\Facades\Swap::class
]
使用发布命令将包配置复制到本地配置
$ php artisan vendor:publish --provider="Swap\Laravel\SwapServiceProvider"
Lumen
配置 Service Provider 和别名
// /boostrap/app.php // Register the facade $app->withFacades(true, [ Swap\Laravel\Facades\Swap::class => 'Swap' ]); // Load the configuration $app->configure('swap'); // Register the service provider $app->register(Swap\Laravel\SwapServiceProvider::class);
如果您希望覆盖配置,请将 配置 复制到 /config/swap.php
使用方法
// Get the latest EUR/USD rate $rate = Swap::latest('EUR/USD'); // 1.129 $rate->getValue(); // 2016-08-26 $rate->getDate()->format('Y-m-d'); // Get the EUR/USD rate yesterday $rate = Swap::historical('EUR/USD', Carbon\Carbon::yesterday());
文档
完整文档可以在 这里 找到。
服务
以下是当前实现的服务列表
致谢
许可协议
MIT 许可协议(MIT)。有关更多信息,请参阅 LICENSE。