diff --git a/src/InfluxDB/Adapter/AdapterInterface.php b/src/InfluxDB/Adapter/AdapterInterface.php index 79ed18670..73d1b2fe5 100644 --- a/src/InfluxDB/Adapter/AdapterInterface.php +++ b/src/InfluxDB/Adapter/AdapterInterface.php @@ -1,7 +1,15 @@ httpClient = $httpClient; $this->options = $options; } + /** + * @return Options + */ public function getOptions() { return $this->options; } + /** + * {@inheritDoc} + */ public function send($message, $timePrecision = false) { $httpMessage = [ @@ -35,6 +56,9 @@ class GuzzleAdapter implements AdapterInterface, QueryableInterface return $this->httpClient->post($endpoint, $httpMessage); } + /** + * {@inheritDoc} + */ public function query($query, $timePrecision = false) { $options = [ @@ -53,6 +77,9 @@ class GuzzleAdapter implements AdapterInterface, QueryableInterface return $this->httpClient->get($endpoint, $options)->json(); } + /** + * {@inheritDoc} + */ public function getDatabases() { $options = [ @@ -64,6 +91,9 @@ class GuzzleAdapter implements AdapterInterface, QueryableInterface return $this->httpClient->get($endpoint, $options)->json(); } + /** + * {@inheritDoc} + */ public function createDatabase($name) { $httpMessage = [ @@ -75,6 +105,9 @@ class GuzzleAdapter implements AdapterInterface, QueryableInterface return $this->httpClient->post($endpoint, $httpMessage)->json(); } + /** + * {@inheritDoc} + */ public function deleteDatabase($name) { $httpMessage = [ diff --git a/src/InfluxDB/Adapter/QueryableInterface.php b/src/InfluxDB/Adapter/QueryableInterface.php index 2e4754011..3bed92384 100644 --- a/src/InfluxDB/Adapter/QueryableInterface.php +++ b/src/InfluxDB/Adapter/QueryableInterface.php @@ -1,10 +1,34 @@ options = $options; } + /** + * @return Options + */ public function getOptions() { return $this->options; } + /** + * {@inheritDoc} + */ public function send($message, $timePrecision = false) { $message = json_encode($message); diff --git a/src/InfluxDB/Client.php b/src/InfluxDB/Client.php index 94e879f8f..b7215244f 100644 --- a/src/InfluxDB/Client.php +++ b/src/InfluxDB/Client.php @@ -5,33 +5,68 @@ namespace InfluxDB; use InfluxDb\Adapter\QueryableInterface; use InfluxDB\Filter\FilterInterface; +/** + * Client to manage request at InfluxDB + */ class Client { + /** + * @var \InfluxDB\Adapter\AdapterInterface + */ private $adapter; + + /** + * @var \InfluxDB\Filter\FilterInterface + */ private $filter; + /** + * Set filter + * @param Filter\FilterInterface $filter + * @return Client + */ public function setFilter(Filter\FilterInterface $filter) { $this->filter = $filter; return $this; } + /** + * Get filter + * @return Filter\FilterInterface + */ public function getFilter() { return $this->filter; } + /** + * Set InfluxDB adapter + * @param Adapter\AdapterInterface + * @return Client + */ public function setAdapter(Adapter\AdapterInterface $adapter) { $this->adapter = $adapter; return $this; } + /** + * Get adapter + * @return Adapter\AdapterInterface + */ public function getAdapter() { return $this->adapter; } + /** + * Insert point into series + * @param string $name + * @param array $value + * @param bool|string $timePrecision + * @return mixed + */ public function mark($name, array $values, $timePrecision = false) { $data =[]; @@ -45,6 +80,12 @@ class Client return $this->getAdapter()->send([$data], $timePrecision); } + /** + * Make a query into database + * @param string $query + * @param bool|string $timePrecision + * @return array + */ public function query($query, $timePrecision = false) { if (!($this->getAdapter() instanceOf QueryableInterface)) { @@ -62,6 +103,10 @@ class Client return $return; } + /** + * List of databases + * @return array + */ public function getDatabases() { if (!($this->getAdapter() instanceOf QueryableInterface)) { @@ -70,6 +115,10 @@ class Client return $this->getAdapter()->getDatabases(); } + /** + * Create database by name + * @param string $name + */ public function createDatabase($name) { if (!($this->getAdapter() instanceOf QueryableInterface)) { @@ -78,6 +127,10 @@ class Client return $this->getAdapter()->createDatabase($name); } + /** + * Delete database by name + * @param string $name + */ public function deleteDatabase($name) { if (!($this->getAdapter() instanceOf QueryableInterface)) { @@ -86,6 +139,11 @@ class Client return $this->getAdapter()->deleteDatabase($name); } + /** + * List of time precision choose + * @param string $timePrecision + * @return bool|string + */ private function clearTimePrecision($timePrecision) { switch ($timePrecision) { diff --git a/src/InfluxDB/ClientFactory.php b/src/InfluxDB/ClientFactory.php index cd94929f6..da987220c 100644 --- a/src/InfluxDB/ClientFactory.php +++ b/src/InfluxDB/ClientFactory.php @@ -4,8 +4,18 @@ namespace InfluxDB; use Zend\Stdlib\Hydrator\ClassMethods; use GuzzleHttp\Client as GuzzleClient; +/** + * Create your static client + */ abstract class ClientFactory { + /** + * Create new client + * @param array $options + * @return Client + * @throws InvalidArgumentException If not exist adapter name + * or not find adapter + */ public static function create(array $options) { $defaultOptions = [ diff --git a/src/InfluxDB/Filter/ColumnsPointsFilter.php b/src/InfluxDB/Filter/ColumnsPointsFilter.php index b6e94dc07..54e9ff127 100644 --- a/src/InfluxDB/Filter/ColumnsPointsFilter.php +++ b/src/InfluxDB/Filter/ColumnsPointsFilter.php @@ -2,8 +2,14 @@ namespace InfluxDB\Filter; +/** + * This filter manipulates response + */ class ColumnsPointsFilter implements FilterInterface { + /** + * {@inheritDoc} + */ public function filter($metrics) { $response = []; diff --git a/src/InfluxDB/Filter/FilterInterface.php b/src/InfluxDB/Filter/FilterInterface.php index 01bb59fd8..b2999a52a 100644 --- a/src/InfluxDB/Filter/FilterInterface.php +++ b/src/InfluxDB/Filter/FilterInterface.php @@ -1,7 +1,14 @@ host = "localhost"; @@ -21,17 +49,27 @@ class Options $this->setProtocol("http"); } + /** + * @return string + */ public function getProtocol() { return $this->protocol; } + /** + * @param string $protocol + * @return Options + */ public function setProtocol($protocol) { $this->protocol = $protocol; return $this; } + /** + * @return string + */ public function getHost() { return $this->host; @@ -43,50 +81,82 @@ class Options return $this; } + /** + * @return string|int + */ public function getPort() { return $this->port; } + /** + * @param string|int $port + * @return Options + */ public function setPort($port) { $this->port = $port; return $this; } + /** + * @return string + */ public function getUsername() { return $this->username; } + /** + * @param string $usarname + * @return Options + */ public function setUsername($username) { $this->username = $username; return $this; } + /** + * @return string + */ public function getPassword() { return $this->password; } + /** + * @param string $password + * @return Options + */ public function setPassword($password) { $this->password = $password; return $this; } + /** + * @return string + */ public function getDatabase() { return $this->database; } + /** + * @param string $database + * @return Options + */ public function setDatabase($database) { $this->database = $database; return $this; } + /** + * Build http series edpoint + * @return string + */ public function getHttpSeriesEndpoint() { return sprintf( @@ -98,6 +168,11 @@ class Options ); } + /** + * Build http database endpoint by name + * @param string $name + * @return string + */ public function getHttpDatabaseEndpoint($name = false) { $url = sprintf(