1 | <?php |
||
36 | class Manganel |
||
37 | { |
||
38 | |||
39 | const DefaultIndexId = 'manganel'; |
||
40 | |||
41 | public $decorators = [ |
||
42 | SearchCriteria::class => [ |
||
43 | ConditionDecorator::class, |
||
44 | ConditionsDecorator::class, |
||
45 | ScrollDecorator::class, |
||
46 | SearchDecorator::class, |
||
47 | InDecorator::class, |
||
48 | SimpleTermDecorator::class |
||
49 | ] |
||
50 | ]; |
||
51 | public $hosts = [ |
||
52 | 'localhost:9200' |
||
53 | ]; |
||
54 | public $auth = null; |
||
55 | public $username = ''; |
||
56 | public $password = ''; |
||
57 | public $params = []; |
||
58 | |||
59 | /** |
||
60 | * TODO Enforce lowercase |
||
61 | */ |
||
62 | public $index = 'my_index'; |
||
63 | public $indexId = self::DefaultIndexId; |
||
64 | |||
65 | /** |
||
66 | * Whether to use refresh option when indexing document. |
||
67 | * NOTE: Due to performance reasons, this should be set to `true` only when |
||
68 | * really necessary - so it can be also callback. |
||
69 | * |
||
70 | * Callback function signature: |
||
71 | * ``` |
||
72 | * function(AnnotatedInterface $model) |
||
73 | * ``` |
||
74 | * @var string|Closure |
||
75 | */ |
||
76 | public $refresh = false; |
||
77 | |||
78 | /** |
||
79 | * |
||
80 | * @var Client |
||
81 | */ |
||
82 | private $client = null; |
||
83 | |||
84 | /** |
||
85 | * Dependency injection container |
||
86 | * @var EmbeDi |
||
87 | */ |
||
88 | private $di = null; |
||
89 | |||
90 | /** |
||
91 | * Instances of manganel |
||
92 | * @var Manganel[] |
||
93 | */ |
||
94 | private static $mnl = []; |
||
95 | |||
96 | /** |
||
97 | * Hash map of class name to id. This is to reduce overhead of Mangan::fromModel() |
||
98 | * @var string[] |
||
99 | */ |
||
100 | private static $classToId = []; |
||
101 | |||
102 | /** |
||
103 | * Profiler instance |
||
104 | * @var ProfilerInterface |
||
105 | */ |
||
106 | private $profiler = null; |
||
107 | |||
108 | /** |
||
109 | * Class constructor |
||
110 | * @codeCoverageIgnore This is implicitly tested |
||
111 | * @param string $indexId |
||
112 | */ |
||
113 | public function __construct($indexId = self::DefaultIndexId) |
||
128 | |||
129 | /** |
||
130 | * @codeCoverageIgnore This is implicitly tested |
||
131 | * @param AnnotatedInterface $model |
||
132 | * @return static |
||
133 | */ |
||
134 | public static function create(AnnotatedInterface $model) |
||
148 | |||
149 | /** |
||
150 | * Get flyweight instance of Manganel component. |
||
151 | * Only one instance will be created for each `$indexId`. |
||
152 | * |
||
153 | * @codeCoverageIgnore This is implicitly tested |
||
154 | * @new |
||
155 | * @param string $indexId |
||
156 | * @return Manganel |
||
157 | */ |
||
158 | public static function fly($indexId = self::DefaultIndexId) |
||
170 | |||
171 | /** |
||
172 | * @codeCoverageIgnore This is implicitly tested |
||
173 | */ |
||
174 | public function init() |
||
178 | |||
179 | /** |
||
180 | * Drop current index |
||
181 | * @return bool |
||
182 | */ |
||
183 | public function drop() |
||
195 | |||
196 | /** |
||
197 | * @codeCoverageIgnore This is implicitly tested |
||
198 | * @return Client |
||
199 | */ |
||
200 | public function getClient() |
||
216 | |||
217 | /** |
||
218 | * Get profiler instance. This is guaranted, if not configured will return NullProfiller. |
||
219 | * @see NullProfiler |
||
220 | * @return ProfilerInterface |
||
221 | */ |
||
222 | 4 | public function getProfiler() |
|
234 | |||
235 | /** |
||
236 | * Set profiler instance |
||
237 | * @param ProfilerInterface $profiller |
||
238 | * @return static |
||
239 | */ |
||
240 | public function setProfiler(ProfilerInterface $profiller) |
||
245 | |||
246 | } |
||
247 |