-
Notifications
You must be signed in to change notification settings - Fork 47
/
FluxRecord.php
122 lines (104 loc) · 2.75 KB
/
FluxRecord.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace InfluxDB2;
use ArrayAccess;
use RuntimeException;
/**
* Class FluxRecord is a tuple of values. Each record in the table represents a single point in the series.
* @see http://bit.ly/flux-spec#record
* @package InfluxDB2
*/
class FluxRecord implements ArrayAccess
{
public $table;
public $values;
public $row;
/**
* FluxRecord constructor.
* @param $table int table index
* @param $values array array with record values, key is the column name
*/
public function __construct($table, $values = null, $row = null)
{
$this->table = $table;
$this->values = $values;
$this->row = $row;
}
/**
* @return mixed record value for column named '_start'
*/
public function getStart()
{
return $this->getRecordValue('_start');
}
/**
* @return mixed record value for column named '_stop'
*/
public function getStop()
{
return $this->getRecordValue('_stop');
}
/**
* @return mixed record value for column named '_time'
*/
public function getTime()
{
return $this->getRecordValue('_time');
}
/**
* @return mixed record value for column named '_value'
*/
public function getValue()
{
return $this->getRecordValue('_value');
}
/**
* @return mixed record value for column named '_field'
*/
public function getField()
{
return $this->getRecordValue('_field');
}
/**
* @return mixed record value for column named '_measurement'
*/
public function getMeasurement(): string
{
return $this->getRecordValue('_measurement');
}
/**
* Get record value.
*
* @param $column string name of column to get
* @return mixed the value of column
* @throws RuntimeException when the record doesn't contain required column
*/
private function getRecordValue(string $column)
{
if (array_key_exists($column, $this->values)) {
return $this->values[$column];
}
$array_keys = join(", ", array_keys($this->values));
throw new RuntimeException("Record doesn't contain column named '$column'. Columns: '$array_keys'.");
}
public function offsetSet($offset, $value): void
{
if (is_null($offset)) {
$this->values[] = $value;
} else {
$this->values[$offset] = $value;
}
}
public function offsetExists($offset): bool
{
return isset($this->values[$offset]);
}
public function offsetUnset($offset): void
{
unset($this->values[$offset]);
}
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->values[$offset] ?? null;
}
}