measurement = (string) $measurement; if ($timestamp !== null) { $this->timestamp = $timestamp; } if (! empty($tags)) { $this->addTags($tags); } if (is_array($fields) || is_object($fields)) { $this->fields = (array) $fields; } else { $this->fields = ['value' => $fields]; } if (empty($this->fields)) { throw new InvalidArgumentException('At least one field/value is required'); } } public function addTags($tags) { $this->tags = array_merge($this->tags, (array) $tags); ksort($this->tags); } public function getTag($name, $default = null) { if (array_key_exists($name, $this->tags)) { return $this->tags[$name]; } else { return $default; } } public function __toString() { return LineProtocol::renderMeasurement($this->measurement, $this->tags, $this->fields, $this->timestamp); } }