1 | <?php |
||
12 | trait SearchTrait |
||
13 | { |
||
14 | /** |
||
15 | * @var array $searchFields |
||
16 | */ |
||
17 | private static $searchFields = []; |
||
18 | |||
19 | /** |
||
20 | * @var array $boostFields |
||
21 | */ |
||
22 | private static $boostFields = []; |
||
23 | |||
24 | /** |
||
25 | * Set up |
||
26 | * |
||
27 | * @throws \Exception |
||
28 | * @return void |
||
29 | */ |
||
30 | 15 | private static function setup() |
|
31 | { |
||
32 | // Ignoring PHP bug #53727 here, Eloquent Models implement several interfaces. |
||
33 | 15 | if (!is_subclass_of(static::class, Model::class)) { |
|
34 | throw new \Exception( |
||
35 | 'SearchTrait must only be used with Eloquent models, ['.get_called_class().'] used.' |
||
36 | ); |
||
37 | } |
||
38 | |||
39 | 15 | static::searchFields(); |
|
40 | 15 | } |
|
41 | |||
42 | /** |
||
43 | * Search Fields |
||
44 | * |
||
45 | * This should never get called. If it does get called, then it means that the Model which is using |
||
46 | * "SearchTrait" has not declared a "searchFields" method and made it static. |
||
47 | * |
||
48 | * @throws \Exception |
||
49 | */ |
||
50 | private static function searchFields() |
||
51 | { |
||
52 | throw new \Exception("Method [searchFields] must exist and be static."); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param array $fields |
||
57 | */ |
||
58 | 15 | public static function setSearchFields(array $fields) |
|
62 | |||
63 | /** |
||
64 | * @return array |
||
65 | */ |
||
66 | public static function getSearchFields() |
||
70 | |||
71 | /** |
||
72 | * @param array $fields |
||
73 | * @throws \Exception |
||
74 | */ |
||
75 | public static function setBoostFields(array $fields) |
||
84 | |||
85 | /** |
||
86 | * @return array |
||
87 | */ |
||
88 | public static function getBoostFields() |
||
92 | |||
93 | /** |
||
94 | * @return mixed |
||
95 | */ |
||
96 | public static function search() |
||
105 | |||
106 | /** |
||
107 | * @return void |
||
108 | */ |
||
109 | 15 | public static function bootSearchTrait() |
|
116 | |||
117 | /** |
||
118 | * @param Store $store |
||
119 | * @return \Closure |
||
120 | */ |
||
121 | private static function insertCallback(Store $store) |
||
128 | |||
129 | /** |
||
130 | * @param Store $store |
||
131 | * @return \Closure |
||
132 | */ |
||
133 | private static function deleteCallback(Store $store) |
||
140 | } |
||
141 |