1 | <?php |
||
34 | class SearchProvider implements DataProviderInterface |
||
35 | { |
||
36 | |||
37 | use ConfigureTrait, |
||
38 | CriteriaTrait, |
||
39 | DataTrait, |
||
40 | ModelAwareTrait, |
||
41 | PaginationTrait, |
||
42 | SortAwareTrait; |
||
43 | |||
44 | const CriteriaClass = SearchCriteria::class; |
||
45 | |||
46 | /** |
||
47 | * Total items count cache |
||
48 | * @var int |
||
49 | */ |
||
50 | private $totalItemCount = null; |
||
51 | |||
52 | 9 | public function __construct($modelClass = null, $config = []) |
|
56 | |||
57 | 9 | protected function fetchData() |
|
58 | { |
||
59 | |||
60 | 9 | $criteria = $this->configureFetch(); |
|
61 | |||
62 | /** |
||
63 | * TODO Refactor this into SearchFinder class |
||
64 | */ |
||
65 | 9 | $qb = new QueryBuilder(); |
|
66 | 9 | if ($criteria instanceof SearchCriteria) |
|
67 | { |
||
68 | 9 | $models = $criteria->getModels(); |
|
69 | 9 | if (!empty($models)) |
|
70 | { |
||
71 | $qb->add($models); |
||
|
|||
72 | } |
||
73 | } |
||
74 | 9 | $model = $this->getModel(); |
|
75 | 9 | if (!empty($model) && !Event::handled($model, FinderInterface::EventBeforeFind)) |
|
76 | { |
||
77 | return []; |
||
78 | } |
||
79 | |||
80 | 9 | $modelCriteria = null; |
|
81 | |||
82 | // This check is required for plain php objects |
||
83 | 9 | if ($model instanceof WithCriteriaInterface) |
|
84 | { |
||
85 | $modelCriteria = $model->getDbCriteria(); |
||
86 | } |
||
87 | |||
88 | 9 | $criteria->mergeWith($modelCriteria); |
|
89 | 9 | if (!empty($model)) |
|
90 | { |
||
91 | 9 | $qb->add($model); |
|
92 | } |
||
93 | 9 | $qb->setCriteria($criteria); |
|
94 | 9 | $rawResults = $qb->search($criteria->getSearch()); |
|
95 | 9 | $results = []; |
|
96 | 9 | foreach ($rawResults as $data) |
|
97 | { |
||
98 | 9 | $model = SearchArray::toModel($data['_source']); |
|
99 | 9 | if ($model instanceof IndexAwareInterface) |
|
100 | { |
||
101 | 1 | $model->setIndex($data['_index']); |
|
102 | } |
||
103 | 9 | if ($model instanceof ScoreAwareInterface) |
|
104 | { |
||
105 | 1 | $model->setScore($data['_score']); |
|
106 | } |
||
107 | 9 | $results[] = $model; |
|
108 | } |
||
109 | 9 | return $results; |
|
110 | } |
||
111 | |||
112 | 7 | public function getItemCount($refresh = false) |
|
116 | |||
117 | 9 | public function getTotalItemCount() |
|
134 | |||
135 | } |
||
136 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: