Releases: brick/money
0.13.0
💥 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
0.12.3
- Method
AbstractMoney::isAmountAndCurrencyEqualTo()is deprecated, useisSameValueAs()instead
🔄 Reverted deprecations
- The deprecation notice when calling
AbstractMoney::isEqualTo()with a money in a different currency (introduced in 0.12.1) has been removed; this method will continue to throw aMoneyMismatchException
✨ New features
- New method:
AbstractMoney::isSameValueAs()(replacesisAmountAndCurrencyEqualTo())
0.12.2
✨ New features
Money::allocate()&allocateWithRemainder()now acceptBigNumber|int|stringand support decimal & rational ratios- New method:
Money::remainder() - Methods
abs()andnegated()are now available onAbstractMoney
📌 Compatibility
- Compatibility with
brick/mathversion0.17
0.12.1
0.12.0
💥 Breaking changes
- Calling the following methods with floating-point values is no longer supported, explicitly cast floats to string
(string) $floatto get the same behaviour as before (brick/math#105):Money::of(),ofMinor(),plus(),minus(),multipliedBy(),dividedBy(),quotient(),quotientAndRemainder(),convertedTo()RationalMoney::of(),plus(),minus(),multipliedBy(),dividedBy()AbstractMoney::compareTo(),isEqualTo(),isLessThan(),isLessThanOrEqualTo(),isGreaterThan(),isGreaterThanOrEqualTo()ConfigurableProvider::setExchangeRate()
- Calling
Currency::of()with a numeric code is no longer supported, useCurrency::ofNumericCode()instead (#104) - Calling the following methods with a numeric currency code is no longer supported, use a
Currencyinstance fromCurrency::ofNumericCode()instead (#104):Money::of()Money::ofMinor()Money::zero()Money::convertedTo()RationalMoney::of()CurrencyConverter::convert()CurrencyConverter::convertToRational()IsoCurrencyProvider::getCurrency()
RationalMoneyis now always simplified to lowest terms:USD 25/100is automatically simplified toUSD 1/4Currency::$numericCodeis now nullablePdoProviderConfigurationnow has a private constructor, use a factory method instead- Internal method
Money::create()is nowprotected
Class name case changes:
ISOCurrencyProviderhas been renamed toIsoCurrencyProviderPDOProviderhas been renamed toPdoProviderPDOProviderConfigurationhas been renamed toPdoProviderConfiguration
Deprecated methods removed:
Currency::is()has been removed, useCurrency::isEqualTo()insteadMoneyBag::getAmount()has been removed, useMoneyBag::getMoney()->getAmount()insteadMoney::formatTo()has been removed, useMoney::formatToLocale()insteadMoney::formatWith()has been removed, useMoneyNumberFormatter::format()instead
- Method
RationalMoney::simplified()is deprecated, as it is now a no-op - Method
Money::getUnscaledAmount()is deprecated, usegetAmount()->getUnscaledValue()instead - Method
Money::total()is deprecated, usesum()instead - Method
AbstractMoney::to()is deprecated, usetoContext()instead - Passing
nullto the$contextparameter of the following methods is deprecated, use named arguments if you need to skip$context:CurrencyConverter::convert()Money::of()Money::ofMinor()Money::zero()
- Passing
nullto the$contextparameter ofMoney::convertedTo()is deprecated, use an explicitContextinstance; the default will change toDefaultContextin a future version - Instantiating a
MoneyBagwithnewis deprecated, useMoneyBag::zero()orMoneyBag::fromMonies()instead - Method
MoneyBag::add()is deprecated, useplus()instead, which returns a new instance - Method
MoneyBag::subtract()is deprecated, useminus()instead, which returns a new instance
📌 Compatibility
- brick/money now requires
brick/math:~0.15
👌 Improvements
- All
InvalidArgumentExceptionthrown now implementMoneyException - More exceptions have been documented
CashContext::applyTo()now performs step ⟷ scale validation
✨ New features
- New method:
AbstractMoney::toRational() - New method:
Money::sum()(replacestotal()) - New method:
RationalMoney::convertedTo() - New method:
RationalMoney::abs() - New method:
RationalMoney::negated() - New
MoneyBagimmutable API:MoneyBag::zero()MoneyBag::fromMonies()MoneyBag::plus()MoneyBag::minus()
- New exception:
ContextExceptionthrown when a context cannot be applied - New
PDOProviderConfigurationfactory methods:forCurrencyPair()forFixedSourceCurrency()forFixedTargetCurrency()
MoneyBagnow implementsJsonSerializable
0.11.2
0.11.1
- Added explicit
trigger_deprecation()calls to methods that were already marked as@deprecated, so deprecation notices are now emitted at runtime
📌 Compatibility
- Restricted compatibility to
brick/math:~0.14.4
👌 Improvements
- Fixed calls to deprecated brick/math and brick/money APIs
0.11.0
💥 Breaking changes
- Minimum PHP version is now 8.2
- The following classes are now
final:CurrencyConversionExceptionMoneyMismatchExceptionUnknownCurrencyException
CustomContextnow validates the step and will throw an exception if an invalid step is given- Interface
MoneyContainerhas been removed (replaced withMonetary) - Method
AbstractMoney::getAmounts()has been removed (replaced withgetMonies()) - Method
MoneyBag::getAmounts()has been removed (replaced withgetMonies()) CurrencyConverter::convert()andconvertToRational()now accept aMonetaryinstance (which still includesMoney,RationalMoneyandMoneyBag)MoneyBag::add()andsubtract()now accept aMonetaryinstance (which still includesMoney,RationalMoneyandMoneyBag)
- Calling
Currency::of()with a numeric code is deprecated, useCurrency::ofNumericCode()instead - Calling
ISOCurrencyProvider::getCurrency()with a numeric code is deprecated, usegetCurrencyByNumericCode()instead - Calling
CurrencyConverter::convert()orconvertToRational()with a numeric currency code is deprecated, use aCurrencyinstance instead - Calling
Money::of(),ofMinor(),zero()orconvertedTo()with a numeric currency code is deprecated, use aCurrencyinstance instead - Calling
RationalMoney::of()with a numeric currency code is deprecated, use aCurrencyinstance instead MoneyBag::getAmount()is deprecated, usegetMoney()insteadMoney::formatTo()is deprecated, useMoney::formatToLocale()insteadMoney::formatWith()is deprecated, useMoneyNumberFormatter::format()insteadCurrency::is()is deprecated, useCurrency::isEqualTo()instead
Important
The convenience of passing a currency by ISO numeric code in addition to alphabetic code has been deprecated, leaving only alphabetic-code lookup in generic APIs. For example, Money::of() will accept Currency|string in the future, instead of Currency|string|int today.
This makes explicit the separation between retrieval by alphabetic code, which has strong backwards compatibility guarantees, and retrieval by numeric code, which may change in minor versions due to ISO reassignments.
This will require users to explicitly obtain a currency through Currency::ofNumericCode(), which is documented as not being covered by the same BC guarantees.
✨ New features
- Support for historical currencies in
Money::of(),Currency::of(), etc. (#104 by @survik1) - New enum:
CurrencyType - New methods:
Currency::getCurrencyType()returns the type of the currencyCurrency::ofNumericCode()returns a currency by its numeric ISO 4217 codeCurrency::isEqualTo()compares two currencies for equality (replacesis())ISOCurrencyProvider::getCurrencyByNumericCode()returns a currency by its numeric codeISOCurrencyProvider::getHistoricalCurrenciesForCountry()returns historical currencies for a countryMoneyBag::getMoney()returns the contained amount in a given currency (replacesgetAmount())MoneyBag::getMonies()returns the contained monies (replacesgetAmounts())Money::formatToLocale()formats the amount to a locale (replacesformatTo()) (#105 by @mklepaczewski)RationalMoney::zero()returns a zeroRationalMoneyin a given currency
- New interfaces:
Monetary(replacesMoneyContainer)MoneyFormatterformats a givenMoneyobject (#105 by @mklepaczewski)
- New classes:
MoneyLocaleFormatterformats a givenMoneyobject to a locale (#105 by @mklepaczewski)MoneyNumberFormatterformats a givenMoneyobject using aNumberFormatterinstance (#105 by @mklepaczewski)