1 | <?php |
||
5 | final class EndOfCentralDirectory |
||
6 | { |
||
7 | const SIGNATURE = 0x504b0506; |
||
8 | |||
9 | /// Minimum length of this entry if zip file comment is empty |
||
10 | const MIN_LENGTH = 22; |
||
11 | |||
12 | /// Maximum length of this entry if zip file comment has the maximum length |
||
13 | const MAX_LENGTH = self::MIN_LENGTH + self::ZIP_FILE_COMMENT_MAX_LENGTH; |
||
14 | |||
15 | /// The zip file comment can not be longer than this (the length field has only 2 bytes) |
||
16 | const ZIP_FILE_COMMENT_MAX_LENGTH = (255 * 255) - 1; |
||
17 | |||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | private $numberOfThisDisk; |
||
22 | |||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | private $numberOfTheDiskWithTheStartOfTheCentralDirectory; |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | private $totalNumberOfEntriesInTheCentralDirectoryOnThisDisk; |
||
32 | |||
33 | /** |
||
34 | * @var int |
||
35 | */ |
||
36 | private $totalNumberOfEntriesInTheCentralDirectory; |
||
37 | |||
38 | /** |
||
39 | * @var int |
||
40 | */ |
||
41 | private $sizeOfTheCentralDirectory; |
||
42 | |||
43 | /** |
||
44 | * @var int |
||
45 | */ |
||
46 | private $offsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber; |
||
47 | |||
48 | /** |
||
49 | * @var int |
||
50 | */ |
||
51 | private $zipFileCommentLength; |
||
52 | |||
53 | /** |
||
54 | * @var string |
||
55 | */ |
||
56 | private $zipFileComment = ""; |
||
57 | |||
58 | /** |
||
59 | * @var bool |
||
60 | */ |
||
61 | private $requireAdditionalData = false; |
||
62 | |||
63 | 2049 | public function __construct( |
|
84 | |||
85 | /** |
||
86 | * Parse the end of central directory from a binary string. |
||
87 | * Use getVariableLength() to get the required number of bytes to execute parseAdditionalData(). |
||
88 | * |
||
89 | * @param string $input |
||
90 | * @param int $offset Start at this position inside the string |
||
91 | * @return static |
||
92 | */ |
||
93 | 2048 | public static function parse(string $input, int $offset = 0) |
|
127 | |||
128 | /** |
||
129 | * After a new object has been created by parse(), this method must be called to initialize the zip file comment entry which has variable field length. |
||
130 | * The required number of bytes can be obtained by getVariableLength() |
||
131 | * |
||
132 | * @param string $input |
||
133 | * @param int $offset |
||
134 | * @return int Consumed bytes, equals getVariableLength() |
||
135 | */ |
||
136 | 2042 | public function parseAdditionalData(string $input, int $offset = 0) : int |
|
151 | |||
152 | /** |
||
153 | * Create the binary on disk representation |
||
154 | * |
||
155 | * @return string |
||
156 | */ |
||
157 | public function marshal() : string |
||
173 | |||
174 | /** |
||
175 | * The number of bytes the fields with variable length require. |
||
176 | * |
||
177 | * @return int |
||
178 | */ |
||
179 | 2048 | public function getVariableLength(): int |
|
183 | |||
184 | /** |
||
185 | * @return int |
||
186 | */ |
||
187 | 1 | public function getNumberOfThisDisk(): int |
|
191 | |||
192 | /** |
||
193 | * @param int $numberOfThisDisk |
||
194 | * @return EndOfCentralDirectory |
||
195 | */ |
||
196 | 1 | public function setNumberOfThisDisk(int $numberOfThisDisk): EndOfCentralDirectory |
|
202 | |||
203 | /** |
||
204 | * @return int |
||
205 | */ |
||
206 | 1 | public function getNumberOfTheDiskWithTheStartOfTheCentralDirectory(): int |
|
210 | |||
211 | /** |
||
212 | * @param int $numberOfTheDiskWithTheStartOfTheCentralDirectory |
||
213 | * @return EndOfCentralDirectory |
||
214 | */ |
||
215 | 1 | public function setNumberOfTheDiskWithTheStartOfTheCentralDirectory(int $numberOfTheDiskWithTheStartOfTheCentralDirectory): EndOfCentralDirectory |
|
221 | |||
222 | /** |
||
223 | * @return int |
||
224 | */ |
||
225 | 1 | public function getTotalNumberOfEntriesInTheCentralDirectoryOnThisDisk(): int |
|
229 | |||
230 | /** |
||
231 | * @param int $totalNumberOfEntriesInTheCentralDirectoryOnThisDisk |
||
232 | * @return EndOfCentralDirectory |
||
233 | */ |
||
234 | 1 | public function setTotalNumberOfEntriesInTheCentralDirectoryOnThisDisk(int $totalNumberOfEntriesInTheCentralDirectoryOnThisDisk): EndOfCentralDirectory |
|
240 | |||
241 | /** |
||
242 | * @return int |
||
243 | */ |
||
244 | 2049 | public function getTotalNumberOfEntriesInTheCentralDirectory(): int |
|
248 | |||
249 | /** |
||
250 | * @param int $totalNumberOfEntriesInTheCentralDirectory |
||
251 | * @return EndOfCentralDirectory |
||
252 | */ |
||
253 | 1 | public function setTotalNumberOfEntriesInTheCentralDirectory(int $totalNumberOfEntriesInTheCentralDirectory): EndOfCentralDirectory |
|
259 | |||
260 | /** |
||
261 | * @return int |
||
262 | */ |
||
263 | 2049 | public function getSizeOfTheCentralDirectory(): int |
|
267 | |||
268 | /** |
||
269 | * @param int $sizeOfTheCentralDirectory |
||
270 | * @return EndOfCentralDirectory |
||
271 | */ |
||
272 | 1 | public function setSizeOfTheCentralDirectory(int $sizeOfTheCentralDirectory): EndOfCentralDirectory |
|
278 | |||
279 | /** |
||
280 | * @return int |
||
281 | */ |
||
282 | 2049 | public function getOffsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber(): int |
|
286 | |||
287 | /** |
||
288 | * @param int $offsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber |
||
289 | * @return EndOfCentralDirectory |
||
290 | */ |
||
291 | 1 | public function setOffsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber(int $offsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber): EndOfCentralDirectory |
|
297 | |||
298 | /** |
||
299 | * @return int |
||
300 | */ |
||
301 | 1 | public function getZipFileCommentLength(): int |
|
305 | |||
306 | /** |
||
307 | * @return string |
||
308 | */ |
||
309 | 2046 | public function getZipFileComment(): string |
|
313 | |||
314 | /** |
||
315 | * @param string $zipFileComment |
||
316 | * @return EndOfCentralDirectory |
||
317 | */ |
||
318 | 1 | public function setZipFileComment(string $zipFileComment): EndOfCentralDirectory |
|
325 | } |
||
326 |