1 | <?php |
||
18 | final class InfluxDbEventListener |
||
19 | { |
||
20 | const STORAGE_KEY_UDP = 'udp'; |
||
21 | const STORAGE_KEY_HTTP = 'http'; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $connection; |
||
27 | |||
28 | /** |
||
29 | * @var bool |
||
30 | */ |
||
31 | private $isDefault; |
||
32 | |||
33 | /** |
||
34 | * @var Database |
||
35 | */ |
||
36 | private $httpDatabase; |
||
37 | |||
38 | /** |
||
39 | * @var Database |
||
40 | */ |
||
41 | private $udpDatabase; |
||
42 | |||
43 | /** |
||
44 | * @var array |
||
45 | */ |
||
46 | private $storage; |
||
47 | |||
48 | /** |
||
49 | * @param string $connection |
||
50 | * @param bool $isDefault |
||
51 | * @param Database $httpDatabase |
||
52 | * @param Database $udpDatabase |
||
53 | */ |
||
54 | 7 | public function __construct(string $connection, bool $isDefault, Database $httpDatabase, Database $udpDatabase = null) |
|
62 | |||
63 | 7 | public function onPointsCollected(AbstractInfluxDbEvent $event): bool |
|
97 | |||
98 | /** |
||
99 | * @param Event $event |
||
100 | * |
||
101 | * @return bool |
||
102 | */ |
||
103 | 2 | public function onKernelTerminate(Event $event): bool |
|
118 | |||
119 | 7 | private function initStorage() |
|
120 | { |
||
121 | 7 | $this->storage = [ |
|
122 | 7 | static::STORAGE_KEY_UDP => [], |
|
123 | 7 | static::STORAGE_KEY_HTTP => [], |
|
124 | ]; |
||
125 | 7 | } |
|
126 | |||
127 | /** |
||
128 | * @param Point[] $points |
||
129 | * @param string $precision |
||
130 | */ |
||
131 | 2 | private function writeUdpPoints(array $points, string $precision) |
|
135 | |||
136 | /** |
||
137 | * @param Point[] $points |
||
138 | * @param string $precision |
||
139 | */ |
||
140 | 2 | private function writeHttpPoints(array $points, string $precision) |
|
144 | |||
145 | /** |
||
146 | * @param string $typeKey |
||
147 | * @param string $precision |
||
148 | * @param array $points |
||
149 | */ |
||
150 | 2 | private function addPointsToStorage(string $typeKey, string $precision, array $points) |
|
160 | } |
||
161 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: