deblan.io-murph/src/Api/InfluxDB.php
2023-09-22 22:06:44 +02:00

47 lines
1 KiB
PHP

<?php
namespace App\Api;
use InfluxDB2\Client;
use InfluxDB2\Model\WritePrecision;
/**
* class InfluxDB.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class InfluxDB
{
protected ?Client $client = null;
public function __construct(
protected ?string $url,
protected ?string $token,
protected ?string $bucket,
protected ?string $org,
protected bool $debug = false
) {
if (isset($this->url, $this->token, $this->bucket, $this->org)) {
$this->client = new Client([
'url' => $this->url,
'token' => $this->token,
'bucket' => $this->bucket,
'org' => $this->org,
'debug' => $this->debug,
'precision' => WritePrecision::S,
'timeout' => 1,
]);
}
}
public function isAvailable(): bool
{
return $this->getClient() !== null;
}
public function getClient(): ?Client
{
return $this->client;
}
}