Download the PHP package gosuperscript/schema-money without Composer
On this page you can find all versions of the php package gosuperscript/schema-money. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gosuperscript/schema-money
More information about gosuperscript/schema-money
Files in gosuperscript/schema-money
Package schema-money
Short Description Monetary extension for Axiom - provides schema types, parsers, and operators for monetary values with strong type safety and currency validation
License MIT
Homepage https://github.com/gosuperscript/axiom-money
Informations about the package schema-money
Axiom Money
A monetary extension for Axiom, providing schema types, a parser, and operator rules for monetary values with strong type safety and currency validation.
Features
- Schema Types: Type-safe monetary value handling with currency validation
- Money Parser: Parse monetary values from various string formats (e.g., "EUR 100", "£50.25")
- Operator rules: Addition, subtraction, comparison and equality between monies of the same currency, plus multiplication/division by a numeric scalar — resolved and type-checked at compile time, declared per currency by a
MoneyExtension - Multiple Type Variants:
MonetaryType: Standard monetary type with currency validationMinorMonetaryType: Money from minor units (cents, pence, etc.)DynamicMonetaryType: Flexible parsing that auto-detects currency (boundary type only)MonetaryIntervalType: Intervals of monetary values
- Monetary Intervals: Support for ranges of monetary values
Requirements
- PHP 8.4 or higher
- ext-intl extension
Installation
Install via Composer:
Usage
Basic Money Types
Every money type projects into Axiom's shape algebra as an opaque money identity parameterized by its currency (Money<'EUR'>). Money<'EUR'> fills a Money<'EUR' | 'USD'> slot and shares no values with Money<'USD'> — all without a single core relation rule mentioning money.
Money Parser
Parse money from various string formats:
Minor Units
Work with minor currency units (cents, pence, etc.):
MinorMonetaryType projects to the same opaque money<currency> shape as MonetaryType: the two differ only in how they read raw input at the boundary, and a value of either is the same Money, so both resolve the same operator rules.
Dynamic Monetary Type
Automatically detect and parse currency from string:
DynamicMonetaryType admits any currency at the boundary, so its currency is not statically known — it projects to an opaque money with no currency parameter. That makes it a coercion/boundary type only: it is deliberately not assignable to the currency-parameterized Money<C> the operator rules resolve for. Declare a concrete MonetaryType where you need arithmetic or comparison.
Operator rules — the MoneyExtension
Money's typing is parameterized by currency, and a signature's return type is fixed, so the rules are declared by enumeration over the host's configured currencies. Compose the extension onto the core dialect and hand it to an expression; the compiler resolves and type-checks every operator, and the compiled Program runs what it resolved with no runtime dispatch.
The rules, per configured currency:
+/-— same currency in, same currency out.- *`
//** — by a numeric scalar (multiplication on either side; division isMoney / number). The calculation runs in Brick's exact rational domain and is **rounded back to the currency scale**, so the result is aMoneyof the same currency — each operator has one honest return type. The rounding mode is the extension's second constructor argument (defaultRoundingMode::HALF_UP). Division by zero is a *value-dependent* error, returned as anErr`, not a compile-time refusal. </<=/>/>=— ordering between two monies of the same currency → boolean.=/==/===and!=/!==— equality via Brick's amount-and-currency comparison. Core refuses equality on opaque operands, so the money package owns its own.
A cross-currency operation (Money<'GBP'> + Money<'USD'>) matches no rule and is refused at compile time with a named diagnostic — no program containing it can be compiled, let alone run.
Rounding note (breaking change): previous versions returned an exact
Brick\Money\RationalMoneyfrom*//and propagated it through+/-("rational is contagious"). Under the typed model each operator has a fixed return type, so*//now round to aMoneyat the currency scale using the extension's rounding mode. Chain in the rational domain yourself (via Brick) if you need to defer rounding.
Monetary Intervals
Work with ranges of monetary values:
MonetaryIntervalType projects to an opaque monetary-interval<currency> shape. The MoneyExtension contributes, per currency, the comparison of a monetary interval against a money of that currency (<, <=, >, >= → boolean) and equality between two monetary intervals of the same currency (=/==/===, !=/!==).
Development
Running Tests
Code Quality
The project enforces 100% code coverage and uses:
- PHPUnit: Unit testing
- PHPStan: Static analysis
- Laravel Pint: Code style
- Infection: Mutation testing
Dependencies
This library builds on several excellent packages:
- brick/money: Robust money and currency library
- gosuperscript/axiom: The expression language it extends
- superscript/interval: Interval mathematics
- superscript/monetary-interval: Monetary interval support
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate and maintain the existing code quality standards.
All versions of schema-money with dependencies
ext-intl Version *
brick/money Version ^0.14.1
gosuperscript/axiom Version ^0.6.9
superscript/interval Version ^2.0
superscript/monetary-interval Version ^0.2.0