|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpZip\Constants; |
|
4
|
|
|
|
|
5
|
|
|
use PhpZip\Exception\ZipUnsupportMethodException; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class ZipCompressionMethod. |
|
9
|
|
|
*/ |
|
10
|
|
|
final class ZipCompressionMethod |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var int Compression method Store */ |
|
13
|
|
|
const STORED = 0; |
|
14
|
|
|
|
|
15
|
|
|
/** @var int Compression method Deflate */ |
|
16
|
|
|
const DEFLATED = 8; |
|
17
|
|
|
|
|
18
|
|
|
/** @var int Compression method Bzip2 */ |
|
19
|
|
|
const BZIP2 = 12; |
|
20
|
|
|
|
|
21
|
|
|
/** @var int Compression method AES-Encryption */ |
|
22
|
|
|
const WINZIP_AES = 99; |
|
23
|
|
|
|
|
24
|
|
|
/** @var array Compression Methods */ |
|
25
|
|
|
private static $ZIP_COMPRESSION_METHODS = [ |
|
26
|
|
|
self::STORED => 'Stored', |
|
27
|
|
|
1 => 'Shrunk', |
|
28
|
|
|
2 => 'Reduced compression factor 1', |
|
29
|
|
|
3 => 'Reduced compression factor 2', |
|
30
|
|
|
4 => 'Reduced compression factor 3', |
|
31
|
|
|
5 => 'Reduced compression factor 4', |
|
32
|
|
|
6 => 'Imploded', |
|
33
|
|
|
7 => 'Reserved for Tokenizing compression algorithm', |
|
34
|
|
|
self::DEFLATED => 'Deflated', |
|
35
|
|
|
9 => 'Enhanced Deflating using Deflate64(tm)', |
|
36
|
|
|
10 => 'PKWARE Data Compression Library Imploding', |
|
37
|
|
|
11 => 'Reserved by PKWARE', |
|
38
|
|
|
self::BZIP2 => 'BZIP2', |
|
39
|
|
|
13 => 'Reserved by PKWARE', |
|
40
|
|
|
14 => 'LZMA', |
|
41
|
|
|
15 => 'Reserved by PKWARE', |
|
42
|
|
|
16 => 'Reserved by PKWARE', |
|
43
|
|
|
17 => 'Reserved by PKWARE', |
|
44
|
|
|
18 => 'File is compressed using IBM TERSE (new)', |
|
45
|
|
|
19 => 'IBM LZ77 z Architecture (PFS)', |
|
46
|
|
|
96 => 'WinZip JPEG Compression', |
|
47
|
|
|
97 => 'WavPack compressed data', |
|
48
|
|
|
98 => 'PPMd version I, Rev 1', |
|
49
|
|
|
self::WINZIP_AES => 'AES Encryption', |
|
50
|
|
|
]; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param int $value |
|
54
|
|
|
* |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
46 |
|
public static function getCompressionMethodName($value) |
|
58
|
|
|
{ |
|
59
|
46 |
|
return isset(self::$ZIP_COMPRESSION_METHODS[$value]) ? |
|
60
|
45 |
|
self::$ZIP_COMPRESSION_METHODS[$value] : |
|
61
|
46 |
|
'Unknown Method'; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return int[] |
|
66
|
|
|
*/ |
|
67
|
221 |
|
public static function getSupportMethods() |
|
68
|
|
|
{ |
|
69
|
221 |
|
static $methods; |
|
70
|
|
|
|
|
71
|
221 |
|
if ($methods === null) { |
|
72
|
|
|
$methods = [ |
|
73
|
6 |
|
self::STORED, |
|
74
|
6 |
|
self::DEFLATED, |
|
75
|
|
|
]; |
|
76
|
|
|
|
|
77
|
6 |
|
if (\extension_loaded('bz2')) { |
|
78
|
6 |
|
$methods[] = self::BZIP2; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
221 |
|
return $methods; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param int $compressionMethod |
|
87
|
|
|
* |
|
88
|
|
|
* @throws ZipUnsupportMethodException |
|
89
|
|
|
*/ |
|
90
|
221 |
|
public static function checkSupport($compressionMethod) |
|
91
|
|
|
{ |
|
92
|
221 |
|
$compressionMethod = (int) $compressionMethod; |
|
93
|
|
|
|
|
94
|
221 |
|
if (!\in_array($compressionMethod, self::getSupportMethods(), true)) { |
|
95
|
32 |
|
throw new ZipUnsupportMethodException(sprintf( |
|
96
|
32 |
|
'Compression method %d (%s) is not supported.', |
|
97
|
|
|
$compressionMethod, |
|
98
|
32 |
|
self::getCompressionMethodName($compressionMethod) |
|
99
|
|
|
)); |
|
100
|
|
|
} |
|
101
|
192 |
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|