amelia/money
最新稳定版本:v1.0.0-beta.2
Composer 安装命令:
composer require amelia/money
包简介
A library for working with the Open Exchange Rates API in PHP
README 文档
README
A PHP 5.4+ library for working with currency APIs and conversion.
Current Providers for data are:
- Open Exchange Rates (https://openexchangerates.org)
Planned:
- Her Majesty's Revenue & Customs (http://www.hmrc.gov.uk/softwaredevelopers/2015-exrates.htm)
- XE.com (https://xe.com)
Feel free to add more!
Usage
To dive in with the OpenExchangeRates API implementation, go sign up for an app id. It's free!
Laravel 5
Money ships with a Laravel 5 service provider.
Simply add Amelia\Money\MoneyServiceProvider::class to your providers array in config/app.php.
You can type-hint Amelia\Money\FactoryInterface in controllers (or more importantly, form requests), or use app(FactoryInterface::class) to fetch it from the IoC container.
<?php use Amelia\Money\FactoryInterface; class FooController extends Controller { public function __construct(FactoryInterface $money) { $money->convert($amount = 130.01, $from = "USD", $to = "GBP"); $money->getBase(); $money->getRates(); $newMoney = $money->base("GBP"); // switch the base currency } }
Add the following configuration to the config/services.php array
"money" => [ "api" => env("MONEY_API_TYPE", "openexchangerates"), "key" => env("MONEY_API_KEY", null), ],
Usage without a framework:
<?php use Amelia\Money\OpenExchangeRatesFactory; $converter = OpenExchangeRatesFactory::create(["key" => "YOUR_APP_ID"]); $converter->convert(140, "gbp", "nok"); // currency codes are case-insensitive. var_dump($converter->getRates(), $converter->getBase());
Converter instances are immutable. To change the base currency, use the ->base(string $base) method. To change the rates, make a new object.
统计信息
- 总下载量: 41
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-01