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

Commit

Permalink
Merge pull request #68 from M2Mobi/delay
Browse files Browse the repository at this point in the history
Delay driver instantiation until it's actually needed.
  • Loading branch information
TheCodeAssassin authored May 17, 2017
2 parents 2a450a0 + 3445dc6 commit c938497
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/InfluxDB/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,8 @@ public function __construct(
// the the base URI
$this->baseURI = sprintf('%s://%s:%d', $this->scheme, $this->host, $this->port);

// set the default driver to guzzle
$this->driver = new Guzzle(
new \GuzzleHttp\Client(
[
'timeout' => $this->timeout,
'base_uri' => $this->baseURI,
'verify' => $this->verifySSL
]
)
);
// delay driver instantiation until it's actually needed
$this->driver = null;

$this->admin = new Admin($this);
}
Expand Down Expand Up @@ -161,17 +153,16 @@ public function selectDB($name)
*/
public function query($database, $query, $parameters = [])
{
$driver = $this->getDriver();

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

if ($database) {
$parameters['db'] = $database;
}

$driver = $this->getDriver();

$parameters = [
'url' => 'query?' . http_build_query(array_merge(['q' => $query], $parameters)),
'database' => $database,
Expand Down Expand Up @@ -332,6 +323,21 @@ public function setDriver(DriverInterface $driver)
*/
public function getDriver()
{
if ($this->driver !== null) {
return $this->driver;
}

// set the default driver to guzzle
$this->driver = new Guzzle(
new \GuzzleHttp\Client(
[
'timeout' => $this->timeout,
'base_uri' => $this->baseURI,
'verify' => $this->verifySSL
]
)
);

return $this->driver;
}

Expand Down

0 comments on commit c938497

Please sign in to comment.