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 | * Writes raw data to the stream. |
||
81 | * |
||
82 | * @param string $data |
||
83 | */ |
||
84 | public function writeRaw($data) |
||
88 | |||
89 | /** |
||
90 | * Returns all object offsets. |
||
91 | * |
||
92 | * @return int |
||
93 | */ |
||
94 | public function getObjectOffsets() |
||
98 | |||
99 | /** |
||
100 | * Allocates a new ID for an object. |
||
101 | * |
||
102 | * @return int |
||
103 | */ |
||
104 | public function allocateObjectId() |
||
108 | |||
109 | /** |
||
110 | * Starts an object. |
||
111 | * |
||
112 | * If the object ID is omitted, a new one is allocated. |
||
113 | * |
||
114 | * @param int|null $objectId |
||
115 | * @return int |
||
116 | */ |
||
117 | public function startObject($objectId = null) |
||
128 | |||
129 | /** |
||
130 | * Ends an object. |
||
131 | */ |
||
132 | public function endObject() |
||
136 | |||
137 | /** |
||
138 | * Starts a stream. |
||
139 | */ |
||
140 | public function startStream() |
||
144 | |||
145 | public function endStream() |
||
149 | |||
150 | /** |
||
151 | * Writes an indirect reference |
||
152 | * |
||
153 | * @param int $objectId |
||
154 | */ |
||
155 | public function writeIndirectReference($objectId) |
||
165 | |||
166 | /** |
||
167 | * Starts a dictionary. |
||
168 | */ |
||
169 | public function startDictionary() |
||
174 | |||
175 | /** |
||
176 | * Ends a dictionary. |
||
177 | */ |
||
178 | public function endDictionary() |
||
183 | |||
184 | /** |
||
185 | * Starts an array. |
||
186 | */ |
||
187 | public function startArray() |
||
192 | |||
193 | /** |
||
194 | * Ends an array. |
||
195 | */ |
||
196 | public function endArray() |
||
201 | |||
202 | /** |
||
203 | * Writes a null value. |
||
204 | */ |
||
205 | public function writeNull() |
||
215 | |||
216 | /** |
||
217 | * Writes a boolean. |
||
218 | * |
||
219 | * @param bool $boolean |
||
220 | */ |
||
221 | public function writeBoolean($boolean) |
||
231 | |||
232 | /** |
||
233 | * Writes a number. |
||
234 | * |
||
235 | * @param int|float $number |
||
236 | * @throws InvalidArgumentException |
||
237 | */ |
||
238 | public function writeNumber($number) |
||
248 | |||
249 | /** |
||
250 | * Writes a name. |
||
251 | * |
||
252 | * @param string $name |
||
253 | */ |
||
254 | public function writeName($name) |
||
259 | |||
260 | /** |
||
261 | * Writes a literal string. |
||
262 | * |
||
263 | * The string itself is splitted into multiple lines after 248 characters. We chose that specific limit to avoid |
||
264 | * splitting mutli-byte characters in half. |
||
265 | * |
||
266 | * @param string $string |
||
267 | */ |
||
268 | public function writeLiteralString($string) |
||
273 | |||
274 | /** |
||
275 | * Writes a hexadecimal string. |
||
276 | * |
||
277 | * @param string $string |
||
278 | */ |
||
279 | public function writeHexadecimalString($string) |
||
284 | } |
||
285 |