@@ -124,16 +124,8 @@ public function __construct(
124
124
// the the base URI
125
125
$ this ->baseURI = sprintf ('%s://%s:%d ' , $ this ->scheme , $ this ->host , $ this ->port );
126
126
127
- // set the default driver to guzzle
128
- $ this ->driver = new Guzzle (
129
- new \GuzzleHttp \Client (
130
- [
131
- 'timeout ' => $ this ->timeout ,
132
- 'base_uri ' => $ this ->baseURI ,
133
- 'verify ' => $ this ->verifySSL
134
- ]
135
- )
136
- );
127
+ // delay driver instantiation until it's actually needed
128
+ $ this ->driver = null ;
137
129
138
130
$ this ->admin = new Admin ($ this );
139
131
}
@@ -161,17 +153,16 @@ public function selectDB($name)
161
153
*/
162
154
public function query ($ database , $ query , $ parameters = [])
163
155
{
156
+ $ driver = $ this ->getDriver ();
164
157
165
- if (!$ this -> driver instanceof QueryDriverInterface) {
158
+ if (!$ driver instanceof QueryDriverInterface) {
166
159
throw new Exception ('The currently configured driver does not support query operations ' );
167
160
}
168
161
169
162
if ($ database ) {
170
163
$ parameters ['db ' ] = $ database ;
171
164
}
172
165
173
- $ driver = $ this ->getDriver ();
174
-
175
166
$ parameters = [
176
167
'url ' => 'query? ' . http_build_query (array_merge (['q ' => $ query ], $ parameters )),
177
168
'database ' => $ database ,
@@ -332,6 +323,21 @@ public function setDriver(DriverInterface $driver)
332
323
*/
333
324
public function getDriver ()
334
325
{
326
+ if ($ this ->driver !== null ) {
327
+ return $ this ->driver ;
328
+ }
329
+
330
+ // set the default driver to guzzle
331
+ $ this ->driver = new Guzzle (
332
+ new \GuzzleHttp \Client (
333
+ [
334
+ 'timeout ' => $ this ->timeout ,
335
+ 'base_uri ' => $ this ->baseURI ,
336
+ 'verify ' => $ this ->verifySSL
337
+ ]
338
+ )
339
+ );
340
+
335
341
return $ this ->driver ;
336
342
}
337
343
0 commit comments