@@ -31,27 +31,54 @@ final class FreeTextQueryFilter implements FilterInterface, ManagerRegistryAware
3131 use ManagerRegistryAwareTrait;
3232
3333 /**
34- * @param list<string> $properties an array of properties, defaults to `parameter->getProperties()`
34+ * @param FilterInterface|array<string, FilterInterface> $filter a filter applied to every property,
35+ * or a map of `property => filter` to use a
36+ * dedicated filter per property
37+ * @param list<string>|null $properties an array of properties, defaults to
38+ * the map keys when `$filter` is a map,
39+ * otherwise to `parameter->getProperties()`
3540 */
36- public function __construct (private readonly FilterInterface $ filter , private readonly ?array $ properties = null )
41+ public function __construct (private readonly FilterInterface | array $ filter , private readonly ?array $ properties = null )
3742 {
3843 }
3944
4045 public function apply (QueryBuilder $ queryBuilder , QueryNameGeneratorInterface $ queryNameGenerator , string $ resourceClass , ?Operation $ operation = null , array $ context = []): void
4146 {
42- if ($ this ->filter instanceof ManagerRegistryAwareInterface) {
43- $ this ->filter ->setManagerRegistry ($ this ->getManagerRegistry ());
44- }
47+ $ filterMap = \is_array ($ this ->filter ) ? $ this ->filter : null ;
48+
49+ if (null === $ filterMap ) {
50+ if ($ this ->filter instanceof ManagerRegistryAwareInterface) {
51+ $ this ->filter ->setManagerRegistry ($ this ->getManagerRegistry ());
52+ }
4553
46- if ($ this ->filter instanceof LoggerAwareInterface) {
47- $ this ->filter ->setLogger ($ this ->getLogger ());
54+ if ($ this ->filter instanceof LoggerAwareInterface) {
55+ $ this ->filter ->setLogger ($ this ->getLogger ());
56+ }
4857 }
4958
5059 $ parameter = $ context ['parameter ' ];
5160 $ qb = clone $ queryBuilder ;
5261 $ qb ->resetDQLPart ('where ' );
5362 $ qb ->setParameters (new ArrayCollection ());
54- foreach ($ this ->properties ?? $ parameter ->getProperties () ?? [] as $ property ) {
63+ $ properties = $ this ->properties ?? (null !== $ filterMap ? array_keys ($ filterMap ) : $ parameter ->getProperties ()) ?? [];
64+
65+ foreach ($ properties as $ property ) {
66+ $ filter = null !== $ filterMap ? ($ filterMap [$ property ] ?? null ) : $ this ->filter ;
67+
68+ if (null === $ filter ) {
69+ continue ;
70+ }
71+
72+ if (null !== $ filterMap ) {
73+ if ($ filter instanceof ManagerRegistryAwareInterface) {
74+ $ filter ->setManagerRegistry ($ this ->getManagerRegistry ());
75+ }
76+
77+ if ($ filter instanceof LoggerAwareInterface) {
78+ $ filter ->setLogger ($ this ->getLogger ());
79+ }
80+ }
81+
5582 $ subParameter = $ parameter ->withProperty ($ property );
5683
5784 $ nestedPropertiesInfo = $ parameter ->getExtraProperties ()['nested_properties_info ' ] ?? [];
@@ -62,7 +89,7 @@ public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $q
6289 : [],
6390 ]);
6491
65- $ this -> filter ->apply (
92+ $ filter ->apply (
6693 $ qb ,
6794 $ queryNameGenerator ,
6895 $ resourceClass ,
0 commit comments