14
14
15
15
class Connection extends BaseConnection
16
16
{
17
-
17
+
18
18
protected $ client ;
19
19
protected $ index ;
20
20
protected $ maxSize ;
@@ -25,23 +25,23 @@ class Connection extends BaseConnection
25
25
protected $ portInHeaders = null ;
26
26
protected $ rebuild = false ;
27
27
protected $ allowIdSort = true ;
28
-
28
+
29
29
public function __construct (array $ config )
30
30
{
31
31
$ this ->config = $ config ;
32
-
32
+
33
33
$ this ->setOptions ($ config );
34
-
34
+
35
35
$ this ->client = $ this ->buildConnection ();
36
-
36
+
37
37
$ this ->useDefaultPostProcessor ();
38
-
38
+
39
39
$ this ->useDefaultSchemaGrammar ();
40
-
40
+
41
41
$ this ->useDefaultQueryGrammar ();
42
-
42
+
43
43
}
44
-
44
+
45
45
public function setOptions ($ config )
46
46
{
47
47
if (!empty ($ config ['index_prefix ' ])) {
@@ -60,23 +60,23 @@ public function setOptions($config)
60
60
$ this ->portInHeaders = $ config ['options ' ]['port_in_host_header ' ];
61
61
}
62
62
}
63
-
63
+
64
64
public function getIndexPrefix (): string |null
65
65
{
66
66
return $ this ->indexPrefix ;
67
67
}
68
-
68
+
69
69
public function setIndexPrefix ($ newPrefix ): void
70
70
{
71
71
$ this ->indexPrefix = $ newPrefix ;
72
72
}
73
-
74
-
73
+
74
+
75
75
public function getTablePrefix (): string |null
76
76
{
77
77
return $ this ->getIndexPrefix ();
78
78
}
79
-
79
+
80
80
public function setIndex ($ index ): string
81
81
{
82
82
$ this ->index = $ index ;
@@ -85,134 +85,134 @@ public function setIndex($index): string
85
85
$ this ->index = $ this ->indexPrefix .'_ ' .$ index ;
86
86
}
87
87
}
88
-
88
+
89
89
return $ this ->getIndex ();
90
90
}
91
-
91
+
92
92
public function getSchemaGrammar ()
93
93
{
94
94
return new Schema \Grammar ($ this );
95
95
}
96
-
96
+
97
97
public function getIndex (): string
98
98
{
99
99
return $ this ->index ;
100
100
}
101
-
101
+
102
102
public function setMaxSize ($ value )
103
103
{
104
104
$ this ->maxSize = $ value ;
105
105
}
106
-
107
-
106
+
107
+
108
108
public function table ($ table , $ as = null )
109
109
{
110
110
$ query = new Query \Builder ($ this , new Query \Processor ());
111
-
111
+
112
112
return $ query ->from ($ table );
113
113
}
114
-
114
+
115
115
/**
116
116
* @inheritdoc
117
117
*/
118
118
public function getSchemaBuilder ()
119
119
{
120
120
return new Schema \Builder ($ this );
121
121
}
122
-
123
-
122
+
123
+
124
124
/**
125
125
* @inheritdoc
126
126
*/
127
127
public function disconnect ()
128
128
{
129
129
unset($ this ->connection );
130
130
}
131
-
132
-
131
+
132
+
133
133
/**
134
134
* @inheritdoc
135
135
*/
136
136
public function getDriverName (): string
137
137
{
138
138
return 'opensearch ' ;
139
139
}
140
-
140
+
141
141
/**
142
142
* @inheritdoc
143
143
*/
144
144
protected function getDefaultPostProcessor ()
145
145
{
146
146
return new Query \Processor ();
147
147
}
148
-
148
+
149
149
/**
150
150
* @inheritdoc
151
151
*/
152
152
protected function getDefaultQueryGrammar ()
153
153
{
154
154
return new Query \Grammar ();
155
155
}
156
-
156
+
157
157
/**
158
158
* @inheritdoc
159
159
*/
160
160
protected function getDefaultSchemaGrammar ()
161
161
{
162
162
return new Schema \Grammar ();
163
163
}
164
-
164
+
165
165
public function rebuildConnection ()
166
166
{
167
167
$ this ->rebuild = true ;
168
168
}
169
-
169
+
170
170
public function getClient ()
171
171
{
172
172
return $ this ->client ;
173
173
}
174
-
174
+
175
175
public function getMaxSize ()
176
176
{
177
177
return $ this ->maxSize ;
178
178
}
179
-
179
+
180
180
public function getAllowIdSort ()
181
181
{
182
182
return $ this ->allowIdSort ;
183
183
}
184
-
185
-
184
+
185
+
186
186
//----------------------------------------------------------------------
187
187
// Connection Builder
188
188
//----------------------------------------------------------------------
189
-
189
+
190
190
protected function buildConnection (): Client
191
191
{
192
192
$ hosts = config ('database.connections.opensearch.hosts ' ) ?? null ;
193
-
193
+
194
194
$ builder = ClientBuilder::create ()->setHosts ($ hosts );
195
195
$ builder = $ this ->_buildOptions ($ builder );
196
196
$ builder = $ this ->_buildAuth ($ builder );
197
197
$ builder = $ this ->_buildSigV4 ($ builder );
198
198
$ builder = $ this ->_buildSSL ($ builder );
199
-
199
+
200
200
return $ builder ->build ();
201
-
201
+
202
202
}
203
-
203
+
204
204
protected function _buildAuth (ClientBuilder $ builder ): ClientBuilder
205
205
{
206
-
206
+
207
207
$ username = config ('database.connections.opensearch.basic_auth.username ' ) ?? null ;
208
208
$ pass = config ('database.connections.opensearch.basic_auth.password ' ) ?? null ;
209
209
if ($ username && $ pass ) {
210
210
$ builder ->setBasicAuthentication ($ username , $ pass );
211
211
}
212
-
212
+
213
213
return $ builder ;
214
214
}
215
-
215
+
216
216
protected function _buildSigV4 (ClientBuilder $ builder ): ClientBuilder
217
217
{
218
218
$ provider = config ('database.connections.opensearch.sig_v4.provider ' ) ?? null ;
@@ -227,10 +227,10 @@ protected function _buildSigV4(ClientBuilder $builder): ClientBuilder
227
227
if ($ service ) {
228
228
$ builder ->setSigV4Service ($ service );
229
229
}
230
-
230
+
231
231
return $ builder ;
232
232
}
233
-
233
+
234
234
protected function _buildSSL (ClientBuilder $ builder ): ClientBuilder
235
235
{
236
236
$ sslCert = config ('database.connections.opensearch.ssl.cert ' ) ?? null ;
@@ -243,10 +243,10 @@ protected function _buildSSL(ClientBuilder $builder): ClientBuilder
243
243
if ($ sslKey ) {
244
244
$ builder ->setSSLKey ($ sslKey , $ sslKeyPassword );
245
245
}
246
-
246
+
247
247
return $ builder ;
248
248
}
249
-
249
+
250
250
protected function _buildOptions (ClientBuilder $ builder ): ClientBuilder
251
251
{
252
252
$ builder ->setSSLVerification ($ this ->sslVerification );
@@ -259,17 +259,17 @@ protected function _buildOptions(ClientBuilder $builder): ClientBuilder
259
259
if (!empty ($ this ->portInHeaders )) {
260
260
$ builder ->includePortInHostHeader ($ this ->portInHeaders );
261
261
}
262
-
262
+
263
263
return $ builder ;
264
264
}
265
-
266
-
267
-
268
-
265
+
266
+
267
+
268
+
269
269
//----------------------------------------------------------------------
270
270
// Dynamic call routing to DSL bridge
271
271
//----------------------------------------------------------------------
272
-
272
+
273
273
public function __call ($ method , $ parameters )
274
274
{
275
275
if (!$ this ->index ) {
@@ -280,7 +280,7 @@ public function __call($method, $parameters)
280
280
$ this ->rebuild = false ;
281
281
}
282
282
$ bridge = new Bridge ($ this );
283
-
283
+
284
284
return $ bridge ->{'process ' .Str::studly ($ method )}(...$ parameters );
285
285
}
286
286
}
0 commit comments