mathiasverraes/money
Composer 安装命令:
composer require mathiasverraes/money
包简介
PHP implementation of Fowler's Money pattern
关键字:
README 文档
README
PHP library to make working with money safer, easier, and fun!
"If I had a dime for every time I've seen someone use FLOAT to store currency, I'd have $999.997634" -- Bill Karwin
In short: You shouldn't represent monetary values by a float Wherever you need to represent money, use this Money value object. Since version 3.0 this library uses strings internally in order to support unlimited integers.
<?php use Money\Money; $fiveEur = Money::EUR(500); $tenEur = $fiveEur->add($fiveEur); list($part1, $part2, $part3) = $tenEur->allocate([1, 1, 1]); assert($part1->equals(Money::EUR(334))); assert($part2->equals(Money::EUR(333))); assert($part3->equals(Money::EUR(333)));
The documentation is available at http://moneyphp.org
Requirements
This library requires the BCMath PHP extension. There might be additional dependencies for specific feature, e.g. the Swap exchange implementation, check the documentation for more information.
Version 4 requires PHP 8.0. For older version of PHP, use version 3 of this library. From version 4.5 this package will only support PHP versions that actually receive updates by PHP itself. If you want to use the package with older PHP versions, you can of course use older versions of this package.
Install
Via Composer
$ composer require moneyphp/money
Features
- JSON Serialization
- Big integer support utilizing different, transparent calculation logic upon availability (bcmath, gmp, plain php)
- Money formatting (including intl formatter)
- Currency repositories (ISO currencies included)
- Money exchange (including Swap implementation)
Documentation
Please see the official documentation.
Testing
We try to follow TDD by using phpunit to test this library.
$ composer test
Running the tests in Docker
Money requires a set of dependencies, so you might want to run it in Docker.
First, build the image locally:
$ docker build -t moneyphp .
Then run the tests:
$ docker run --rm -it -v $PWD:/app -w /app moneyphp vendor/bin/phpunit --exclude-group segmentation
Contributing
We would love to see you helping us to make this library better and better.
Please keep in mind we do not use suffixes and prefixes in class names,
so not CurrenciesInterface, but Currencies. Other than that, Style CI will help you
using the same code style as we are using. Please provide tests when creating a PR and clear descriptions of bugs when filing issues.
Security
If you discover any security related issues, please contact us at team@moneyphp.org.
License
The MIT License (MIT). Please see License File for more information.
Acknowledgements
This library is heavily inspired by Martin Fowler's Money pattern. A special remark goes to Mathias Verraes, without his contributions, in code and via his blog, this library would not be where it stands now.
mathiasverraes/money 适用场景与选型建议
mathiasverraes/money 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.06M 次下载、GitHub Stars 达 4.83k, 最近一次更新时间为 2012 年 08 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「money」 「Value Object」 「vo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mathiasverraes/money 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mathiasverraes/money 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mathiasverraes/money 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Beyonic PHP Library
Runn Me! Value Objects Library
Laravel SDK mapping data in object
MaxAl Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
Rinvex Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
统计信息
- 总下载量: 2.06M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4844
- 点击次数: 23
- 依赖项目数: 28
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2012-08-01
