We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 51e65ae commit 9b8bb84Copy full SHA for 9b8bb84
1 file changed
src/Importer.php
@@ -0,0 +1,42 @@
1
+<?php
2
+
3
+namespace Xhgui\Profiler;
4
5
+use Exception;
6
+use Xhgui\Profiler\Saver\SaverInterface;
7
8
+final class Importer
9
+{
10
+ /** @var SaverInterface */
11
+ private $saver;
12
13
+ public function __construct(SaverInterface $saver)
14
+ {
15
+ $this->saver = $saver;
16
+ }
17
18
+ public function import($stream)
19
20
+ $saver = $this->saver;
21
+ $lines = 0;
22
+ while (!feof($stream)) {
23
+ $line = trim(fgets($stream));
24
+ if (!$line) {
25
+ continue;
26
27
+ $data = json_decode($line, true);
28
+ if (!$data) {
29
+ error_log("Ignoring malformed JSON line: $line");
30
31
32
33
+ try {
34
+ $saver->save($data);
35
+ $lines++;
36
+ } catch (Exception $e) {
37
+ error_log($e);
38
39
40
+ error_log("Imported {$lines} lines");
41
42
+}
0 commit comments