Skip to content

Conversation

@aaa2000
Copy link
Contributor

@aaa2000 aaa2000 commented Nov 25, 2025

Q A
Branch? main
Tickets Closes #6934
License MIT

Render BCMath\Number (PHP 8.4+) as string instead of object

Before

{
    "@context": "/contexts/MathNumber",
    "@id": "/math_numbers/1",
    "@type": "MathNumber",
    "id": 1,
    "value": {
        "@id": "/.well-known/genid/d884d3a7bec8d1a52024",
        "@type": "Number",
        "scale": 2,
        "value": "300.55"
    }
}

After

{
    "@context": "/contexts/MathNumber",
    "@id": "/math_numbers/1",
    "@type": "MathNumber",
    "id": 1,
    "value": "300.55"
}

The symfony/serializer:7.3 added the NumberNormalizer, the symfony/framework-bundle:7.3 registered it.

In CI and the job PHPUnit (PHP 8.4), api-platform install symfony/framework-bundle:7.2

  - Locking symfony/framework-bundle (7.2.x-dev 42ac8bb)
  - Locking symfony/http-client (v7.3.6)
  - Locking symfony/http-client-contracts (v3.6.0)

if I try locally

composer require --dev "symfony/framework-bundle:7.3" -W --dry-run 
....
- symfony/object-mapper is locked to version 7.4.x-dev and an update of this package was not requested.
- symfony/framework-bundle v7.3.0 conflicts with symfony/object-mapper >=7.4.

@aaa2000 aaa2000 force-pushed the feat-6934-bcmath-number branch from a5e0533 to 0f95799 Compare November 25, 2025 18:09
@soyuka
Copy link
Member

soyuka commented Nov 30, 2025

interesting, I'm wondering if this couldn't be added to 4.2 though.

];
}

if (class_exists(\BcMath\Number::class) && is_a($className, \BcMath\Number::class, true)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (class_exists(\BcMath\Number::class) && is_a($className, \BcMath\Number::class, true)) {
if (is_a($className, \BcMath\Number::class, true)) {

IIRC, the call to is_a() will return false if the class doesn't exist.

// symfony/serializer:7.3 added the NumberNormalizer
// symfony/framework-bundle:7.3 added the serializer.normalizer.number` service
// if symfony/serializer >= 7.3 and symfony/framework-bundle < 7.3, the service is registred
if (class_exists(NumberNormalizer::class) && !$container->has('serializer.normalizer.number')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to just bump the minimum required versions to avoid supporting this edge case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we just bumped everything to 7.4 if I'm not mistaken

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mhh we did not but indeed we should bump this to 7.4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t see the bump to 7.4 on the branch 4.2, I was wondering which components should I bump ?

https://github.com/api-platform/core/blob/4.2/src/JsonSchema/composer.json#L31
https://github.com/api-platform/core/blob/4.2/src/Serializer/composer.json#L30
https://github.com/api-platform/core/blob/4.2/src/Symfony/composer.json#L46

And there’s currently no dependency on symfony/framework-bundle for the api-platform/symfony, should I add it ?

@aaa2000 aaa2000 force-pushed the feat-6934-bcmath-number branch 2 times, most recently from ef978e3 to e0a4812 Compare December 1, 2025 13:19
@aaa2000 aaa2000 changed the base branch from main to 4.2 December 1, 2025 14:01
@aaa2000 aaa2000 force-pushed the feat-6934-bcmath-number branch from e0a4812 to 0320ed9 Compare December 1, 2025 14:21
@aaa2000 aaa2000 force-pushed the feat-6934-bcmath-number branch from 0320ed9 to b0c4939 Compare December 1, 2025 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Render BCMath\Number (PHP 8.4+) as string instead of object

3 participants