morbicer/converter-bundle

为 Symfony2 提供货币转换包。支持多个汇率提供商。

安装: 15

依赖者: 0

建议者: 0

安全: 0

星标: 3

关注者: 1

分支: 1

开放问题: 0

类型:symfony-bundle

0.0.1 2015-09-09 10:08 UTC

This package is not auto-updated.

Last update: 2024-10-02 10:50:21 UTC


README

为 Symfony2 提供货币转换包。支持多个汇率提供商

  • Yahoo (免费)
  • Google (免费)
  • Currency API (免费)
  • chain (如果某些不可用,尝试多个)

使用 Martin Fowler 的 Money 模式进行适当的货币处理,由 mathiasverraes/money 实现

1 安装

1.1 Composer

"require": {
  ....
  "morbicer/converter-bundle": "dev"
},

或者

php composer.phar require morbicer/converter-bundle

1.2 启用包

// app/AppKernel.php
public function registerBundles()
{
      $bundles = array(
        // ...
        new Morbicer\ConverterBundle\MorbicerConverterBundle(),
    );
}

1.3 添加配置

# app/config.yml
morbicer_converter:
  default_provider: chain
  providers:
      yahoo: []
      google: []
      currency_api: []
      chain: [yahoo, currency_api, google]

使用方法

//in controller, get service
$converter = $this->get('morbicer_converter.convert');
// $100 USD to EUR
$converted = $converter->convert(100, 'USD', 'EUR');
$result = array(
    'amount' => $converted->getAmount()/100,
    'currency' => (string)$converted->getCurrency(),
);