forked from zhouyl/Archive-Compress-for-PHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchive.php
93 lines (83 loc) · 2.14 KB
/
archive.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* 文档压缩/解压抽象类
*
* <code>
* // 创建 ZIP 压缩文件
* $zip = new Archive_Zip();
* $zip->setArchive('zip_compress.zip') // 指定输出的文件名
* ->compress('/var/compress_path'); // 压缩指定的目录到 ZIP
*
* // 创建解压缩目录
* mkdir("/var/decompress_path", 7770);
*
* // 解压缩 ZIP 文件
* $zip = new Archive_Zip();
* $zip->setTarget('/var/decompress_path') // 解压到指定目录
* ->decompress('zip_compress.zip'); // 解压指定文件
* </code>
*
* @see http://framework.zend.com/manual/1.10/en/zend.filter.set.html#zend.filter.set.compress.decompress
* @author ZhouYL <[email protected]>
* @license http://apache.org/licenses/LICENSE-2.0.txt
*/
abstract class Archive
{
/**
* Class constructor
*
* @param array $options (Optional) Options to set
*/
public function __construct(array $options = NULL)
{
if (is_array($options)) {
$this->setOptions($options);
}
}
/**
* Returns one or all set options
*
* @param string $option (Optional) Option to return
* @return mixed
*/
public function getOptions($option = NULL)
{
if ($option === NULL) {
return $this->_options;
}
if ( ! array_key_exists($option, $this->_options)) {
return NULL;
}
return $this->_options[$option];
}
/**
* Sets all or one option
*
* @param array $options
* @return Archive
*/
public function setOptions(array $options)
{
foreach ($options as $key => $option) {
$method = 'set'.$key;
if (method_exists($this, $method)) {
$this->$method($option);
}
}
return $this;
}
/**
* Compresses the given content
*
* @param string $content
* @return string
*/
abstract public function compress($content);
/**
* Decompresses the given content
*
* @param string $content
* @return string
*/
abstract public function decompress($content);
}