Skip to content

MoneyCast: design discussion + implementation #4

Description

@yuriizee

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)

  1. Value object: ship a tiny immutable Money value object in the package, or integrate with moneyphp/money via suggest? (Core must stay dependency-free.)
  2. Input formats: 1099 (minor units), '10.99' (decimal string), ['amount' => 1099, 'currency' => 'USD']?
  3. 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions