1 | <?php |
||
26 | class ObjectWriter |
||
27 | { |
||
28 | /** |
||
29 | * @var SplFileObject |
||
30 | */ |
||
31 | private $fileObject; |
||
32 | |||
33 | /** |
||
34 | * @var bool |
||
35 | */ |
||
36 | private $requiresWhitespace = false; |
||
37 | |||
38 | /** |
||
39 | * @var int |
||
40 | */ |
||
41 | private $lastAllocatedObjectId = 0; |
||
42 | |||
43 | /** |
||
44 | * @var int[] |
||
45 | */ |
||
46 | private $objectOffsets = []; |
||
47 | |||
48 | /** |
||
49 | * @param SplFileObject $fileObject |
||
50 | */ |
||
51 | public function __construct(SplFileObject $fileObject) |
||
55 | |||
56 | /** |
||
57 | * Returns the current position in the file. |
||
58 | * |
||
59 | * @return int |
||
60 | */ |
||
61 | public function getCurrentOffset() |
||
65 | |||
66 | /** |
||
67 | * Writes a raw data line to the stream. |
||
68 | * |
||
69 | * A newline character is appended after the data. Keep in mind that you may still be after a token which requires |
||
70 | * a following whitespace, depending on the context you are in. |
||
71 | * |
||
72 | * @param string $data |
||
73 | */ |
||
74 | public function writeRawLine($data) |
||
78 | |||
79 | /** |
||
80 | * Returns all object offsets. |
||
81 | * |
||
82 | * @return int |
||
83 | */ |
||
84 | public function getObjectOffsets() |
||
88 | |||
89 | /** |
||
90 | * Allocates a new ID for an object. |
||
91 | * |
||
92 | * @return int |
||
93 | */ |
||
94 | public function allocateObjectId() |
||
98 | |||
99 | /** |
||
100 | * Starts an object. |
||
101 | * |
||
102 | * If the object ID is omitted, a new one is allocated. |
||
103 | * |
||
104 | * @param int|null $objectId |
||
105 | * @return int |
||
106 | */ |
||
107 | public function startObject($objectId = null) |
||
118 | |||
119 | /** |
||
120 | * Ends an object. |
||
121 | */ |
||
122 | public function endObject() |
||
126 | |||
127 | /** |
||
128 | * Writes an indirect reference |
||
129 | * |
||
130 | * @param int $objectId |
||
131 | */ |
||
132 | public function writeIndirectReference($objectId) |
||
142 | |||
143 | /** |
||
144 | * Starts a dictionary. |
||
145 | */ |
||
146 | public function startDictionary() |
||
151 | |||
152 | /** |
||
153 | * Ends a dictionary. |
||
154 | */ |
||
155 | public function endDictionary() |
||
160 | |||
161 | /** |
||
162 | * Starts an array. |
||
163 | */ |
||
164 | public function startArray() |
||
169 | |||
170 | /** |
||
171 | * Ends an array. |
||
172 | */ |
||
173 | public function endArray() |
||
178 | |||
179 | /** |
||
180 | * Writes a null value. |
||
181 | */ |
||
182 | public function writeNull() |
||
192 | |||
193 | /** |
||
194 | * Writes a boolean. |
||
195 | * |
||
196 | * @param bool $boolean |
||
197 | */ |
||
198 | public function writeBoolean($boolean) |
||
208 | |||
209 | /** |
||
210 | * Writes a number. |
||
211 | * |
||
212 | * @param int|float $number |
||
213 | * @throws InvalidArgumentException |
||
214 | */ |
||
215 | public function writeNumber($number) |
||
225 | |||
226 | /** |
||
227 | * Writes a name. |
||
228 | * |
||
229 | * @param string $name |
||
230 | */ |
||
231 | public function writeName($name) |
||
236 | |||
237 | /** |
||
238 | * Writes a literal string. |
||
239 | * |
||
240 | * The string itself is splitted into multiple lines after 248 characters. We chose that specific limit to avoid |
||
241 | * splitting mutli-byte characters in half. |
||
242 | * |
||
243 | * @param string $string |
||
244 | */ |
||
245 | public function writeLiteralString($string) |
||
250 | |||
251 | /** |
||
252 | * Writes a hexadecimal string. |
||
253 | * |
||
254 | * @param string $string |
||
255 | */ |
||
256 | public function writeHexadecimalString($string) |
||
261 | } |
||
262 |