faridbabayev / cbar-currency
用于处理cbar.az货币汇率的PHP库
1.0.1
2022-09-08 12:27 UTC
Requires
- php: ^7.4|^8.0
- ext-bcmath: *
- ext-simplexml: *
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0
- phpunit/phpunit: ^8.0|^9.0
This package is auto-updated.
Last update: 2024-09-08 17:05:11 UTC
README
需求
PHP 7.4 或更高版本,需要 simplexml 和 bcmath 扩展。
安装
使用composer安装此包。
composer require faridbabayev/cbar-currency
使用发布命令将包配置复制到您的本地配置中
php artisan vendor:publish --provider="FaridBabayev\CBARCurrency\CBARCurrencyServiceProvider"
Laravel无自动发现
如果不使用自动发现,请将ServiceProvider添加到config/app.php中的providers数组
FaridBabayev\CBARCurrency\CBARCurrencyServiceProvider::class
如果您想使用外观来记录消息,请在app.php中添加以下内容
'CBAR' => \FaridBabayev\CBARCurrency\Facades\CBAR::class
用法
从CBAR获取货币
实例化 FaridBabayev\CBARCurrency\Facades\CBAR,指定您想要获取货币的日期。如果不传递日期,则使用当前日期
use FaridBabayev\CBARCurrency\Facades\CBAR; $currencies = CBAR::currencies(); // this will fetch currencies for current date $currencies = CBAR::from("18.02.2022")->currencies(); // this will fetch currencies for 18.02.2022
您可以使用PHP的strtotime()函数接受的任何日期格式传递日期。例如,20.10.2022,10/20/2022,2022-10-20,today,yesterday,-1 week,-1 year,15 December 2020,last Friday。
使用可用驱动程序
您可以通过环境文件更改默认驱动程序。
CBAR_CONNECTION=database
- 默认驱动程序是
sync
use FaridBabayev\CBARCurrency\Facades\CBAR; $currencies = CBAR::currencies(); // this will fetch currencies for current date $currencies = CBAR::from("18.02.2022")->currencies(); // this will fetch currencies for 18.02.2022
- 您可以使用
database驱动程序。在使用database驱动程序之前,首先运行php artisan migrate以currencies表
use FaridBabayev\CBARCurrency\Facades\CBAR; $currencies = CBAR::driver('database')->currencies(); // this will fetch currencies for current date $currencies = CBAR::driver('database')->from("18.02.2022")->currencies(); // this will fetch currencies for 18.02.2022
- 您可以使用
file驱动程序
use FaridBabayev\CBARCurrency\Facades\CBAR; $currencies = CBAR::driver('file')->currencies(); // this will fetch currencies for current date $currencies = CBAR::driver('file')->from("18.02.2022")->currencies(); // this will fetch currencies for 18.02.2022
货币转换
所有可用的货币和货币代码都可以在 CBAR网站 找到
将金额转换为AZN和从AZN转换
库支持使用给定日期的汇率将指定金额的外币转换为AZN
$currencies = CBAR::currencies(); $currencies->toAZN('USD')->convert(); // returns AZN equivalent of 1.00 USD with today's currencies $currencies->toAZN('USD')->convert(25.53); // returns AZN equivalent of 25.53 USD with today's currencies
您还可以将指定金额的AZN转换为任何可用的外币
$currencies = CBAR::currencies(); $currencies->fromAZN('USD')->convert(); // returns USD equivalent of 1.00 AZN with today's currencies $currencies->fromAZN('USD')->convert(25.53); // returns USD equivalent of 25.53 AZN with today's currencies
测试
composer test
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG
贡献
有关详细信息,请参阅 CONTRIBUTING
安全性
如果您发现任何与安全相关的问题,请通过电子邮件faridbabayev98@gmail.com联系,而不是使用问题跟踪器。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅 许可证文件
