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