1 | <?php |
||
7 | final class ExtraField implements ExtraFieldInterface |
||
8 | { |
||
9 | /** |
||
10 | * Minimum length an extra field if the data is empty |
||
11 | */ |
||
12 | const MIN_LENGTH = 4; |
||
13 | |||
14 | /** |
||
15 | * Maximum length an extra field can have if the data is completely used |
||
16 | */ |
||
17 | const MAX_LENGTH = self::MIN_LENGTH + self::DATA_MAX_LENGTH; |
||
18 | |||
19 | /** |
||
20 | * Data can not be longer than this (the length field has only 2 bytes) |
||
21 | */ |
||
22 | const DATA_MAX_LENGTH = (255 * 255) - 1; |
||
23 | |||
24 | /** |
||
25 | * Mapping from header ID => implementing class |
||
26 | * @var array |
||
27 | */ |
||
28 | private static $extraFieldTypes = [ |
||
29 | Zip64ExtendedInformation::ID => Zip64ExtendedInformation::class, |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * @var int |
||
34 | */ |
||
35 | private $headerId; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private $data; |
||
41 | |||
42 | 5 | public function __construct(int $headerId, string $data = "") |
|
47 | |||
48 | 5 | public static function parse(string $input, $context = null) |
|
62 | |||
63 | /** |
||
64 | * @param string $extraFieldData |
||
65 | * @param null $context The context this extra field comes from, e.g. a CentralDirectoryHeader |
||
66 | * @return ExtraFieldInterface[] |
||
67 | */ |
||
68 | 2048 | public static function parseAll(string $extraFieldData, $context = null) |
|
79 | |||
80 | public function getHeaderId() |
||
84 | |||
85 | 5 | public function getDataSize() |
|
89 | |||
90 | public function getData() |
||
94 | |||
95 | /** |
||
96 | * Register a custom extra field type that can parse extra fields identified by $id. |
||
97 | * The class must implement ExtraFieldInterface |
||
98 | * |
||
99 | * @param int $id |
||
100 | * @param string $className |
||
101 | */ |
||
102 | public static function registerExtraFieldType(int $id, string $className) |
||
110 | |||
111 | /** |
||
112 | * Convert an extra field to it's binary string representation |
||
113 | * @param ExtraFieldInterface $extraField |
||
114 | * @return string |
||
115 | */ |
||
116 | 1080 | public static function marshal(ExtraFieldInterface $extraField) |
|
120 | } |
||
121 |