1 | <?php |
||
30 | class Manganel |
||
31 | { |
||
32 | |||
33 | const DefaultIndexId = 'manganel'; |
||
34 | |||
35 | public $decorators = [ |
||
36 | SearchCriteria::class => [ |
||
37 | ConditionDecorator::class, |
||
38 | ConditionsDecorator::class, |
||
39 | ScrollDecorator::class, |
||
40 | SearchDecorator::class, |
||
41 | ] |
||
42 | ]; |
||
43 | public $hosts = [ |
||
44 | 'localhost:9200' |
||
45 | ]; |
||
46 | public $auth = null; |
||
47 | public $username = ''; |
||
48 | public $password = ''; |
||
49 | public $params = []; |
||
50 | |||
51 | /** |
||
52 | * TODO Enforce lowercase |
||
53 | */ |
||
54 | public $index = 'my_index'; |
||
55 | public $indexId = self::DefaultIndexId; |
||
56 | |||
57 | /** |
||
58 | * |
||
59 | * @var Client |
||
60 | */ |
||
61 | private $client = null; |
||
62 | |||
63 | /** |
||
64 | * Dependency injection container |
||
65 | * @var EmbeDi |
||
66 | */ |
||
67 | private $di = null; |
||
68 | |||
69 | /** |
||
70 | * Instances of manganel |
||
71 | * @var Manganel[] |
||
72 | */ |
||
73 | private static $mnl = []; |
||
74 | |||
75 | /** |
||
76 | * Hash map of class name to id. This is to reduce overhead of Mangan::fromModel() |
||
77 | * @var string[] |
||
78 | */ |
||
79 | private static $classToId = []; |
||
80 | |||
81 | /** |
||
82 | * Class constructor |
||
83 | * @codeCoverageIgnore This is implicitly tested |
||
84 | * @param string $indexId |
||
85 | */ |
||
86 | public function __construct($indexId = self::DefaultIndexId) |
||
101 | |||
102 | /** |
||
103 | * @codeCoverageIgnore This is implicitly tested |
||
104 | * @param AnnotatedInterface $model |
||
105 | * @return static |
||
106 | */ |
||
107 | public static function create(AnnotatedInterface $model) |
||
121 | |||
122 | /** |
||
123 | * Get flyweight instance of Manganel component. |
||
124 | * Only one instance will be created for each `$indexId`. |
||
125 | * |
||
126 | * @codeCoverageIgnore This is implicitly tested |
||
127 | * @new |
||
128 | * @param string $indexId |
||
129 | * @return Manganel |
||
130 | */ |
||
131 | public static function fly($indexId = self::DefaultIndexId) |
||
143 | |||
144 | /** |
||
145 | * @codeCoverageIgnore This is implicitly tested |
||
146 | */ |
||
147 | public function init() |
||
151 | |||
152 | /** |
||
153 | * Drop current index |
||
154 | * @return bool |
||
155 | */ |
||
156 | 1 | public function drop() |
|
168 | |||
169 | /** |
||
170 | * @codeCoverageIgnore This is implicitly tested |
||
171 | * @return Client |
||
172 | */ |
||
173 | public function getClient() |
||
189 | |||
190 | } |
||
191 |