1
|
|
|
<?php |
2
|
|
|
namespace wapmorgan\UnifiedArchive\Drivers; |
3
|
|
|
|
4
|
|
|
use wapmorgan\UnifiedArchive\ArchiveEntry; |
5
|
|
|
use wapmorgan\UnifiedArchive\ArchiveInformation; |
6
|
|
|
use wapmorgan\UnifiedArchive\Exceptions\ArchiveCreationException; |
7
|
|
|
use wapmorgan\UnifiedArchive\Exceptions\ArchiveExtractionException; |
8
|
|
|
use wapmorgan\UnifiedArchive\Exceptions\ArchiveModificationException; |
9
|
|
|
use wapmorgan\UnifiedArchive\Exceptions\UnsupportedArchiveException; |
10
|
|
|
use wapmorgan\UnifiedArchive\Exceptions\UnsupportedOperationException; |
11
|
|
|
use wapmorgan\UnifiedArchive\PclzipZipInterface; |
12
|
|
|
|
13
|
|
|
abstract class BasicDriver |
14
|
|
|
{ |
15
|
|
|
const COMPRESSION_NONE = 0; |
16
|
|
|
const COMPRESSION_WEAK = 1; |
17
|
|
|
const COMPRESSION_AVERAGE = 2; |
18
|
|
|
const COMPRESSION_STRONG = 3; |
19
|
|
|
const COMPRESSION_MAXIMUM = 4; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @return array |
23
|
|
|
*/ |
24
|
|
|
public static function getSupportedFormats() |
25
|
|
|
{ |
26
|
|
|
return []; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param $format |
31
|
|
|
* @return bool |
32
|
|
|
*/ |
33
|
|
|
public static function checkFormatSupport($format) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
return false; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
public static function getDescription() |
42
|
|
|
{ |
43
|
|
|
return null; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public static function getInstallationInstruction() |
50
|
|
|
{ |
51
|
|
|
return null; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param $format |
56
|
|
|
* @return bool |
57
|
|
|
*/ |
58
|
|
|
public static function canCreateArchive($format) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
return false; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param $format |
65
|
|
|
* @return bool |
66
|
|
|
*/ |
67
|
|
|
public static function canAddFiles($format) |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param $format |
74
|
|
|
* @return bool |
75
|
|
|
*/ |
76
|
|
|
public static function canDeleteFiles($format) |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
return false; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param $format |
83
|
|
|
* @return false |
84
|
|
|
*/ |
85
|
|
|
public static function canEncrypt($format) |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
return false; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param $format |
92
|
|
|
* @return false |
93
|
|
|
*/ |
94
|
|
|
public static function canStream($format) |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
return false; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param array $files |
101
|
|
|
* @param string $archiveFileName |
102
|
|
|
* @param int $compressionLevel |
103
|
|
|
* @param null $password |
|
|
|
|
104
|
|
|
* @return int Number of archived files |
105
|
|
|
* @throws UnsupportedOperationException |
106
|
|
|
*/ |
107
|
|
|
public static function createArchive(array $files, $archiveFileName, $compressionLevel = self::COMPRESSION_AVERAGE, $password = null) |
|
|
|
|
108
|
|
|
{ |
109
|
|
|
throw new UnsupportedOperationException(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* BasicDriver constructor. |
114
|
|
|
* @param string $archiveFileName |
115
|
|
|
* @param string $format |
116
|
|
|
* @param string|null $password Archive password for opening |
117
|
|
|
*/ |
118
|
|
|
abstract public function __construct($archiveFileName, $format, $password = null); |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Returns summary about an archive. |
122
|
|
|
* Called after |
123
|
|
|
* - constructing |
124
|
|
|
* - addFiles() |
125
|
|
|
* - deleteFiles() |
126
|
|
|
* @return ArchiveInformation |
127
|
|
|
*/ |
128
|
|
|
abstract public function getArchiveInformation(); |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return array |
132
|
|
|
*/ |
133
|
|
|
abstract public function getFileNames(); |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param string $fileName |
137
|
|
|
* @return bool |
138
|
|
|
*/ |
139
|
|
|
abstract public function isFileExists($fileName); |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param string $fileName |
143
|
|
|
* @return ArchiveEntry|false |
144
|
|
|
*/ |
145
|
|
|
abstract public function getFileData($fileName); |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param string $fileName |
149
|
|
|
* @return string|false |
150
|
|
|
*/ |
151
|
|
|
abstract public function getFileContent($fileName); |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param string $fileName |
155
|
|
|
* @return resource |
156
|
|
|
*/ |
157
|
|
|
abstract public function getFileStream($fileName); |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param $string |
161
|
|
|
* @return resource |
162
|
|
|
*/ |
163
|
6 |
|
public static function wrapStringInStream($string) |
164
|
|
|
{ |
165
|
6 |
|
$resource = fopen('php://temp', 'r+'); |
166
|
6 |
|
fwrite($resource, $string); |
167
|
6 |
|
rewind($resource); |
168
|
6 |
|
return $resource; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param string $outputFolder |
173
|
|
|
* @param array $files |
174
|
|
|
* @return int Number of extracted files |
175
|
|
|
* @throws ArchiveExtractionException |
176
|
|
|
*/ |
177
|
|
|
abstract public function extractFiles($outputFolder, array $files); |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param string $outputFolder |
181
|
|
|
* @return int Number of extracted files |
182
|
|
|
* @throws ArchiveExtractionException |
183
|
|
|
*/ |
184
|
|
|
abstract public function extractArchive($outputFolder); |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @param array $files |
188
|
|
|
* @return false|int Number of deleted files |
189
|
|
|
* @throws UnsupportedOperationException |
190
|
|
|
* @throws ArchiveModificationException |
191
|
|
|
*/ |
192
|
|
|
public function deleteFiles(array $files) |
|
|
|
|
193
|
|
|
{ |
194
|
|
|
throw new UnsupportedOperationException(); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param array $files |
199
|
|
|
* @return int Number of added files |
200
|
|
|
* @throws UnsupportedOperationException |
201
|
|
|
* @throws ArchiveModificationException |
202
|
|
|
*/ |
203
|
|
|
public function addFiles(array $files) |
|
|
|
|
204
|
|
|
{ |
205
|
|
|
throw new UnsupportedOperationException(); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param string $inArchiveName |
210
|
|
|
* @param string $content |
211
|
|
|
* @return bool |
212
|
|
|
* @throws UnsupportedOperationException |
213
|
|
|
* @throws ArchiveModificationException |
214
|
|
|
*/ |
215
|
|
|
abstract public function addFileFromString($inArchiveName, $content); |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @return string|null |
219
|
|
|
*/ |
220
|
|
|
public function getComment() |
221
|
|
|
{ |
222
|
|
|
return null; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @param string|null $comment |
227
|
|
|
* @return null |
228
|
|
|
*/ |
229
|
|
|
public function setComment($comment) |
|
|
|
|
230
|
|
|
{ |
231
|
|
|
return null; |
232
|
|
|
} |
233
|
|
|
} |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.