4
4
5
5
use Amp \Deferred ;
6
6
use Amp \Promise ;
7
- use Amp \Socket \ClientTlsContext ;
8
7
9
8
class Connection implements Link {
10
9
const REFRESH_GRANT = 0x01 ;
@@ -32,31 +31,6 @@ public function __construct(Internal\Processor $processor) {
32
31
$ this ->processor = $ processor ;
33
32
}
34
33
35
- public static function parseConnectionString (string $ connStr , ClientTlsContext $ sslOptions = null ): ConnectionConfig {
36
- $ db = null ;
37
- $ useCompression = "false " ;
38
-
39
- foreach (explode ("; " , $ connStr ) as $ param ) {
40
- list ($ key , $ $ key ) = array_map ("trim " , explode ("= " , $ param , 2 ) + [1 => null ]);
41
- }
42
- if (!isset ($ host , $ user , $ pass )) {
43
- throw new \Error ("Required parameters host, user and pass need to be passed in connection string " );
44
- }
45
-
46
- $ config = new ConnectionConfig ;
47
- $ config ->host = $ host ;
48
- $ config ->user = $ user ;
49
- $ config ->pass = $ pass ;
50
- $ config ->db = $ db ;
51
- $ config ->useCompression = $ useCompression && $ useCompression != "false " ;
52
-
53
- $ config ->ssl = $ sslOptions ;
54
-
55
- $ config ->resolveHost ();
56
-
57
- return $ config ;
58
- }
59
-
60
34
public function isAlive (): bool {
61
35
return $ this ->processor ->isAlive ();
62
36
}
@@ -93,18 +67,18 @@ public function setCharset(string $charset, string $collate = ""): Promise {
93
67
/** @see 14.6.2 COM_QUIT */
94
68
public function close () {
95
69
$ processor = $ this ->processor ;
96
- $ processor ->startCommand (static function () use ($ processor ) {
70
+ $ processor ->startCommand (static function () use ($ processor ) {
97
71
$ processor ->sendPacket ("\x01" );
98
72
$ processor ->initClosing ();
99
- })->onResolve (static function () use ($ processor ) {
73
+ })->onResolve (static function () use ($ processor ) {
100
74
$ processor ->close ();
101
75
});
102
76
}
103
77
104
78
/** @see 14.6.3 COM_INIT_DB */
105
79
public function useDb (string $ db ): Promise {
106
80
$ processor = $ this ->processor ;
107
- return $ processor ->startCommand (static function () use ($ processor , $ db ) {
81
+ return $ processor ->startCommand (static function () use ($ processor , $ db ) {
108
82
$ processor ->config ->db = $ db ;
109
83
$ processor ->sendPacket ("\x02$ db " );
110
84
});
@@ -114,7 +88,7 @@ public function useDb(string $db): Promise {
114
88
public function query (string $ query ): Promise {
115
89
$ processor = $ this ->processor ;
116
90
return \Amp \call (static function () use ($ processor , $ query ) {
117
- $ result = yield $ processor ->startCommand (static function () use ($ processor , $ query ) {
91
+ $ result = yield $ processor ->startCommand (static function () use ($ processor , $ query ) {
118
92
$ processor ->setQuery ($ query );
119
93
$ processor ->sendPacket ("\x03$ query " );
120
94
});
@@ -161,7 +135,7 @@ public function transaction(int $isolation = Transaction::COMMITTED): Promise {
161
135
/** @see 14.6.5 COM_FIELD_LIST */
162
136
public function listFields (string $ table , string $ like = "% " ): Promise {
163
137
$ processor = $ this ->processor ;
164
- return $ processor ->startCommand (static function () use ($ processor , $ table , $ like ) {
138
+ return $ processor ->startCommand (static function () use ($ processor , $ table , $ like ) {
165
139
$ processor ->sendPacket ("\x04$ table \0$ like " );
166
140
$ processor ->setFieldListing ();
167
141
});
@@ -171,7 +145,7 @@ public function listAllFields(string $table, string $like = "%"): Promise {
171
145
$ deferred = new Deferred ;
172
146
173
147
$ columns = [];
174
- $ when = function ($ error , $ array ) use (&$ columns , &$ when , $ deferred ) {
148
+ $ onResolve = function ($ error , $ array ) use (&$ columns , &$ onResolve , $ deferred ) {
175
149
if ($ error ) {
176
150
$ deferred ->fail ($ error );
177
151
return ;
@@ -181,25 +155,25 @@ public function listAllFields(string $table, string $like = "%"): Promise {
181
155
return ;
182
156
}
183
157
list ($ columns [], $ promise ) = $ array ;
184
- $ promise ->onResolve ($ when );
158
+ $ promise ->onResolve ($ onResolve );
185
159
};
186
- $ this ->listFields ($ table , $ like )->onResolve ($ when );
160
+ $ this ->listFields ($ table , $ like )->onResolve ($ onResolve );
187
161
188
162
return $ deferred ->promise ();
189
163
}
190
164
191
165
/** @see 14.6.6 COM_CREATE_DB */
192
166
public function createDatabase ($ db ) {
193
167
$ processor = $ this ->processor ;
194
- return $ processor ->startCommand (static function () use ($ processor , $ db ) {
168
+ return $ processor ->startCommand (static function () use ($ processor , $ db ) {
195
169
$ processor ->sendPacket ("\x05$ db " );
196
170
});
197
171
}
198
172
199
173
/** @see 14.6.7 COM_DROP_DB */
200
174
public function dropDatabase (string $ db ): Promise {
201
175
$ processor = $ this ->processor ;
202
- return $ processor ->startCommand (static function () use ($ processor , $ db ) {
176
+ return $ processor ->startCommand (static function () use ($ processor , $ db ) {
203
177
$ processor ->sendPacket ("\x06$ db " );
204
178
});
205
179
}
@@ -210,23 +184,23 @@ public function dropDatabase(string $db): Promise {
210
184
*/
211
185
public function refresh (int $ subcommand ): Promise {
212
186
$ processor = $ this ->processor ;
213
- return $ processor ->startCommand (static function () use ($ processor , $ subcommand ) {
187
+ return $ processor ->startCommand (static function () use ($ processor , $ subcommand ) {
214
188
$ processor ->sendPacket ("\x07" . chr ($ subcommand ));
215
189
});
216
190
}
217
191
218
192
/** @see 14.6.9 COM_SHUTDOWN */
219
193
public function shutdown (): Promise {
220
194
$ processor = $ this ->processor ;
221
- return $ processor ->startCommand (static function () use ($ processor ) {
195
+ return $ processor ->startCommand (static function () use ($ processor ) {
222
196
$ processor ->sendPacket ("\x08\x00" ); /* SHUTDOWN_DEFAULT / SHUTDOWN_WAIT_ALL_BUFFERS, only one in use */
223
197
});
224
198
}
225
199
226
200
/** @see 14.6.10 COM_STATISTICS */
227
201
public function statistics (): Promise {
228
202
$ processor = $ this ->processor ;
229
- return $ processor ->startCommand (static function () use ($ processor ) {
203
+ return $ processor ->startCommand (static function () use ($ processor ) {
230
204
$ processor ->sendPacket ("\x09" );
231
205
$ processor ->setStatisticsReading ();
232
206
});
@@ -235,7 +209,7 @@ public function statistics(): Promise {
235
209
/** @see 14.6.11 COM_PROCESS_INFO */
236
210
public function processInfo (): Promise {
237
211
$ processor = $ this ->processor ;
238
- return $ processor ->startCommand (static function () use ($ processor ) {
212
+ return $ processor ->startCommand (static function () use ($ processor ) {
239
213
$ processor ->sendPacket ("\x0a" );
240
214
$ processor ->setQuery ("SHOW PROCESSLIST " );
241
215
});
@@ -244,23 +218,23 @@ public function processInfo(): Promise {
244
218
/** @see 14.6.13 COM_PROCESS_KILL */
245
219
public function killProcess ($ process ): Promise {
246
220
$ processor = $ this ->processor ;
247
- return $ processor ->startCommand (static function () use ($ processor , $ process ) {
221
+ return $ processor ->startCommand (static function () use ($ processor , $ process ) {
248
222
$ processor ->sendPacket ("\x0c" . DataTypes::encode_int32 ($ process ));
249
223
});
250
224
}
251
225
252
226
/** @see 14.6.14 COM_DEBUG */
253
227
public function debugStdout (): Promise {
254
228
$ processor = $ this ->processor ;
255
- return $ processor ->startCommand (static function () use ($ processor ) {
229
+ return $ processor ->startCommand (static function () use ($ processor ) {
256
230
$ processor ->sendPacket ("\x0d" );
257
231
});
258
232
}
259
233
260
234
/** @see 14.6.15 COM_PING */
261
235
public function ping (): Promise {
262
236
$ processor = $ this ->processor ;
263
- return $ processor ->startCommand (static function () use ($ processor ) {
237
+ return $ processor ->startCommand (static function () use ($ processor ) {
264
238
$ processor ->sendPacket ("\x0e" );
265
239
});
266
240
}
@@ -292,15 +266,15 @@ public function changeUser($user, $pass, $db = null) {
292
266
/** @see 14.6.19 COM_RESET_CONNECTION */
293
267
public function resetConnection () {
294
268
$ processor = $ this ->processor ;
295
- return $ processor ->startCommand (static function () use ($ processor ) {
269
+ return $ processor ->startCommand (static function () use ($ processor ) {
296
270
$ processor ->sendPacket ("\x1f" );
297
271
});
298
272
}
299
273
300
274
/** @see 14.7.4 COM_STMT_PREPARE */
301
275
public function prepare (string $ query ): Promise {
302
276
$ processor = $ this ->processor ;
303
- $ promise = $ processor ->startCommand (static function () use ($ processor , $ query ) {
277
+ $ promise = $ processor ->startCommand (static function () use ($ processor , $ query ) {
304
278
$ processor ->setPrepare ($ query );
305
279
$ regex = <<<'REGEX'
306
280
(["'`])(?:\\(?:\\|\1)|(?!\1).)*+\1(*SKIP)(*F)|(\?)|:([a-zA-Z_]+)
0 commit comments