feat(doctrine): add ChainFilter to compose filters on one parameter#8416
Open
soyuka wants to merge 1 commit into
Open
feat(doctrine): add ChainFilter to compose filters on one parameter#8416soyuka wants to merge 1 commit into
soyuka wants to merge 1 commit into
Conversation
ChainFilter applies each wrapped filter in turn so a single query-parameter key can accept several value shapes — e.g. equality plus comparison operators — without a bespoke decorator. Each primary self-selects by value shape (ComparisonFilter ignores scalars; ExactFilter/PartialSearchFilter ignore operator-map arrays), so the composite applies all of them and merges their OpenAPI parameters. ManagerRegistry/Logger are forwarded to aware inner filters, mirroring FreeTextQueryFilter. Also adds the associative-array guard on ExactFilter/PartialSearchFilter, which is load-bearing for the chain (same guard as api-platform#8415 on 4.3; will reconcile on merge-up).
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.
What
Adds
ApiPlatform\Doctrine\Orm\Filter\ChainFilter— a thin composite that holds several filters and applies each in turn on a single query-parameter key:?quantity=10→ equality?quantity[lt]=10/[lte]/[gt]/[gte]/[ne]→ comparisonEach primary self-selects by value shape —
ComparisonFilterignores scalars,ExactFilter/PartialSearchFilterignore associative (operator-map) arrays — so the composite just applies all of them; nosupports()method needed.getOpenApiParameters()merges every wrapped filter's parameters, so the docs show the plain field and the operator variants.ManagerRegistry/Loggerare forwarded to aware inner filters, mirroringFreeTextQueryFilter.Why
Users combining equality with comparison/date operators on one property previously had to hand-write a bespoke dispatching decorator (see #8407).
ChainFiltermakes it declarative and reusable, staying on the "thin composers over single-responsibility primaries" line of the new filter system (likeOrFilter,FreeTextQueryFilter).Note on the guard
This PR also carries the associative-array guard on
ExactFilter/PartialSearchFilter(if (\is_array($value) && !array_is_list($value)) return;). That guard is load-bearing for the chain — without it,ExactFiltertreats an operator-map as anIN (...)list and corrupts the comparison. The same guard ships on4.3in #8415; the two will reconcile cleanly on merge-up (identical hunk). If you prefer, merge #8415 up first and I'll rebase this to drop the duplicate.Test
tests/Functional/Parameters/ChainFilterTest.php: exact match,[lt],[gte], and an OpenAPI assertion that both filters' parameters are merged. Fulltests/Functional/Parameters/suite green (447 tests), php-cs-fixer clean, PHPStan[OK].