定制 amelia/money 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Build Status Scrutinizer Latest Stable Version MIT License

A PHP 5.4+ library for working with currency APIs and conversion.

Current Providers for data are:

Planned:

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-01