Add BcMath\Number support to NumberField#7506
Open
NovakHonza wants to merge 1 commit intoEasyCorp:5.xfrom
Open
Add BcMath\Number support to NumberField#7506NovakHonza wants to merge 1 commit intoEasyCorp:5.xfrom
NovakHonza wants to merge 1 commit intoEasyCorp:5.xfrom
Conversation
NumberField now supports PHP 8.4's BcMath\Number type via the new setStoredAsBcMathNumber() option. This allows entities using Doctrine's Types::NUMBER column type with BcMath\Number properties to work seamlessly with NumberField in both forms and detail pages. Implementation: - Add EaNumberType form type (extends NumberType) with a model transformer that converts between string and BcMath\Number - Add StringToBcMathNumberTransformer for the form data conversion - Update NumberConfigurator to convert BcMath\Number to float for IntlFormatter display, with PHP version guard and conflict detection - Cannot be combined with setStoredAsString()
Contributor
Author
|
A small note on the exception type: on line 38 of That said, from a PHP semantics perspective, If you consider |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PHP 8.4 introduced
\BcMath\Number— an object type for arbitrary-precision arithmetic that avoids the floating-point rounding issues inherent tofloat. Doctrine ORM supports it viaTypes::NUMBER. This PR adds native support for\BcMath\Numberproperties inNumberField.Changes
setStoredAsBcMathNumber()option toNumberFieldEaNumberTypeform type (extendsNumberType) withStringToBcMathNumberTransformerthat handles conversion between form input and\BcMath\NumberNumberConfiguratorto convert\BcMath\NumbertofloatforIntlFormatterdisplay\LogicExceptionon PHP < 8.4,\InvalidArgumentExceptionwhen combined withsetStoredAsString()BcMath\Number(not available when analyzing withphpVersion: 80200)Usage
With a Doctrine entity:
Without this option,
NumberFieldsends afloaton form submit (causingInvalidTypeException) and passes\BcMath\Numberdirectly toIntlFormatter::formatNumber()which only acceptsint|float(causingTypeError).