Skip to content

fix(serializer): deprecate SerializerAwareProviderInterface and SerializableProvider #7348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 4.2
Choose a base branch
from

Conversation

vinceAmstoutz
Copy link
Member

@vinceAmstoutz vinceAmstoutz commented Aug 22, 2025

Q A
Branch? 4.2
Tickets -
License MIT

Made the deprecation before the removal made in #7314.

Reason: Direct access to private services is discouraged because this practice:

  • Violates the dependency injection principle, which is at the heart of Symfony's architecture.
  • Creates a strong coupling between your code and the container, making it less modular.
  • Makes your application more fragile and much more difficult to maintain and test.

That's why PHPStan reported an error, which is ignored by our PHPStan config here: https://github.com/vinceAmstoutz/api-platform-core/blob/9e382e01bb4529d4ae63dbbeda01839d1da2994a/phpstan.neon.dist#L107-L110.

Historic reason:

After looking at its history, it looks like a legacy code backported from version to version of api-platform/core for backward compatibility. As discussed with @soyuka, it might be possible this behavior (this interface + DataProviderPass) was introduced long time ago to prevent a circular reference between any State Provider directly using the Serializer.

@vincentchalamon
Copy link
Contributor

@vinceAmstoutz the deprecation reason seems a bit generic to me, could you elaborate it please? Could be in the PR description for history purpose 🙂 Thanks!

@vinceAmstoutz
Copy link
Member Author

@vinceAmstoutz the deprecation reason seems a bit generic to me, could you elaborate it please? Could be in the PR description for history purpose 🙂 Thanks!

Thanks for your review @vincentchalamon! I added a description on the PR to solve that, is it ok for you?

@vinceAmstoutz vinceAmstoutz force-pushed the fix/deprecate-public-service-and-interface branch from 579d2ea to 9dce18e Compare August 22, 2025 12:57
@vincentchalamon
Copy link
Contributor

@vinceAmstoutz the deprecation reason seems a bit generic to me, could you elaborate it please? Could be in the PR description for history purpose 🙂 Thanks!

Thanks for your review @vincentchalamon! I added a description on the PR to solve that, is it ok for you?

OK but that doesn't explain to me why this class has been originally added, and why we don't need it anymore.

After looking at its history, it looks like a legacy code backported from version to version of api-platform/core for backward compatibility. As discussed with @soyuka, it might be possible this behavior (this interface + DataProviderPass) was introduced long time ago to prevent a circular reference between any State Provider directly using the Serializer.

To validate this deprecation, I suggest to:

  1. ensure using the Serializer directly in a State Provider doesn't create any exception nor circular reference of any type
  2. update this PR description with the previous explanation for history purpose

WDYT @soyuka @vinceAmstoutz?

@vinceAmstoutz
Copy link
Member Author

@vinceAmstoutz the deprecation reason seems a bit generic to me, could you elaborate it please? Could be in the PR description for history purpose 🙂 Thanks!

Thanks for your review @vincentchalamon! I added a description on the PR to solve that, is it ok for you?

OK but that doesn't explain to me why this class has been originally added, and why we don't need it anymore.

After looking at its history, it looks like a legacy code backported from version to version of api-platform/core for backward compatibility. As discussed with @soyuka, it might be possible this behavior (this interface + DataProviderPass) was introduced long time ago to prevent a circular reference between any State Provider directly using the Serializer.

To validate this deprecation, I suggest to:

1. ensure using the Serializer directly in a State Provider doesn't create any exception nor circular reference of any type

2. update this PR description with the previous explanation for history purpose

WDYT @soyuka @vinceAmstoutz?

Thanks for your research @vincentchalamon.

After some tests it's ok for me to use the Serializer directly in a State Provider (no exception and seems to have also no circular reference - not sure at 100% for this one)

Alos, I updated the PR description by adding your explanation. Is it better? Do not hesitate to improve it on your own if you want.

Copy link
Contributor

@vincentchalamon vincentchalamon left a comment

Choose a reason for hiding this comment

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

[nice to have]
Add a TODO in DataProviderPass to don't forget to remove it in 5.0

@vinceAmstoutz vinceAmstoutz force-pushed the fix/deprecate-public-service-and-interface branch from 9dce18e to 88862a4 Compare August 22, 2025 13:33
…lizableProvider

A PR for the removal was already made: api-platform#7314.
@vinceAmstoutz vinceAmstoutz force-pushed the fix/deprecate-public-service-and-interface branch from 88862a4 to 88be17c Compare August 22, 2025 13:39
@vinceAmstoutz
Copy link
Member Author

[nice to have] Add a TODO in DataProviderPass to don't forget to remove it in 5.0

Done. I also added it for src/Symfony/Bundle/ApiPlatformBundle.php and tests/Symfony/Bundle/ApiPlatformBundleTest.php.

@vinceAmstoutz vinceAmstoutz changed the base branch from main to 4.2 August 24, 2025 13:19
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.

3 participants