teknoman / currency-exchange
一个使用多个网络服务检索货币兑换的库
v3.1.0
2015-08-31 14:51 UTC
Requires
- php: >=5.4
- guzzlehttp/guzzle: 5.*
Requires (Dev)
- phpunit/phpunit: 4.*
README
这是一个使用多个网络服务检索货币兑换的库。它不依赖于任何框架,因此您可以在Zend、Symfony、Silex、Yii等框架上安装它。
安装
将此库添加到您的composer.json中
"require": { "teknoman/currency-exchange": "3.*" }
现在运行以下命令来告诉Composer下载此库
$ php composer.phar update teknoman/currency-exchange
Composer将此库安装到您的项目vendor/teknoman
目录。
用法
<?php // require composer's autoload require 'vendor/autoload.php'; $exchanger = new \CurrencyExchange\Exchanger(); // This method will print the current exchange rate from Euros to U.S. Dollars using default web service (YahooFinance) $result = $exchanger->getExchangeRate('EUR', 'USD'); // This method will exchange 14 Euros in the correspondant U.S. Dollars, it uses the default exchange service (YahooFinance) $result = $exchanger->exchange(14, 'EUR', 'USD');
或者,您也可以设置您首选的兑换服务
<?php $exchanger = new \CurrencyExchange\Exchanger('GrandTrunk'); // This method will print the current exchange rate from Euros to U.S. Dollars using GrandTrunk web service $result = $exchanger->getExchangeRate('EUR', 'USD'); // This method will exchange 14 Euros in the correspondant U.S. Dollars using GrandTrunk web service $result = $exchanger->exchange(14, 'EUR', 'USD');
如果您需要使用代理,您可以通过调用$exchanger
实例上的setProxy()
方法来设置它
$exchanger->setProxy('example.host.com:8080'); // In the format 'host:port'
版本 3
在3.*版本中,已移除db部分,将在未来的新包中包含,该新包将需要此包作为依赖项。此外,在此版本中,已移除Zend的包,并且使用Guzzle执行http请求。