Motivation
Money is the classic "don't use floats" domain. A MoneyCast storing minor units (integer cents) with a currency would make the package attractive for fintech/e-commerce DTOs out of the box.
Design questions to settle first (comments welcome)
- Value object: ship a tiny immutable
Money value object in the package, or integrate with moneyphp/money via suggest? (Core must stay dependency-free.)
- Input formats:
1099 (minor units), '10.99' (decimal string), ['amount' => 1099, 'currency' => 'USD']?
- Serialization shape for
toArray() — needs to round-trip through from().
Sketch
#[Cast(new MoneyCast(currency: 'USD'))]
public readonly Money $price,
This is a bigger design than a typical cast — please discuss the approach on this issue before opening a PR. Performance note: whatever we do must not add work to the hot path for classes that don't use the cast (see CONTRIBUTING.md → Performance guidelines).
Motivation
Money is the classic "don't use floats" domain. A
MoneyCaststoring minor units (integer cents) with a currency would make the package attractive for fintech/e-commerce DTOs out of the box.Design questions to settle first (comments welcome)
Moneyvalue object in the package, or integrate withmoneyphp/moneyviasuggest? (Core must stay dependency-free.)1099(minor units),'10.99'(decimal string),['amount' => 1099, 'currency' => 'USD']?toArray()— needs to round-trip throughfrom().Sketch
This is a bigger design than a typical cast — please discuss the approach on this issue before opening a PR. Performance note: whatever we do must not add work to the hot path for classes that don't use the cast (see CONTRIBUTING.md → Performance guidelines).