1 | <?php |
||
18 | class SearchFinder extends AbstractFinder implements FinderInterface, ModelsAwareInterface |
||
19 | { |
||
20 | |||
21 | use FinderHelpers, |
||
22 | UniqueModelsAwareTrait; |
||
23 | |||
24 | /** |
||
25 | * Constructor |
||
26 | * |
||
27 | * @param object|object[] $models Model or array of model instances |
||
28 | * @param IndexManager $im |
||
29 | * @param Manganel $manganel |
||
30 | */ |
||
31 | 30 | public function __construct($models, $im = null, $manganel = null) |
|
32 | { |
||
33 | 30 | if (is_array($models)) |
|
34 | { |
||
35 | 11 | $model = current($models); |
|
36 | } |
||
37 | else |
||
38 | { |
||
39 | // Ensure array and that model is set for further usage |
||
40 | 19 | $model = $models; |
|
41 | 19 | $models = [$models]; |
|
42 | } |
||
43 | 30 | foreach ($models as $modelIndex => $modelSignature) |
|
44 | { |
||
45 | 30 | if (is_string($modelSignature)) |
|
46 | { |
||
47 | 30 | $models[$modelIndex] = new $modelSignature; |
|
48 | } |
||
49 | } |
||
50 | 30 | if (is_string($model)) |
|
51 | { |
||
52 | 3 | $model = new $model; |
|
53 | } |
||
54 | 30 | if (null === $manganel) |
|
55 | { |
||
56 | 30 | $manganel = Manganel::create($model); |
|
57 | } |
||
58 | 30 | assert($model instanceof AnnotatedInterface); |
|
59 | |||
60 | 30 | $this->setModel($model); |
|
61 | 30 | $this->setModels($models); |
|
62 | 30 | $this->setScopeManager(new MultiScopeManager($model, $models)); |
|
63 | 30 | $this->setAdapter(new ElasticSearchAdapter($models)); |
|
64 | |||
65 | 30 | $this->setProfiler($manganel->getProfiler()); |
|
66 | 30 | $this->setFinderEvents(new Helpers\MultiFinderEvents()); |
|
67 | 30 | $this->withCursor(false); |
|
68 | 30 | } |
|
69 | |||
70 | /** |
||
71 | * Create search finder instance. |
||
72 | * |
||
73 | * @param AnnotatedInterface $model |
||
74 | * @param IndexManager $im |
||
75 | * @param Manganel $manganel |
||
76 | * @return FinderInterface |
||
77 | */ |
||
78 | public static function create(AnnotatedInterface $model, $im = null, Manganel $manganel = null) |
||
82 | |||
83 | 21 | protected function createModel($data) |
|
90 | |||
91 | } |
||
92 |