1 | <?php |
||
22 | class Compress |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * Returns an instance of the archive object |
||
27 | * |
||
28 | * @var \ZipArchive |
||
29 | */ |
||
30 | protected $archiver = null; |
||
31 | |||
32 | /** |
||
33 | * Flag to determine whether the orignial file should be kept |
||
34 | * |
||
35 | * @var bool |
||
36 | */ |
||
37 | protected $keep_original = true; |
||
38 | |||
39 | /** |
||
40 | * The name of the completed archive file |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $archive_name = 'archive.zip'; |
||
45 | |||
46 | /** |
||
47 | * Returns an instance of the Archiver |
||
48 | * |
||
49 | * @return ZipArchive |
||
50 | */ |
||
51 | public function getArchiver() |
||
59 | |||
60 | /** |
||
61 | * Extracts a compressed file to the destination |
||
62 | * |
||
63 | * @param string $file |
||
64 | * The full path to the file to extract |
||
65 | * @param string $destination |
||
66 | * The destination to extract to |
||
67 | * @return bool |
||
68 | */ |
||
69 | public function extract($file, $destination = false) |
||
77 | |||
78 | /** |
||
79 | * Sets the archive file name |
||
80 | * |
||
81 | * @param string $name |
||
82 | * @return \mithra62\Compress |
||
83 | */ |
||
84 | public function setArchiveName($name) |
||
89 | |||
90 | /** |
||
91 | * Returns the archive file name |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | public function getArchiveName() |
||
99 | |||
100 | /** |
||
101 | * Starts the process of creating an archive |
||
102 | * |
||
103 | * @param string $name |
||
104 | * @return \mithra62\Compress |
||
105 | */ |
||
106 | public function create($name) |
||
112 | |||
113 | /** |
||
114 | * Adds a file to the archive |
||
115 | * |
||
116 | * @param string $path |
||
117 | * @param string $relative |
||
118 | * @return \mithra62\Compress |
||
119 | */ |
||
120 | public function add($path, $relative) |
||
125 | |||
126 | /** |
||
127 | * Closes the zip archive object |
||
128 | * |
||
129 | * @return string The path to the archive |
||
130 | */ |
||
131 | public function close() |
||
136 | |||
137 | /** |
||
138 | * Compresses a single file |
||
139 | * |
||
140 | * @param string $file |
||
141 | * the full path to the file to compress |
||
142 | * @param string $desination |
||
143 | * optional the full path to the destination. If none is given then $file is used with the extension appended |
||
144 | */ |
||
145 | public function archiveSingle($file, $desination = false) |
||
196 | |||
197 | /** |
||
198 | * Sets whether the original file should be removed once compressed |
||
199 | * |
||
200 | * @param bool $flag |
||
201 | * @return \mithra62\Compress |
||
202 | */ |
||
203 | public function setKeepOriginal($flag = true) |
||
208 | |||
209 | /** |
||
210 | * Returns whether the original file should be kept once compressed |
||
211 | * |
||
212 | * @return \mithra62\bool |
||
213 | */ |
||
214 | public function getKeepOriginal() |
||
218 | } |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: