@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | 'WriteThreshold' => 100 |
41 | 41 | ); |
42 | 42 | |
43 | - /** |
|
44 | - * @var string |
|
45 | - */ |
|
43 | + /** |
|
44 | + * @var string |
|
45 | + */ |
|
46 | 46 | protected $file; |
47 | 47 | |
48 | - /** |
|
49 | - * @var ZipArchive|NULL |
|
50 | - */ |
|
48 | + /** |
|
49 | + * @var ZipArchive|NULL |
|
50 | + */ |
|
51 | 51 | protected $zip; |
52 | 52 | |
53 | 53 | protected bool $open = false; |
@@ -57,35 +57,35 @@ discard block |
||
57 | 57 | $this->file = $targetFile; |
58 | 58 | } |
59 | 59 | |
60 | - /** |
|
61 | - * Sets an option, among the available options: |
|
62 | - * |
|
63 | - * <ul> |
|
64 | - * <li>WriteThreshold: The amount of files to add before the zip is automatically written to disk and re-opened to release the file handles. Set to 0 to disable.</li> |
|
65 | - * </ul> |
|
66 | - * |
|
67 | - * @param string $name |
|
68 | - * @param mixed $value |
|
69 | - * @return ZIPHelper |
|
70 | - */ |
|
60 | + /** |
|
61 | + * Sets an option, among the available options: |
|
62 | + * |
|
63 | + * <ul> |
|
64 | + * <li>WriteThreshold: The amount of files to add before the zip is automatically written to disk and re-opened to release the file handles. Set to 0 to disable.</li> |
|
65 | + * </ul> |
|
66 | + * |
|
67 | + * @param string $name |
|
68 | + * @param mixed $value |
|
69 | + * @return ZIPHelper |
|
70 | + */ |
|
71 | 71 | public function setOption(string $name, $value) : ZIPHelper |
72 | 72 | { |
73 | 73 | $this->options[$name] = $value; |
74 | 74 | return $this; |
75 | 75 | } |
76 | 76 | |
77 | - /** |
|
78 | - * Adds a file to the zip. By default, the file is stored |
|
79 | - * with the same name in the root of the zip. Use the optional |
|
80 | - * parameter to change the location in the zip. |
|
81 | - * |
|
82 | - * @param string $filePath |
|
83 | - * @param string|null $zipPath If no path is specified, file will be added with the same name in the ZIP's root. |
|
84 | - * @throws ZIPHelper_Exception |
|
85 | - * @return bool |
|
86 | - * |
|
87 | - * @see FileHelper::ERROR_SOURCE_FILE_DOES_NOT_EXIST |
|
88 | - */ |
|
77 | + /** |
|
78 | + * Adds a file to the zip. By default, the file is stored |
|
79 | + * with the same name in the root of the zip. Use the optional |
|
80 | + * parameter to change the location in the zip. |
|
81 | + * |
|
82 | + * @param string $filePath |
|
83 | + * @param string|null $zipPath If no path is specified, file will be added with the same name in the ZIP's root. |
|
84 | + * @throws ZIPHelper_Exception |
|
85 | + * @return bool |
|
86 | + * |
|
87 | + * @see FileHelper::ERROR_SOURCE_FILE_DOES_NOT_EXIST |
|
88 | + */ |
|
89 | 89 | public function addFile(string $filePath, ?string $zipPath=null) : bool |
90 | 90 | { |
91 | 91 | $this->open(); |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | public const ERROR_SOURCE_FILE_DOES_NOT_EXIST = 338001; |
32 | 32 | public const ERROR_NO_FILES_IN_ARCHIVE = 338002; |
33 | 33 | public const ERROR_OPENING_ZIP_FILE = 338003; |
34 | - public const ERROR_CANNOT_SAVE_FILE_TO_DISK =338004; |
|
34 | + public const ERROR_CANNOT_SAVE_FILE_TO_DISK = 338004; |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @var array<string,mixed> |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @see FileHelper::ERROR_SOURCE_FILE_DOES_NOT_EXIST |
88 | 88 | */ |
89 | - public function addFile(string $filePath, ?string $zipPath=null) : bool |
|
89 | + public function addFile(string $filePath, ?string $zipPath = null) : bool |
|
90 | 90 | { |
91 | 91 | $this->open(); |
92 | 92 | |
@@ -134,16 +134,16 @@ discard block |
||
134 | 134 | */ |
135 | 135 | protected function open() : void |
136 | 136 | { |
137 | - if($this->open) { |
|
137 | + if ($this->open) { |
|
138 | 138 | return; |
139 | 139 | } |
140 | 140 | |
141 | - if(!isset($this->zip)) { |
|
141 | + if (!isset($this->zip)) { |
|
142 | 142 | $this->zip = new ZipArchive(); |
143 | 143 | } |
144 | 144 | |
145 | 145 | $flag = null; |
146 | - if(!file_exists($this->file)) { |
|
146 | + if (!file_exists($this->file)) { |
|
147 | 147 | $flag = ZipArchive::CREATE; |
148 | 148 | } |
149 | 149 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | { |
187 | 187 | $this->fileTracker++; |
188 | 188 | |
189 | - if($this->options['WriteThreshold'] < 1) { |
|
189 | + if ($this->options['WriteThreshold'] < 1) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | */ |
204 | 204 | protected function close() : void |
205 | 205 | { |
206 | - if(!$this->open) { |
|
206 | + if (!$this->open) { |
|
207 | 207 | return; |
208 | 208 | } |
209 | 209 | |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | throw new ZIPHelper_Exception( |
213 | 213 | 'Could not save ZIP file to disk', |
214 | 214 | sprintf( |
215 | - 'Tried saving the ZIP file [%1$s], but the write failed. This can have several causes, ' . |
|
216 | - 'including adding files that do not exist on disk, trying to create an empty zip, ' . |
|
215 | + 'Tried saving the ZIP file [%1$s], but the write failed. This can have several causes, '. |
|
216 | + 'including adding files that do not exist on disk, trying to create an empty zip, '. |
|
217 | 217 | 'or trying to save to a directory that does not exist.', |
218 | 218 | $this->file |
219 | 219 | ), |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | { |
233 | 233 | $this->open(); |
234 | 234 | |
235 | - if($this->countFiles() < 1) |
|
235 | + if ($this->countFiles() < 1) |
|
236 | 236 | { |
237 | 237 | throw new ZIPHelper_Exception( |
238 | 238 | 'No files in the zip file', |
@@ -258,18 +258,18 @@ discard block |
||
258 | 258 | * @throws ZIPHelper_Exception |
259 | 259 | * @return string The file name that was sent (useful in case none was specified). |
260 | 260 | */ |
261 | - public function download(?string $fileName=null) : string |
|
261 | + public function download(?string $fileName = null) : string |
|
262 | 262 | { |
263 | 263 | $this->save(); |
264 | 264 | |
265 | - if(empty($fileName)) |
|
265 | + if (empty($fileName)) |
|
266 | 266 | { |
267 | 267 | $fileName = basename($this->file); |
268 | 268 | } |
269 | 269 | |
270 | 270 | header('Content-type: application/zip'); |
271 | - header('Content-Disposition: attachment; filename=' . $fileName); |
|
272 | - header('Content-length: ' . filesize($this->file)); |
|
271 | + header('Content-Disposition: attachment; filename='.$fileName); |
|
272 | + header('Content-length: '.filesize($this->file)); |
|
273 | 273 | header('Pragma: no-cache'); |
274 | 274 | header('Expires: 0'); |
275 | 275 | readfile($this->file); |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * @throws ZIPHelper_Exception |
288 | 288 | * @see ZIPHelper::download() |
289 | 289 | */ |
290 | - public function downloadAndDelete(?string $fileName=null) : ZIPHelper |
|
290 | + public function downloadAndDelete(?string $fileName = null) : ZIPHelper |
|
291 | 291 | { |
292 | 292 | $this->download($fileName); |
293 | 293 | |
@@ -305,9 +305,9 @@ discard block |
||
305 | 305 | * @return boolean |
306 | 306 | * @throws ZIPHelper_Exception |
307 | 307 | */ |
308 | - public function extractAll(?string $outputFolder=null) : bool |
|
308 | + public function extractAll(?string $outputFolder = null) : bool |
|
309 | 309 | { |
310 | - if(empty($outputFolder)) { |
|
310 | + if (empty($outputFolder)) { |
|
311 | 311 | $outputFolder = dirname($this->file); |
312 | 312 | } |
313 | 313 |