Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Commit c938497

Browse files
author
TheCodeAssassin
authored
Merge pull request #68 from M2Mobi/delay
Delay driver instantiation until it's actually needed.
2 parents 2a450a0 + 3445dc6 commit c938497

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/InfluxDB/Client.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,8 @@ public function __construct(
124124
// the the base URI
125125
$this->baseURI = sprintf('%s://%s:%d', $this->scheme, $this->host, $this->port);
126126

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;
137129

138130
$this->admin = new Admin($this);
139131
}
@@ -161,17 +153,16 @@ public function selectDB($name)
161153
*/
162154
public function query($database, $query, $parameters = [])
163155
{
156+
$driver = $this->getDriver();
164157

165-
if (!$this->driver instanceof QueryDriverInterface) {
158+
if (!$driver instanceof QueryDriverInterface) {
166159
throw new Exception('The currently configured driver does not support query operations');
167160
}
168161

169162
if ($database) {
170163
$parameters['db'] = $database;
171164
}
172165

173-
$driver = $this->getDriver();
174-
175166
$parameters = [
176167
'url' => 'query?' . http_build_query(array_merge(['q' => $query], $parameters)),
177168
'database' => $database,
@@ -332,6 +323,21 @@ public function setDriver(DriverInterface $driver)
332323
*/
333324
public function getDriver()
334325
{
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+
335341
return $this->driver;
336342
}
337343

0 commit comments

Comments
 (0)