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:
Walter Dal Mut
2015-06-13 12:04:04 +02:00
parent 062645222d
commit c52377aad1
4 changed files with 15 additions and 23 deletions
+2 -7
View File
@@ -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;
-15
View File
@@ -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);
}
+7
View File
@@ -0,0 +1,7 @@
<?php
namespace InfluxDB\Adapter;
interface WritableInterface
{
public function send(array $message);
}
+6 -1
View File
@@ -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 =[];