ionut/currency
Composer 安装命令:
composer require ionut/currency
包简介
Framework-agnostic currency conversion based on the European Central Bank rates. Integrates seamlessly with Laravel.
README 文档
README
Currency is a currency exchanger written in PHP that aims for ease of use and complete independence of any frameworks or CMSs.
Besides being fully unit-tested and well written, it is also one of the few libraries(if not the only) that uses the European Central Bank rates. This does not only mean that you get the conversion rates for free but also that you do not tie one of the core responsibilities of your application to a fragile third-party service.
So far, it provides an out of the box service provider for Laravel. But besides that, the library is completely framework agnostic and it'll stay like this for the foreseeable future.
Starting out
Some applications do not need the complexity and verbosity of our OOP endeavours. For those, currency has a clean helper that would love to help you keep your code short.
Let's say you want to convert $20.5 to EUR by using the latest rates provided by the European Central Bank, the code accomplishing that will look like this:
$eurAmount = currency(20.5, 'USD')->toEUR();
Gain control of the exchanger's building
In case you don't fancy having helpers in your codebase you'll be happy to know that using the helper function is optional. Let's just rewrite the previous example and get rid of the helper:
$exchanger = (new Ionut\Currency\Factory)->create(); $usdAmount = new Amount(20.5, 'USD'); $eurAmount = $exchanger->convert($usdAmount, 'EUR');
Of course, there's more code to write by using this approach. But such level of control couldn't be readily accomplished by using the helper function.
Intermediate Usage
As seen in the previous example, there are three distinct parts which form the core of the Currency library:
- Exchanger
- The guy that converts the numbers by applying first grade math.
- ExchangeRates
- Whose implementation is the EuropeanCentralBank guy in the example.
It provides the exchanger with the latest exchange rates. - Downloader
- The guy that comes and helps ExchangeRates by downloading files and caching them locally. (for example an XML containing the exchange rates)
By remembering those and keeping in mind that the library fully follows the interfaces found in the Contracts namespace, you should be able to master everything there is to know about this library.
Contracts
Because libraries die more often that one would expect, Currency provides the developer with Contracts for every of the Currency's class, allowing his code to remain SOLID while using the best currency conversion library there is.
Tests
The present library is fully unit-tested, contributors are welcome to check the aforementioned tests in the tests folder and run them by calling PHPUnit.
License
The present package is open-sourced software licensed under the MIT license.
ionut/currency 适用场景与选型建议
ionut/currency 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.46k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2016 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ionut/currency 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ionut/currency 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-01-30