ez-php/money
Composer 安装命令:
composer require ez-php/money
包简介
Immutable Money and Currency value objects for the ez-php ecosystem — ISO 4217 currencies, arbitrary-precision arithmetic via ez-php/bignum, allocation, and locale-aware formatting
README 文档
README
Immutable Money and Currency value objects for the ez-php ecosystem.
- ISO 4217 currencies with minor-unit scale (bundled, no network calls)
- Arbitrary-precision arithmetic via
ez-php/bignum - Allocation without losing a minor unit
- Locale-aware formatting via PHP's
ext-intl
Requirements
- PHP 8.5+
ext-gmp(required, viaez-php/bignum)ext-intl(optional, forIntlMoneyFormatter/IntlMoneyParser)
Installation
composer require ez-php/money
Usage
Creating Money
use EzPhp\Money\Money; $price = Money::of('19.99', 'EUR'); // from decimal string $tax = Money::ofMinorUnits(199, 'EUR'); // from cents → 1.99 EUR $zero = Money::zero('USD'); // JPY has no minor units (scale = 0) $yen = Money::of('1000', 'JPY');
Arithmetic
use EzPhp\BigNum\RoundingMode; $total = $price->add($tax); // 21.98 EUR $half = $price->divide(2, RoundingMode::HALF_UP); $vat = $price->multiply('0.19'); // 3.80 EUR (rounded HALF_UP)
Allocation
// Split 10.00 EUR three ways — no cent is lost [$a, $b, $c] = Money::of('10.00', 'EUR')->allocate([1, 1, 1]); // 3.34 EUR, 3.33 EUR, 3.33 EUR (total = 10.00 EUR ✓) // Weighted split [$deposit, $remainder] = Money::of('100.00', 'EUR')->allocate([1, 3]); // 25.00 EUR, 75.00 EUR
Comparison
$price->isGreaterThan($tax); // true $price->isEqualTo($tax); // false $price->compareTo($tax); // 1
Minor units
$price->toMinorUnits()->toString(); // "1999"
Currencies
use EzPhp\Money\Currency; $eur = Currency::of('EUR'); $eur->getCode(); // "EUR" $eur->getNumericCode(); // "978" $eur->getName(); // "Euro" $eur->getScale(); // 2 $eur->getSymbol(); // "€"
Formatting
use EzPhp\Money\Formatter\DecimalMoneyFormatter; use EzPhp\Money\Formatter\IntlMoneyFormatter; $plain = new DecimalMoneyFormatter(); $plain->format($price); // "19.99" $withCode = new DecimalMoneyFormatter(includeCurrencyCode: true); $withCode->format($price); // "19.99 EUR" $intl = new IntlMoneyFormatter('de_DE'); // requires ext-intl $intl->format($price); // "19,99 €"
Parsing
use EzPhp\Money\Parser\DecimalMoneyParser; use EzPhp\Money\Parser\IntlMoneyParser; $parser = new DecimalMoneyParser(); $money = $parser->parse('19.99', 'EUR'); $intlParser = new IntlMoneyParser('en_US'); // requires ext-intl $money = $intlParser->parse('$19.99', 'USD');
Exception hierarchy
MoneyException (extends RuntimeException)
├── CurrencyMismatchException — arithmetic between different currencies
└── UnknownCurrencyException — unrecognised ISO 4217 code
Currencies
The bundled registry covers ~150 ISO 4217 currencies. Lookups are case-insensitive and cached after first access.
use EzPhp\Money\CurrencyRegistry; CurrencyRegistry::has('EUR'); // true CurrencyRegistry::has('ZZZ'); // false CurrencyRegistry::all(); // array<string, Currency>
ez-php/money 适用场景与选型建议
ez-php/money 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「money」 「currency」 「bigdecimal」 「iso4217」 「financial」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ez-php/money 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ez-php/money 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ez-php/money 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Beyonic PHP Library
Fixer.io data provider for Peso
TCMB Currenct Converter
Immutable PHP currency converter that's data-agnostic.
The Payum Yandex Money gateway
Alfabank REST API integration
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 43
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-14