1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpZip\Model\Extra\Fields; |
4
|
|
|
|
5
|
|
|
use PhpZip\Model\Extra\ZipExtraField; |
6
|
|
|
use PhpZip\Model\ZipEntry; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Simple placeholder for all those extra fields we don't want to deal with. |
10
|
|
|
*/ |
11
|
|
|
class UnrecognizedExtraField implements ZipExtraField |
12
|
|
|
{ |
13
|
|
|
/** @var int */ |
14
|
|
|
private $headerId; |
15
|
|
|
|
16
|
|
|
/** @var string extra field data without Header-ID or length specifier */ |
17
|
|
|
private $data; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* UnrecognizedExtraField constructor. |
21
|
|
|
* |
22
|
|
|
* @param int $headerId |
23
|
|
|
* @param string $data |
24
|
|
|
*/ |
25
|
2 |
|
public function __construct($headerId, $data) |
26
|
|
|
{ |
27
|
2 |
|
$this->headerId = (int) $headerId; |
28
|
2 |
|
$this->data = (string) $data; |
29
|
2 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param int $headerId |
33
|
|
|
*/ |
34
|
|
|
public function setHeaderId($headerId) |
35
|
|
|
{ |
36
|
|
|
$this->headerId = $headerId; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Returns the Header ID (type) of this Extra Field. |
41
|
|
|
* The Header ID is an unsigned short integer (two bytes) |
42
|
|
|
* which must be constant during the life cycle of this object. |
43
|
|
|
* |
44
|
|
|
* @return int |
45
|
|
|
*/ |
46
|
2 |
|
public function getHeaderId() |
47
|
|
|
{ |
48
|
2 |
|
return $this->headerId; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Populate data from this array as if it was in local file data. |
53
|
|
|
* |
54
|
|
|
* @param string $buffer the buffer to read data from |
55
|
|
|
* @param ZipEntry|null $entry |
56
|
|
|
*/ |
57
|
|
|
public static function unpackLocalFileData($buffer, ZipEntry $entry = null) |
58
|
|
|
{ |
59
|
|
|
throw new \RuntimeException('Unsupport parse'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Populate data from this array as if it was in central directory data. |
64
|
|
|
* |
65
|
|
|
* @param string $buffer the buffer to read data from |
66
|
|
|
* @param ZipEntry|null $entry |
67
|
|
|
*/ |
68
|
|
|
public static function unpackCentralDirData($buffer, ZipEntry $entry = null) |
69
|
|
|
{ |
70
|
|
|
throw new \RuntimeException('Unsupport parse'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
|
|
public function packLocalFileData() |
77
|
|
|
{ |
78
|
|
|
return $this->data; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
public function packCentralDirData() |
85
|
|
|
{ |
86
|
|
|
return $this->data; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function getData() |
93
|
|
|
{ |
94
|
|
|
return $this->data; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param string $data |
99
|
|
|
*/ |
100
|
|
|
public function setData($data) |
101
|
|
|
{ |
102
|
|
|
$this->data = (string) $data; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
public function __toString() |
109
|
|
|
{ |
110
|
|
|
$args = [$this->headerId, $this->data]; |
111
|
|
|
$format = '0x%04x Unrecognized Extra Field: "%s"'; |
112
|
|
|
|
113
|
|
|
return vsprintf($format, $args); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|