@@ -512,20 +512,16 @@ private function getParameterArgs(Operation $operation, array $args = []): array
512512 $ name = key ($ leafs );
513513
514514 $ filterLeafs = [];
515- if (($ filterId = $ parameter ->getFilter ()) && $ this ->filterLocator ->has ($ filterId )) {
516- $ filter = $ this ->filterLocator ->get ($ filterId );
517-
518- if ($ filter instanceof FilterInterface) {
519- $ property = $ parameter ->getProperty () ?? $ name ;
520- $ property = str_replace ('. ' , $ this ->nestingSeparator , $ property );
521- $ description = $ filter ->getDescription ($ operation ->getClass ());
522-
523- foreach ($ description as $ descKey => $ descValue ) {
524- $ descKey = str_replace ('. ' , $ this ->nestingSeparator , $ descKey );
525- parse_str ($ descKey , $ descValues );
526- if (isset ($ descValues [$ property ]) && \is_array ($ descValues [$ property ])) {
527- $ filterLeafs = array_merge ($ filterLeafs , $ descValues [$ property ]);
528- }
515+ if ($ filter = $ this ->resolveFilter ($ parameter ->getFilter ())) {
516+ $ property = $ parameter ->getProperty () ?? $ name ;
517+ $ property = str_replace ('. ' , $ this ->nestingSeparator , $ property );
518+ $ description = $ filter ->getDescription ($ operation ->getClass ());
519+
520+ foreach ($ description as $ descKey => $ descValue ) {
521+ $ descKey = str_replace ('. ' , $ this ->nestingSeparator , $ descKey );
522+ parse_str ($ descKey , $ descValues );
523+ if (isset ($ descValues [$ property ]) && \is_array ($ descValues [$ property ])) {
524+ $ filterLeafs = array_merge ($ filterLeafs , $ descValues [$ property ]);
529525 }
530526 }
531527 }
@@ -612,12 +608,12 @@ private function getFilterArgs(array $args, ?string $resourceClass, string $root
612608 }
613609
614610 foreach ($ resourceOperation ->getFilters () ?? [] as $ filterId ) {
615- if (!$ this ->filterLocator -> has ($ filterId )) {
611+ if (!( $ filter = $ this ->resolveFilter ($ filterId) )) {
616612 continue ;
617613 }
618614
619615 $ entityClass = $ this ->getStateOptionsClass ($ resourceOperation , $ resourceOperation ->getClass ());
620- foreach ($ this -> filterLocator -> get ( $ filterId ) ->getDescription ($ entityClass ) as $ key => $ description ) {
616+ foreach ($ filter ->getDescription ($ entityClass ) as $ key => $ description ) {
621617 $ filterType = \in_array ($ description ['type ' ], TypeIdentifier::values (), true ) ? Type::builtin ($ description ['type ' ]) : Type::object ($ description ['type ' ]);
622618 if (!($ description ['required ' ] ?? false )) {
623619 $ filterType = Type::nullable ($ filterType );
@@ -751,4 +747,24 @@ private function normalizePropertyName(string $property, string $resourceClass):
751747
752748 return $ this ->nameConverter ->normalize ($ property , $ resourceClass );
753749 }
750+
751+ /**
752+ * Resolves a filter reference to a {@see FilterInterface} instance, supporting
753+ * both a string service id (legacy/locator path) and an object form
754+ * (`new QueryParameter(filter: new SortFilter())`).
755+ */
756+ private function resolveFilter (mixed $ filter ): ?FilterInterface
757+ {
758+ if ($ filter instanceof FilterInterface) {
759+ return $ filter ;
760+ }
761+
762+ if (\is_string ($ filter ) && $ this ->filterLocator ->has ($ filter )) {
763+ $ resolved = $ this ->filterLocator ->get ($ filter );
764+
765+ return $ resolved instanceof FilterInterface ? $ resolved : null ;
766+ }
767+
768+ return null ;
769+ }
754770}
0 commit comments