|
7 | 7 | class Filter |
8 | 8 | { |
9 | 9 | public function __construct( |
10 | | - private readonly FilterRegistry $filterRegistry |
| 10 | + private readonly FilterRegistry $filterRegistry, |
| 11 | + private readonly FilterScopeFactory $filterScopeFactory, |
11 | 12 | ) { |
12 | 13 | } |
13 | 14 |
|
14 | 15 | public function filter( |
15 | 16 | ComponentInterface $component, |
16 | 17 | mixed $data = null, |
17 | | - ?string $scope = null |
| 18 | + mixed $propertyName = null |
18 | 19 | ): mixed { |
19 | | - $requestedFilters = $component->getFilters(); |
| 20 | + $filters = $this->filterRegistry->getApplicableFilters( |
| 21 | + $component->getFilters() |
| 22 | + ); |
| 23 | + |
| 24 | + $filterScope = $this->filterScopeFactory->create(); |
| 25 | + $filterScope->setComponent($component); |
| 26 | + $filterScope->setProperty($propertyName); |
20 | 27 |
|
21 | 28 | if (empty($data) || is_bool($data) || is_int($data)) { |
22 | 29 | return $data; |
23 | 30 | } |
24 | 31 |
|
25 | 32 | if (is_array($data)) { |
26 | | - foreach ($data as $name => $value) { |
27 | | - $data[$name] = $this->filter($component, $value, $name); |
| 33 | + foreach ($data as $propertyName => $value) { |
| 34 | + $data[$propertyName] = $this->filter($component, $value, $propertyName); |
28 | 35 | } |
29 | 36 |
|
30 | 37 | return $data; |
31 | 38 | } |
32 | 39 |
|
33 | | - $filters = $this->filterRegistry->getApplicableFilters( |
34 | | - $requestedFilters |
35 | | - ); |
36 | 40 | foreach ($filters as $filter) { |
37 | | - $data = $filter->filter($data, $component, $scope); |
| 41 | + $data = $filter->filter($data, $filterScope); |
38 | 42 | } |
39 | 43 |
|
40 | 44 | return $data; |
|
0 commit comments