mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 16:08:55 +02:00
Allows non write adapters
* Renamed `AdapterInterface` to `WritableInterface` * Constructor now allows different adapter implementations * Check that adapter implements `WritableInterface` during data send
This commit is contained in:
@@ -2,22 +2,17 @@
|
||||
namespace InfluxDB\Adapter;
|
||||
|
||||
use InfluxDB\Options;
|
||||
use InfluxDB\Adapter\WritableInterface;
|
||||
|
||||
abstract class AdapterAbstract implements AdapterInterface
|
||||
abstract class AdapterAbstract implements WritableInterface
|
||||
{
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* @param Options $options
|
||||
*/
|
||||
public function __construct(Options $options)
|
||||
{
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Options
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
namespace InfluxDB\Adapter;
|
||||
|
||||
/**
|
||||
* Every InfluxDB adapter implements this interface
|
||||
*/
|
||||
interface AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Send series into database
|
||||
* @param mixed $message
|
||||
* @param string|boolean $timePrecision
|
||||
*/
|
||||
public function send(array $message);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace InfluxDB\Adapter;
|
||||
|
||||
interface WritableInterface
|
||||
{
|
||||
public function send(array $message);
|
||||
}
|
||||
+6
-1
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace InfluxDB;
|
||||
|
||||
use InfluxDB\Adapter\WritableInterface;
|
||||
use InfluxDb\Adapter\QueryableInterface;
|
||||
|
||||
/**
|
||||
@@ -11,7 +12,7 @@ class Client
|
||||
{
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter\AdapterInterface $adapter)
|
||||
public function __construct($adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
return $this;
|
||||
@@ -24,6 +25,10 @@ class Client
|
||||
|
||||
public function mark($name, array $values = [])
|
||||
{
|
||||
if (!($this->getAdapter() instanceOf WritableInterface)) {
|
||||
throw new \BadMethodCallException("You can write data to database only if the adapter supports it!");
|
||||
}
|
||||
|
||||
$data = $name;
|
||||
if (!is_array($name)) {
|
||||
$data =[];
|
||||
|
||||
Reference in New Issue
Block a user