fix(symfony): isolate api_platform.property_info tags#8206
Open
soyuka wants to merge 1 commit into
Open
Conversation
PR api-platform#7969 (shipped in 4.3.6) turned `api_platform.property_info` from an alias of Symfony's `property_info` into a self-contained service that registered `ReflectionExtractor`, `PhpDocExtractor`, and `PhpStanExtractor` tagged with the public `property_info.*` namespace. Two problems followed: - Symfony's framework `property_info` consumes the same public tag iterator and therefore inherited our `PhpStanExtractor` too — including in `validator.property_info_loader`. On projects with Doctrine interfaces carrying `@template T of object` (e.g. Sylius), `bin/console cache:clear` crashed inside `PhpStanExtractor::getType` with "Cannot create union with both \"object\" and class type." - Tagging our extractors with only a private namespace would have fixed the leak but would also have lost inheritance of third-party-registered extractors (notably Doctrine's `DoctrineExtractor`), breaking serialization and validation (embedded objects vs IRIs, "array given" on persist, missing constraint violations). Fix: - Tag API Platform's 3 fallback extractors with private `api_platform.property_info.*` tags only. - `api_platform.property_info` consumes the private tag iterators. - Add `PropertyInfoTagPass`, a one-way bridge compiler pass that copies every public `property_info.{suffix}` tag (preserving attributes such as priority) onto the same service as `api_platform.property_info.{suffix}`, skipping services already carrying the private tag. Result: framework `property_info` is untouched (public tags only, no API Platform extractors leak in), while `api_platform.property_info` still inherits framework + Doctrine + third-party extractors via the bridged private tags. The api-platform#7876 fallback path stays intact when framework's `property_info` is absent. Fixes api-platform#8201 Refs api-platform#7969 api-platform#7876
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
api_platform.property_infoextractors were tagged with the global Symfonyproperty_info.*tag namespace in #7969. Symfony's frameworkproperty_infoservice consumestagged_iterator('property_info.type_extractor')and so picked up API Platform'sPhpStanExtractortoo — including in the chain used byvalidator.property_info_loader.On projects depending on
doctrine/persistence/doctrine/common(e.g. Sylius),bin/console cache:clearthen crashes inside the validator while walking Doctrine interfaces carrying@template T of object:This PR renames the tags to
api_platform.property_info.*(private namespace) and updates thePropertyInfoExtractorcomposing service to consume the private tags. The framework'sproperty_infois no longer mutated by API Platform, restoring the design intent expressed during #7969 review ("stop touchingframework.property_infoentirely").src/Symfony/Bundle/Resources/config/api.php— three extractors (reflection / php_doc / phpstan) and the composingPropertyInfoExtractorswitch fromproperty_info.*toapi_platform.property_info.*.testPropertyInfoExtractorsDoNotLeakIntoFrameworkPropertyInforegression test asserting tag isolation.Test plan
vendor/bin/phpunit --filter testPropertyInfoExtractorsDoNotLeakIntoFrameworkPropertyInfo— passes (15 assertions)vendor/bin/phpunit tests/Symfony/Bundle/ApiPlatformBundleTest.php— passesrm -rf tests/Fixtures/app/var/cache/test && tests/Fixtures/app/console cache:clear --env=test— clears cleanlycomposer linkof this branch) — confirmedcache:clearexits 0Fixes #8201
Refs #7969