faridbabayev/cbar-currency

用于处理cbar.az货币汇率的PHP库

1.0.1 2022-09-08 12:27 UTC

This package is auto-updated.

Last update: 2024-09-08 17:05:11 UTC


README

需求

PHP 7.4 或更高版本,需要 simplexmlbcmath 扩展。

安装

使用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.202210/20/20222022-10-20todayyesterday-1 week-1 year15 December 2020last Friday

使用可用驱动程序

您可以通过环境文件更改默认驱动程序。

CBAR_CONNECTION=database
  1. 默认驱动程序是 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
  1. 您可以使用 database 驱动程序。在使用 database 驱动程序之前,首先运行 php artisan migratecurrencies
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
  1. 您可以使用 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)。有关更多信息,请参阅 许可证文件