💥 Breaking changes
MoneyBagcan no longer be instantiated withnew: its constructor is now private; useMoneyBag::zero()to create an empty instanceMoney::convertedTo()now defaults toDefaultContextinstead of$this's context- The following methods no longer accept
nullfor the$contextparameter:CurrencyConverter::convert()Money::of()Money::ofMinor()Money::zero()Money::convertedTo()
Money::allocate()signature has changed: replaceallocate(1, 2, 3)withallocate([1, 2, 3], AllocationMode::FloorToFirst)to keep the same behaviour as beforeMoney::allocateWithRemainder()has been removed: replaceallocateWithRemainder(1, 2, 3)withallocate([1, 2, 3], AllocationMode::BlockSeparate)to keep the same behaviour as beforeMoney::split()signature has changed: replacesplit(3)withsplit(3, SplitMode::ToFirst)to keep the same behaviour as beforeMoney::splitWithRemainder()has been removed: replacesplitWithRemainder(3)withsplit(3, SplitMode::Separate)to keep the same behaviour as before- The following methods now throw an exception when used on a
MoneywithAutoContext:quotient()remainder()quotientAndRemainder()allocate()split()
MoneyBagno longer retains zero-balance currencies afterplus()/minus()operationsExchangeRateProvider::getExchangeRate()signature has changed: it now acceptsCurrencyinstances, and returnsBigNumber|nullCurrencyConversionExceptionhas been renamed toExchangeRateException, withExchangeRateProviderExceptionandExchangeRateNotFoundExceptionsubclassesPdoProvider::setParameters()has been removed, use dimension bindings insteadPdoProviderconstructor is now private, usePdoProvider::builder()->...->build()to create an instancePdoProviderConfigurationhas been removed, usePdoProvider::builder()insteadCurrencyConverter::convert()signature has changed: parameter$dimensionsnow comes before$contextCachedProvider::invalidate()has been removed, pass a PSR-16 cache implementation to the constructor if you need to invalidate the cacheMoneyComparatorconstructor now requires aComparisonModeinstance, explicitly pass an instance ofPairwiseModeto keep the same behaviour as beforeConfigurableProvideris now immutable:setExchangeRate()has been removed, useConfigurableProvider::builder()->addExchangeRate()->build()instead- The following methods now throw an exception when the exchange rate is negative or zero:
Money::convertedTo()RationalMoney::convertedTo()CurrencyConverter::convert()CurrencyConverter::convertToRational()
- The following methods now throw when performing same-currency operations with a rate different from
1:Money::convertedTo()RationalMoney::convertedTo()
- Constructors and factory methods of library-internal exceptions are now
@internal Contextmethods are now@internal: userland code should only rely on constructors- Interfaces
Context,Monetary, andMoneyExceptionare now sealed: userland implementations are no longer supported - Built-in
ExchangeRateProviderimplementations now consistently return1for same-currency pairs
Deprecated methods removed:
AbstractMoney::to()has been removed, usetoContext()insteadAbstractMoney::isAmountAndCurrencyEqualTo()has been removed, useisSameValueAs()insteadMoney::total()has been removed, usesum()insteadMoney::getUnscaledAmount()has been removed, usegetAmount()->getUnscaledValue()insteadRationalMoney::simplified()has been removed,RationalMoneyis always in its simplest form nowMoneyBag::add()has been removed, useplus()instead, which returns a new instanceMoneyBag::subtract()has been removed, useminus()instead, which returns a new instance
The following breaking changes only affect you if you're using named arguments:
Currency::ofNumericCode()now uses$numericCodeas the parameter nameIsoCurrencyProvider::getCurrencyByNumericCode()now uses$numericCodeas the parameter nameMoneyBag::plus()andminus()now use$thatas the parameter name
- Method
MoneyBag::fromMonies()is deprecated, useof()instead - Class
ProviderChainis deprecated, useChainProviderinstead
✨ New features
- Support for custom dimensions (date, rate type, ...) in
ExchangeRateProvider,CurrencyConverterandMoneyComparator - Support for
Money,RationalMoney, andMoneyBaginMoneyComparator - Support for multiple comparison modes in
MoneyComparator - New
Money::allocate()API with five algorithms, exposed through the newAllocationModeenum:FloorToFirst(this is the implementationallocate()used previously)FloorToLargestRatioFloorToLargestRemainderFloorSeparateBlockSeparate(this is the implementationallocateWithRemainder()used previously)
- New
Money::split()API with two algorithms, exposed through the newSplitModeenum:ToFirst(this is the implementationsplit()used previously)Separate(this is the implementationsplitWithRemainder()used previously)
MoneyMismatchExceptionnow has explicitCurrencyMismatchExceptionandContextMismatchExceptionsubclasses- New exception:
MoneyFormatException, thrown byMoneyFormatter::format() - New methods in
MoneyBag:isZero(),multipliedBy(),dividedBy(),negated(),isEqualTo(),of()(replacesfromMonies()) - New methods in
RationalMoney:min(),max(),sum() - Support for custom PSR-16 cache implementations in
CachedProvider - New exchange rate provider:
ChainProvider(replacesProviderChain) - Support for numeric currency codes in
PdoProvider