1 | <?php |
||
26 | class JsonWriter |
||
27 | { |
||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | private $filename; |
||
32 | |||
33 | /** |
||
34 | * @var resource A file system pointer resource. |
||
35 | */ |
||
36 | private $handle; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | private $metadata; |
||
42 | |||
43 | /** |
||
44 | * @var int Current record number. |
||
45 | */ |
||
46 | private $currentPosition = 0; |
||
47 | |||
48 | /** |
||
49 | * Constructor. |
||
50 | * |
||
51 | * Metadata can contain any fields but only the field "count" |
||
52 | * is recognized and used while writing to file. If written lines count |
||
53 | * reaches "count", writer will automatically finalize file. |
||
54 | * |
||
55 | * @param string $filename A file in which data will be saved. |
||
56 | * @param array $metadata Additional metadata to be stored. |
||
57 | */ |
||
58 | public function __construct($filename, $metadata = []) |
||
63 | |||
64 | /** |
||
65 | * Destructor. Closes file handler if open. |
||
66 | */ |
||
67 | public function __destruct() |
||
71 | |||
72 | /** |
||
73 | * Performs initialization. |
||
74 | */ |
||
75 | protected function initialize() |
||
85 | |||
86 | /** |
||
87 | * Performs finalization. |
||
88 | */ |
||
89 | public function finalize() |
||
98 | |||
99 | /** |
||
100 | * Writes single document to stream. |
||
101 | * |
||
102 | * @param mixed $document Object to insert into stream. |
||
103 | * |
||
104 | * @throws \OverflowException |
||
105 | */ |
||
106 | public function push($document) |
||
124 | } |
||
125 |