@@ -17,7 +17,7 @@ |
||
17 | 17 | private static $AVERAGE_COMPRESSION_RATIO = 2; |
18 | 18 | public static $forceTmpFile = false; |
19 | 19 | /** High limit. unit: MBytes. |
20 | - */ |
|
20 | + */ |
|
21 | 21 | public static $highLimit = 512; |
22 | 22 | |
23 | 23 | private $mode; |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | */ |
12 | 12 | public static function registerWrapper() |
13 | 13 | { |
14 | - if (!self::$registered) |
|
15 | - stream_wrapper_register('compress.lzw', __CLASS__); |
|
14 | + if (!self::$registered) { |
|
15 | + stream_wrapper_register('compress.lzw', __CLASS__); |
|
16 | + } |
|
16 | 17 | self::$registered = true; |
17 | 18 | } |
18 | 19 | |
@@ -43,12 +44,14 @@ discard block |
||
43 | 44 | { |
44 | 45 | // check for compress & uncompress utility |
45 | 46 | $this->checkBinary(); |
46 | - if (self::$installed === false) |
|
47 | - throw new \Exception('compress and uncompress commands are required'); |
|
47 | + if (self::$installed === false) { |
|
48 | + throw new \Exception('compress and uncompress commands are required'); |
|
49 | + } |
|
48 | 50 | |
49 | 51 | $schema = 'compress.lzw://'; |
50 | - if (strncasecmp($schema, $path, strlen($schema)) == 0) |
|
51 | - $path = substr($path, strlen($schema)); |
|
52 | + if (strncasecmp($schema, $path, strlen($schema)) == 0) { |
|
53 | + $path = substr($path, strlen($schema)); |
|
54 | + } |
|
52 | 55 | |
53 | 56 | if (file_exists($path)) { |
54 | 57 | $this->path = realpath($path); |
@@ -62,14 +65,16 @@ discard block |
||
62 | 65 | $this->read(); |
63 | 66 | } else { |
64 | 67 | $prefix = basename(__FILE__, '.php'); |
65 | - if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
66 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
68 | + if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
69 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
67 | 70 | ': Could not create temporary file in '. |
68 | 71 | sys_get_temp_dir()); |
69 | - if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
70 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
72 | + } |
|
73 | + if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
74 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
71 | 75 | ': Could not create temporary file in '. |
72 | 76 | sys_get_temp_dir()); |
77 | + } |
|
73 | 78 | $this->tmp = $tmp; |
74 | 79 | $this->tmp2 = $tmp2; |
75 | 80 | $this->read(); |
@@ -78,14 +83,16 @@ discard block |
||
78 | 83 | $this->path = $path; |
79 | 84 | if (self::$forceTmpFile) { |
80 | 85 | $prefix = basename(__FILE__, '.php'); |
81 | - if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
82 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
86 | + if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
87 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
83 | 88 | ': Could not create temporary file in '. |
84 | 89 | sys_get_temp_dir()); |
85 | - if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
86 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
90 | + } |
|
91 | + if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
92 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
87 | 93 | ': Could not create temporary file in '. |
88 | 94 | sys_get_temp_dir()); |
95 | + } |
|
89 | 96 | $this->tmp = $tmp; |
90 | 97 | $this->tmp2 = $tmp2; |
91 | 98 | $this->pointer = 0; |
@@ -266,7 +273,9 @@ discard block |
||
266 | 273 | } |
267 | 274 | if ($this->tmp !== null) { |
268 | 275 | unlink($this->tmp); |
269 | - if (file_exists($this->tmp2)) unlink($this->tmp2); |
|
276 | + if (file_exists($this->tmp2)) { |
|
277 | + unlink($this->tmp2); |
|
278 | + } |
|
270 | 279 | } else { |
271 | 280 | $this->data = null; |
272 | 281 | } |
@@ -237,8 +237,8 @@ |
||
237 | 237 | if ($code == 0 || $code == 2 || is_null($code)) { |
238 | 238 | // rewrite original file |
239 | 239 | if (rename($this->tmp2, $this->path) !== true) { |
240 | - throw new \RuntimeException(__FILE__ . ', line ' . __LINE__ . |
|
241 | - ': Could not replace original file ' . $this->path); |
|
240 | + throw new \RuntimeException(__FILE__.', line '.__LINE__. |
|
241 | + ': Could not replace original file '.$this->path); |
|
242 | 242 | } |
243 | 243 | } else { |
244 | 244 | throw new \RuntimeException(__FILE__.', line '.__LINE__. |
@@ -147,8 +147,8 @@ discard block |
||
147 | 147 | } |
148 | 148 | } else { |
149 | 149 | $options = array_combine( |
150 | - array_filter($options, function ($v) {return (bool) $v&2;}), |
|
151 | - array_filter($options, function ($v) {return (bool) ($v-1)&2;}) |
|
150 | + array_filter($options, function($v) {return (bool) $v & 2; }), |
|
151 | + array_filter($options, function($v) {return (bool) ($v - 1) & 2; }) |
|
152 | 152 | ); |
153 | 153 | } |
154 | 154 | |
@@ -156,12 +156,12 @@ discard block |
||
156 | 156 | $filters = array(); |
157 | 157 | if (isset($options[PCLZIP_OPT_REMOVE_PATH]) |
158 | 158 | && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
159 | - $filters[] = function (&$key, &$value) use ($options) { |
|
159 | + $filters[] = function(&$key, &$value) use ($options) { |
|
160 | 160 | $key = str_replace($key, null, $key); }; |
161 | 161 | if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
162 | - $filters[] = function (&$key, &$value) { $key = basename($key); }; |
|
162 | + $filters[] = function(&$key, &$value) { $key = basename($key); }; |
|
163 | 163 | if (isset($options[PCLZIP_OPT_ADD_PATH])) |
164 | - $filters[] = function (&$key, &$value) use ($options) { |
|
164 | + $filters[] = function(&$key, &$value) use ($options) { |
|
165 | 165 | $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/').'/'. |
166 | 166 | ltrim($key, '/'); |
167 | 167 | }; |
@@ -169,12 +169,12 @@ discard block |
||
169 | 169 | if (isset($options[PCLZIP_CB_PRE_ADD]) |
170 | 170 | && is_callable($options[PCLZIP_CB_PRE_ADD])) |
171 | 171 | $preAddCallback = $options[PCLZIP_CB_PRE_ADD]; |
172 | - else $preAddCallback = function () { return 1; }; |
|
172 | + else $preAddCallback = function() { return 1; }; |
|
173 | 173 | |
174 | 174 | if (isset($options[PCLZIP_CB_POST_ADD]) |
175 | 175 | && is_callable($options[PCLZIP_CB_POST_ADD])) |
176 | 176 | $postAddCallback = $options[PCLZIP_CB_POST_ADD]; |
177 | - else $postAddCallback = function () { return 1; }; |
|
177 | + else $postAddCallback = function() { return 1; }; |
|
178 | 178 | |
179 | 179 | if (isset($options[PCLZIP_OPT_COMMENT])) |
180 | 180 | $this->archive->setArchiveComment($options[PCLZIP_OPT_COMMENT]); |
@@ -248,8 +248,7 @@ discard block |
||
248 | 248 | 'size' => $statIndex['size'], |
249 | 249 | 'compressed_size' => $statIndex['comp_size'], |
250 | 250 | 'mtime' => $statIndex, |
251 | - 'comment' => ($comment = $this->archive->getCommentIndex |
|
252 | - ($statIndex['index']) !== false) ? $comment : null, |
|
251 | + 'comment' => ($comment = $this->archive->getCommentIndex($statIndex['index']) !== false) ? $comment : null, |
|
253 | 252 | 'folder' => in_array(substr($statIndex['name'], -1), |
254 | 253 | array('/', '\\')), |
255 | 254 | 'index' => $statIndex['index'], |
@@ -279,8 +278,8 @@ discard block |
||
279 | 278 | } |
280 | 279 | } else { |
281 | 280 | $options = array_combine( |
282 | - array_filter($options, function ($v) {return (bool) $v&2;}), |
|
283 | - array_filter($options, function ($v) {return (bool) ($v-1)&2;}) |
|
281 | + array_filter($options, function($v) {return (bool) $v & 2; }), |
|
282 | + array_filter($options, function($v) {return (bool) ($v - 1) & 2; }) |
|
284 | 283 | ); |
285 | 284 | } |
286 | 285 | |
@@ -292,13 +291,13 @@ discard block |
||
292 | 291 | $filters = array(); |
293 | 292 | if (isset($options[PCLZIP_OPT_REMOVE_PATH]) |
294 | 293 | && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
295 | - $filters[] = function (&$key, &$value) use ($options) { |
|
294 | + $filters[] = function(&$key, &$value) use ($options) { |
|
296 | 295 | $key = str_replace($key, null, $key); |
297 | 296 | }; |
298 | 297 | if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
299 | - $filters[] = function (&$key, &$value) { $key = basename($key); }; |
|
298 | + $filters[] = function(&$key, &$value) { $key = basename($key); }; |
|
300 | 299 | if (isset($options[PCLZIP_OPT_ADD_PATH])) |
301 | - $filters[] = function (&$key, &$value) use ($options) { |
|
300 | + $filters[] = function(&$key, &$value) use ($options) { |
|
302 | 301 | $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/').'/'. |
303 | 302 | ltrim($key, '/'); |
304 | 303 | }; |
@@ -306,16 +305,16 @@ discard block |
||
306 | 305 | if (isset($options[PCLZIP_CB_PRE_EXTRACT]) |
307 | 306 | && is_callable($options[PCLZIP_CB_PRE_EXTRACT])) |
308 | 307 | $preExtractCallback = $options[PCLZIP_CB_PRE_EXTRACT]; |
309 | - else $preExtractCallback = function () { return 1; }; |
|
308 | + else $preExtractCallback = function() { return 1; }; |
|
310 | 309 | |
311 | 310 | if (isset($options[PCLZIP_CB_POST_EXTRACT]) |
312 | 311 | && is_callable($options[PCLZIP_CB_POST_EXTRACT])) |
313 | 312 | $postExtractCallback = $options[PCLZIP_CB_POST_EXTRACT]; |
314 | - else $postExtractCallback = function () { return 1; }; |
|
313 | + else $postExtractCallback = function() { return 1; }; |
|
315 | 314 | |
316 | 315 | // exact matching |
317 | 316 | if (isset($options[PCLZIP_OPT_BY_NAME])) |
318 | - $selectFilter = function ($key, $value) use ($options) { |
|
317 | + $selectFilter = function($key, $value) use ($options) { |
|
319 | 318 | $allowedNames = is_array($options[PCLZIP_OPT_BY_NAME]) |
320 | 319 | ? $options[PCLZIP_OPT_BY_NAME] |
321 | 320 | : explode(',', $options[PCLZIP_OPT_BY_NAME]); |
@@ -340,21 +339,21 @@ discard block |
||
340 | 339 | }; |
341 | 340 | // <ereg> rule |
342 | 341 | else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg')) |
343 | - $selectFilter = function ($key, $value) use ($options) { |
|
342 | + $selectFilter = function($key, $value) use ($options) { |
|
344 | 343 | return (ereg($options[PCLZIP_OPT_BY_EREG], $key) !== false) |
345 | 344 | ? self::SELECT_FILTER_PASS |
346 | 345 | : self::SELECT_FILTER_REFUSE; |
347 | 346 | }; |
348 | 347 | // <preg_match> rule |
349 | 348 | else if (isset($options[PCLZIP_OPT_BY_PREG])) |
350 | - $selectFilter = function ($key, $value) use ($options) { |
|
349 | + $selectFilter = function($key, $value) use ($options) { |
|
351 | 350 | return preg_match($options[PCLZIP_OPT_BY_PREG], $key) |
352 | 351 | ? self::SELECT_FILTER_PASS |
353 | 352 | : self::SELECT_FILTER_REFUSE; |
354 | 353 | }; |
355 | 354 | // index rule |
356 | 355 | else if (isset($options[PCLZIP_OPT_BY_INDEX])) |
357 | - $selectFilter = function ($key, $value, $index) use ($options) { |
|
356 | + $selectFilter = function($key, $value, $index) use ($options) { |
|
358 | 357 | $allowedIndexes = array(); |
359 | 358 | foreach ($options[PCLZIP_OPT_BY_INDEX] as $rule) { |
360 | 359 | $parts = explode('-', $rule); |
@@ -368,7 +367,7 @@ discard block |
||
368 | 367 | }; |
369 | 368 | // no rule |
370 | 369 | else |
371 | - $selectFilter = function () { return self::SELECT_FILTER_PASS; }; |
|
370 | + $selectFilter = function() { return self::SELECT_FILTER_PASS; }; |
|
372 | 371 | |
373 | 372 | if (isset($options[PCLZIP_OPT_EXTRACT_AS_STRING])) |
374 | 373 | $anotherOutputFormat = PCLZIP_OPT_EXTRACT_AS_STRING; |
@@ -560,8 +559,8 @@ discard block |
||
560 | 559 | } |
561 | 560 | } else { |
562 | 561 | $options = array_combine( |
563 | - array_filter($options, function ($v) {return (bool) $v&2;}), |
|
564 | - array_filter($options, function ($v) {return (bool) ($v-1)&2;}) |
|
562 | + array_filter($options, function($v) {return (bool) $v & 2; }), |
|
563 | + array_filter($options, function($v) {return (bool) ($v - 1) & 2; }) |
|
565 | 564 | ); |
566 | 565 | } |
567 | 566 | |
@@ -569,13 +568,13 @@ discard block |
||
569 | 568 | $filters = array(); |
570 | 569 | if (isset($options[PCLZIP_OPT_REMOVE_PATH]) |
571 | 570 | && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
572 | - $filters[] = function (&$key, &$value) use ($options) { |
|
571 | + $filters[] = function(&$key, &$value) use ($options) { |
|
573 | 572 | $key = str_replace($key, null, $key); |
574 | 573 | }; |
575 | 574 | if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
576 | - $filters[] = function (&$key, &$value) { $key = basename($key); }; |
|
575 | + $filters[] = function(&$key, &$value) { $key = basename($key); }; |
|
577 | 576 | if (isset($options[PCLZIP_OPT_ADD_PATH])) |
578 | - $filters[] = function (&$key, &$value) use ($options) { |
|
577 | + $filters[] = function(&$key, &$value) use ($options) { |
|
579 | 578 | $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/').'/'. |
580 | 579 | ltrim($key, '/'); |
581 | 580 | }; |
@@ -583,12 +582,12 @@ discard block |
||
583 | 582 | if (isset($options[PCLZIP_CB_PRE_ADD]) |
584 | 583 | && is_callable($options[PCLZIP_CB_PRE_ADD])) |
585 | 584 | $preAddCallback = $options[PCLZIP_CB_PRE_ADD]; |
586 | - else $preAddCallback = function () { return 1; }; |
|
585 | + else $preAddCallback = function() { return 1; }; |
|
587 | 586 | |
588 | 587 | if (isset($options[PCLZIP_CB_POST_ADD]) |
589 | 588 | && is_callable($options[PCLZIP_CB_POST_ADD])) |
590 | 589 | $postAddCallback = $options[PCLZIP_CB_POST_ADD]; |
591 | - else $postAddCallback = function () { return 1; }; |
|
590 | + else $postAddCallback = function() { return 1; }; |
|
592 | 591 | |
593 | 592 | if (isset($options[PCLZIP_OPT_COMMENT])) |
594 | 593 | $this->archive->setArchiveComment($options[PCLZIP_OPT_COMMENT]); |
@@ -597,14 +596,14 @@ discard block |
||
597 | 596 | ($comment = $this->archive->getArchiveComment() !== false) |
598 | 597 | ? $comment : null; |
599 | 598 | $this->archive->setArchiveComment( |
600 | - $comment . $options[PCLZIP_OPT_ADD_COMMENT]); |
|
599 | + $comment.$options[PCLZIP_OPT_ADD_COMMENT]); |
|
601 | 600 | } |
602 | 601 | if (isset($options[PCLZIP_OPT_PREPEND_COMMENT])) { |
603 | 602 | $comment = |
604 | 603 | ($comment = $this->archive->getArchiveComment() !== false) |
605 | 604 | ? $comment : null; |
606 | 605 | $this->archive->setArchiveComment( |
607 | - $options[PCLZIP_OPT_PREPEND_COMMENT] . $comment); |
|
606 | + $options[PCLZIP_OPT_PREPEND_COMMENT].$comment); |
|
608 | 607 | } |
609 | 608 | |
610 | 609 | |
@@ -640,13 +639,13 @@ discard block |
||
640 | 639 | $report = array(); |
641 | 640 | $options = func_get_args(); |
642 | 641 | $options = array_combine( |
643 | - array_filter($options, function ($v) {return (bool) $v&2;}), |
|
644 | - array_filter($options, function ($v) {return (bool) ($v-1)&2;}) |
|
642 | + array_filter($options, function($v) {return (bool) $v & 2; }), |
|
643 | + array_filter($options, function($v) {return (bool) ($v - 1) & 2; }) |
|
645 | 644 | ); |
646 | 645 | |
647 | 646 | // exact matching |
648 | 647 | if (isset($options[PCLZIP_OPT_BY_NAME])) |
649 | - $selectFilter = function ($key, $value) use ($options) { |
|
648 | + $selectFilter = function($key, $value) use ($options) { |
|
650 | 649 | $allowedNames = is_array($options[PCLZIP_OPT_BY_NAME]) |
651 | 650 | ? $options[PCLZIP_OPT_BY_NAME] |
652 | 651 | : explode(',', $options[PCLZIP_OPT_BY_NAME]); |
@@ -671,21 +670,21 @@ discard block |
||
671 | 670 | }; |
672 | 671 | // <ereg> rule |
673 | 672 | else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg')) |
674 | - $selectFilter = function ($key, $value) use ($options) { |
|
673 | + $selectFilter = function($key, $value) use ($options) { |
|
675 | 674 | return (ereg($options[PCLZIP_OPT_BY_EREG], $key) !== false) |
676 | 675 | ? self::SELECT_FILTER_PASS |
677 | 676 | : self::SELECT_FILTER_REFUSE; |
678 | 677 | }; |
679 | 678 | // <preg_match> rule |
680 | 679 | else if (isset($options[PCLZIP_OPT_BY_PREG])) |
681 | - $selectFilter = function ($key, $value) use ($options) { |
|
680 | + $selectFilter = function($key, $value) use ($options) { |
|
682 | 681 | return preg_match($options[PCLZIP_OPT_BY_PREG], $key) |
683 | 682 | ? self::SELECT_FILTER_PASS |
684 | 683 | : self::SELECT_FILTER_REFUSE; |
685 | 684 | }; |
686 | 685 | // index rule |
687 | 686 | else if (isset($options[PCLZIP_OPT_BY_INDEX])) |
688 | - $selectFilter = function ($key, $value, $index) use ($options) { |
|
687 | + $selectFilter = function($key, $value, $index) use ($options) { |
|
689 | 688 | $allowedIndexes = array(); |
690 | 689 | foreach ($options[PCLZIP_OPT_BY_INDEX] as $rule) { |
691 | 690 | $parts = explode('-', $rule); |
@@ -700,7 +699,7 @@ discard block |
||
700 | 699 | }; |
701 | 700 | // no rule |
702 | 701 | else |
703 | - $selectFilter = function () { return self::SELECT_FILTER_PASS; }; |
|
702 | + $selectFilter = function() { return self::SELECT_FILTER_PASS; }; |
|
704 | 703 | |
705 | 704 | foreach ($this->listContent() as $file_header) { |
706 | 705 | // select by select rule |
@@ -780,7 +779,7 @@ discard block |
||
780 | 779 | } |
781 | 780 | } |
782 | 781 | |
783 | - call_user_func(function ($directory) { |
|
782 | + call_user_func(function($directory) { |
|
784 | 783 | foreach (glob($directory.'/*') as $f) { |
785 | 784 | if (is_dir($f)) call_user_func(__FUNCTION__, $f); |
786 | 785 | else unlink($f); |
@@ -132,8 +132,11 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function create($content) |
134 | 134 | { |
135 | - if (is_array($content)) $paths_list = $content; |
|
136 | - else $paths_list = explode(',', $content); |
|
135 | + if (is_array($content)) { |
|
136 | + $paths_list = $content; |
|
137 | + } else { |
|
138 | + $paths_list = explode(',', $content); |
|
139 | + } |
|
137 | 140 | $report = array(); |
138 | 141 | |
139 | 142 | $options = func_get_args(); |
@@ -155,29 +158,41 @@ discard block |
||
155 | 158 | // filters initiation |
156 | 159 | $filters = array(); |
157 | 160 | if (isset($options[PCLZIP_OPT_REMOVE_PATH]) |
158 | - && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
159 | - $filters[] = function (&$key, &$value) use ($options) { |
|
160 | - $key = str_replace($key, null, $key); }; |
|
161 | - if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
162 | - $filters[] = function (&$key, &$value) { $key = basename($key); }; |
|
163 | - if (isset($options[PCLZIP_OPT_ADD_PATH])) |
|
164 | - $filters[] = function (&$key, &$value) use ($options) { |
|
161 | + && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
162 | + $filters[] = function (&$key, &$value) use ($options) { |
|
163 | + $key = str_replace($key, null, $key); |
|
164 | + } |
|
165 | + }; |
|
166 | + if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
167 | + $filters[] = function (&$key, &$value) { $key = basename($key); |
|
168 | + } |
|
169 | + }; |
|
170 | + if (isset($options[PCLZIP_OPT_ADD_PATH])) { |
|
171 | + $filters[] = function (&$key, &$value) use ($options) { |
|
165 | 172 | $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/').'/'. |
166 | 173 | ltrim($key, '/'); |
174 | + } |
|
167 | 175 | }; |
168 | 176 | |
169 | 177 | if (isset($options[PCLZIP_CB_PRE_ADD]) |
170 | - && is_callable($options[PCLZIP_CB_PRE_ADD])) |
|
171 | - $preAddCallback = $options[PCLZIP_CB_PRE_ADD]; |
|
172 | - else $preAddCallback = function () { return 1; }; |
|
178 | + && is_callable($options[PCLZIP_CB_PRE_ADD])) { |
|
179 | + $preAddCallback = $options[PCLZIP_CB_PRE_ADD]; |
|
180 | + } else { |
|
181 | + $preAddCallback = function () { return 1; |
|
182 | + } |
|
183 | + }; |
|
173 | 184 | |
174 | 185 | if (isset($options[PCLZIP_CB_POST_ADD]) |
175 | - && is_callable($options[PCLZIP_CB_POST_ADD])) |
|
176 | - $postAddCallback = $options[PCLZIP_CB_POST_ADD]; |
|
177 | - else $postAddCallback = function () { return 1; }; |
|
186 | + && is_callable($options[PCLZIP_CB_POST_ADD])) { |
|
187 | + $postAddCallback = $options[PCLZIP_CB_POST_ADD]; |
|
188 | + } else { |
|
189 | + $postAddCallback = function () { return 1; |
|
190 | + } |
|
191 | + }; |
|
178 | 192 | |
179 | - if (isset($options[PCLZIP_OPT_COMMENT])) |
|
180 | - $this->archive->setArchiveComment($options[PCLZIP_OPT_COMMENT]); |
|
193 | + if (isset($options[PCLZIP_OPT_COMMENT])) { |
|
194 | + $this->archive->setArchiveComment($options[PCLZIP_OPT_COMMENT]); |
|
195 | + } |
|
181 | 196 | |
182 | 197 | // scan filesystem for files list |
183 | 198 | $files_list = array(); |
@@ -208,20 +223,23 @@ discard block |
||
208 | 223 | // apply filters to a file |
209 | 224 | $localname = $file_to_add; |
210 | 225 | $filename = $file_to_add; |
211 | - foreach ($filters as $filter) |
|
212 | - call_user_func($filter, $localname, $filename); |
|
226 | + foreach ($filters as $filter) { |
|
227 | + call_user_func($filter, $localname, $filename); |
|
228 | + } |
|
213 | 229 | $file_header = $this->createFileHeader($localname, $filename); |
214 | 230 | if (call_user_func($preAddCallback, $file_header) == 1) { |
215 | 231 | // |
216 | 232 | // Check for max length > 255 |
217 | 233 | // |
218 | - if (strlen(basename($file_header->stored_filename)) > 255) |
|
219 | - $file_header->status = 'filename_too_long'; |
|
220 | - if (is_file($filename)) |
|
221 | - $this->archive->addFile($file_header->filename, |
|
234 | + if (strlen(basename($file_header->stored_filename)) > 255) { |
|
235 | + $file_header->status = 'filename_too_long'; |
|
236 | + } |
|
237 | + if (is_file($filename)) { |
|
238 | + $this->archive->addFile($file_header->filename, |
|
222 | 239 | $file_header->stored_filename); |
223 | - else if (is_dir($filename)) |
|
224 | - $this->archive->addEmptyDir($file_header->stored_filename); |
|
240 | + } else if (is_dir($filename)) { |
|
241 | + $this->archive->addEmptyDir($file_header->stored_filename); |
|
242 | + } |
|
225 | 243 | } else { |
226 | 244 | // |
227 | 245 | // File was skipped |
@@ -285,40 +303,53 @@ discard block |
||
285 | 303 | } |
286 | 304 | |
287 | 305 | // filters initiation |
288 | - if (isset($options[PCLZIP_OPT_PATH])) |
|
289 | - $extractPath = rtrim($options[PCLZIP_OPT_PATH], '/'); |
|
290 | - else $extractPath = rtrim(getcwd(), '/'); |
|
306 | + if (isset($options[PCLZIP_OPT_PATH])) { |
|
307 | + $extractPath = rtrim($options[PCLZIP_OPT_PATH], '/'); |
|
308 | + } else { |
|
309 | + $extractPath = rtrim(getcwd(), '/'); |
|
310 | + } |
|
291 | 311 | |
292 | 312 | $filters = array(); |
293 | 313 | if (isset($options[PCLZIP_OPT_REMOVE_PATH]) |
294 | - && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
295 | - $filters[] = function (&$key, &$value) use ($options) { |
|
314 | + && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
315 | + $filters[] = function (&$key, &$value) use ($options) { |
|
296 | 316 | $key = str_replace($key, null, $key); |
317 | + } |
|
297 | 318 | }; |
298 | - if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
299 | - $filters[] = function (&$key, &$value) { $key = basename($key); }; |
|
300 | - if (isset($options[PCLZIP_OPT_ADD_PATH])) |
|
301 | - $filters[] = function (&$key, &$value) use ($options) { |
|
319 | + if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
320 | + $filters[] = function (&$key, &$value) { $key = basename($key); |
|
321 | + } |
|
322 | + }; |
|
323 | + if (isset($options[PCLZIP_OPT_ADD_PATH])) { |
|
324 | + $filters[] = function (&$key, &$value) use ($options) { |
|
302 | 325 | $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/').'/'. |
303 | 326 | ltrim($key, '/'); |
327 | + } |
|
304 | 328 | }; |
305 | 329 | |
306 | 330 | if (isset($options[PCLZIP_CB_PRE_EXTRACT]) |
307 | - && is_callable($options[PCLZIP_CB_PRE_EXTRACT])) |
|
308 | - $preExtractCallback = $options[PCLZIP_CB_PRE_EXTRACT]; |
|
309 | - else $preExtractCallback = function () { return 1; }; |
|
331 | + && is_callable($options[PCLZIP_CB_PRE_EXTRACT])) { |
|
332 | + $preExtractCallback = $options[PCLZIP_CB_PRE_EXTRACT]; |
|
333 | + } else { |
|
334 | + $preExtractCallback = function () { return 1; |
|
335 | + } |
|
336 | + }; |
|
310 | 337 | |
311 | 338 | if (isset($options[PCLZIP_CB_POST_EXTRACT]) |
312 | - && is_callable($options[PCLZIP_CB_POST_EXTRACT])) |
|
313 | - $postExtractCallback = $options[PCLZIP_CB_POST_EXTRACT]; |
|
314 | - else $postExtractCallback = function () { return 1; }; |
|
339 | + && is_callable($options[PCLZIP_CB_POST_EXTRACT])) { |
|
340 | + $postExtractCallback = $options[PCLZIP_CB_POST_EXTRACT]; |
|
341 | + } else { |
|
342 | + $postExtractCallback = function () { return 1; |
|
343 | + } |
|
344 | + }; |
|
315 | 345 | |
316 | 346 | // exact matching |
317 | - if (isset($options[PCLZIP_OPT_BY_NAME])) |
|
318 | - $selectFilter = function ($key, $value) use ($options) { |
|
347 | + if (isset($options[PCLZIP_OPT_BY_NAME])) { |
|
348 | + $selectFilter = function ($key, $value) use ($options) { |
|
319 | 349 | $allowedNames = is_array($options[PCLZIP_OPT_BY_NAME]) |
320 | 350 | ? $options[PCLZIP_OPT_BY_NAME] |
321 | 351 | : explode(',', $options[PCLZIP_OPT_BY_NAME]); |
352 | + } |
|
322 | 353 | foreach ($allowedNames as $name) { |
323 | 354 | // select directory with nested files |
324 | 355 | if (in_array(substr($name, -1), array('/', '\\'))) { |
@@ -339,50 +370,64 @@ discard block |
||
339 | 370 | return self::SELECT_FILTER_REFUSE; |
340 | 371 | }; |
341 | 372 | // <ereg> rule |
342 | - else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg')) |
|
343 | - $selectFilter = function ($key, $value) use ($options) { |
|
373 | + else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg')) { |
|
374 | + $selectFilter = function ($key, $value) use ($options) { |
|
344 | 375 | return (ereg($options[PCLZIP_OPT_BY_EREG], $key) !== false) |
345 | 376 | ? self::SELECT_FILTER_PASS |
346 | 377 | : self::SELECT_FILTER_REFUSE; |
378 | + } |
|
347 | 379 | }; |
348 | 380 | // <preg_match> rule |
349 | - else if (isset($options[PCLZIP_OPT_BY_PREG])) |
|
350 | - $selectFilter = function ($key, $value) use ($options) { |
|
381 | + else if (isset($options[PCLZIP_OPT_BY_PREG])) { |
|
382 | + $selectFilter = function ($key, $value) use ($options) { |
|
351 | 383 | return preg_match($options[PCLZIP_OPT_BY_PREG], $key) |
352 | 384 | ? self::SELECT_FILTER_PASS |
353 | 385 | : self::SELECT_FILTER_REFUSE; |
386 | + } |
|
354 | 387 | }; |
355 | 388 | // index rule |
356 | - else if (isset($options[PCLZIP_OPT_BY_INDEX])) |
|
357 | - $selectFilter = function ($key, $value, $index) use ($options) { |
|
389 | + else if (isset($options[PCLZIP_OPT_BY_INDEX])) { |
|
390 | + $selectFilter = function ($key, $value, $index) use ($options) { |
|
358 | 391 | $allowedIndexes = array(); |
392 | + } |
|
359 | 393 | foreach ($options[PCLZIP_OPT_BY_INDEX] as $rule) { |
360 | 394 | $parts = explode('-', $rule); |
361 | - if (count($parts) == 1) $allowedIndexes[] = $rule; |
|
362 | - else $allowedIndexes = array_merge( |
|
395 | + if (count($parts) == 1) { |
|
396 | + $allowedIndexes[] = $rule; |
|
397 | + } else { |
|
398 | + $allowedIndexes = array_merge( |
|
363 | 399 | range($parts[0], $parts[1]), $allowedIndexes); |
400 | + } |
|
364 | 401 | } |
365 | 402 | |
366 | 403 | return in_array($index, $allowedIndexes) ? self::SELECT_FILTER_PASS |
367 | 404 | : self::SELECT_FILTER_REFUSE; |
368 | 405 | }; |
369 | 406 | // no rule |
370 | - else |
|
371 | - $selectFilter = function () { return self::SELECT_FILTER_PASS; }; |
|
407 | + else { |
|
408 | + $selectFilter = function () { return self::SELECT_FILTER_PASS; |
|
409 | + } |
|
410 | + }; |
|
372 | 411 | |
373 | - if (isset($options[PCLZIP_OPT_EXTRACT_AS_STRING])) |
|
374 | - $anotherOutputFormat = PCLZIP_OPT_EXTRACT_AS_STRING; |
|
375 | - else if (isset($options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) |
|
376 | - $anotherOutputFormat = PCLZIP_OPT_EXTRACT_IN_OUTPUT; |
|
377 | - else $anotherOutputFormat = false; |
|
412 | + if (isset($options[PCLZIP_OPT_EXTRACT_AS_STRING])) { |
|
413 | + $anotherOutputFormat = PCLZIP_OPT_EXTRACT_AS_STRING; |
|
414 | + } else if (isset($options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { |
|
415 | + $anotherOutputFormat = PCLZIP_OPT_EXTRACT_IN_OUTPUT; |
|
416 | + } else { |
|
417 | + $anotherOutputFormat = false; |
|
418 | + } |
|
378 | 419 | |
379 | - if (isset($options[PCLZIP_OPT_REPLACE_NEWER])) |
|
380 | - $doNotReplaceNewer = false; |
|
381 | - else $doNotReplaceNewer = true; |
|
420 | + if (isset($options[PCLZIP_OPT_REPLACE_NEWER])) { |
|
421 | + $doNotReplaceNewer = false; |
|
422 | + } else { |
|
423 | + $doNotReplaceNewer = true; |
|
424 | + } |
|
382 | 425 | |
383 | - if (isset($options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) |
|
384 | - $restrictExtractDir = $options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION]; |
|
385 | - else $restrictExtractDir = false; |
|
426 | + if (isset($options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { |
|
427 | + $restrictExtractDir = $options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION]; |
|
428 | + } else { |
|
429 | + $restrictExtractDir = false; |
|
430 | + } |
|
386 | 431 | |
387 | 432 | $report = array(); |
388 | 433 | foreach ($this->listContent() as $file_header) { |
@@ -452,8 +497,10 @@ discard block |
||
452 | 497 | // extract content |
453 | 498 | else if ($anotherOutputFormat === false) { |
454 | 499 | // apply path filters |
455 | - foreach ($filters as $filter) call_user_func($filter, |
|
500 | + foreach ($filters as $filter) { |
|
501 | + call_user_func($filter, |
|
456 | 502 | $file_header->stored_filename, $file_header->filename); |
503 | + } |
|
457 | 504 | // dir extraction process |
458 | 505 | if ($file_header->folder) { |
459 | 506 | // if dir doesn't exist |
@@ -545,8 +592,11 @@ discard block |
||
545 | 592 | */ |
546 | 593 | public function add($content) |
547 | 594 | { |
548 | - if (is_array($content)) $paths_list = $content; |
|
549 | - else $paths_list = array_map(explode(',', $content)); |
|
595 | + if (is_array($content)) { |
|
596 | + $paths_list = $content; |
|
597 | + } else { |
|
598 | + $paths_list = array_map(explode(',', $content)); |
|
599 | + } |
|
550 | 600 | $report = array(); |
551 | 601 | |
552 | 602 | $options = func_get_args(); |
@@ -568,30 +618,41 @@ discard block |
||
568 | 618 | // filters initiation |
569 | 619 | $filters = array(); |
570 | 620 | if (isset($options[PCLZIP_OPT_REMOVE_PATH]) |
571 | - && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
572 | - $filters[] = function (&$key, &$value) use ($options) { |
|
621 | + && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
622 | + $filters[] = function (&$key, &$value) use ($options) { |
|
573 | 623 | $key = str_replace($key, null, $key); |
624 | + } |
|
574 | 625 | }; |
575 | - if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
576 | - $filters[] = function (&$key, &$value) { $key = basename($key); }; |
|
577 | - if (isset($options[PCLZIP_OPT_ADD_PATH])) |
|
578 | - $filters[] = function (&$key, &$value) use ($options) { |
|
626 | + if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
627 | + $filters[] = function (&$key, &$value) { $key = basename($key); |
|
628 | + } |
|
629 | + }; |
|
630 | + if (isset($options[PCLZIP_OPT_ADD_PATH])) { |
|
631 | + $filters[] = function (&$key, &$value) use ($options) { |
|
579 | 632 | $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/').'/'. |
580 | 633 | ltrim($key, '/'); |
634 | + } |
|
581 | 635 | }; |
582 | 636 | |
583 | 637 | if (isset($options[PCLZIP_CB_PRE_ADD]) |
584 | - && is_callable($options[PCLZIP_CB_PRE_ADD])) |
|
585 | - $preAddCallback = $options[PCLZIP_CB_PRE_ADD]; |
|
586 | - else $preAddCallback = function () { return 1; }; |
|
638 | + && is_callable($options[PCLZIP_CB_PRE_ADD])) { |
|
639 | + $preAddCallback = $options[PCLZIP_CB_PRE_ADD]; |
|
640 | + } else { |
|
641 | + $preAddCallback = function () { return 1; |
|
642 | + } |
|
643 | + }; |
|
587 | 644 | |
588 | 645 | if (isset($options[PCLZIP_CB_POST_ADD]) |
589 | - && is_callable($options[PCLZIP_CB_POST_ADD])) |
|
590 | - $postAddCallback = $options[PCLZIP_CB_POST_ADD]; |
|
591 | - else $postAddCallback = function () { return 1; }; |
|
646 | + && is_callable($options[PCLZIP_CB_POST_ADD])) { |
|
647 | + $postAddCallback = $options[PCLZIP_CB_POST_ADD]; |
|
648 | + } else { |
|
649 | + $postAddCallback = function () { return 1; |
|
650 | + } |
|
651 | + }; |
|
592 | 652 | |
593 | - if (isset($options[PCLZIP_OPT_COMMENT])) |
|
594 | - $this->archive->setArchiveComment($options[PCLZIP_OPT_COMMENT]); |
|
653 | + if (isset($options[PCLZIP_OPT_COMMENT])) { |
|
654 | + $this->archive->setArchiveComment($options[PCLZIP_OPT_COMMENT]); |
|
655 | + } |
|
595 | 656 | if (isset($options[PCLZIP_OPT_ADD_COMMENT])) { |
596 | 657 | $comment = |
597 | 658 | ($comment = $this->archive->getArchiveComment() !== false) |
@@ -645,11 +706,12 @@ discard block |
||
645 | 706 | ); |
646 | 707 | |
647 | 708 | // exact matching |
648 | - if (isset($options[PCLZIP_OPT_BY_NAME])) |
|
649 | - $selectFilter = function ($key, $value) use ($options) { |
|
709 | + if (isset($options[PCLZIP_OPT_BY_NAME])) { |
|
710 | + $selectFilter = function ($key, $value) use ($options) { |
|
650 | 711 | $allowedNames = is_array($options[PCLZIP_OPT_BY_NAME]) |
651 | 712 | ? $options[PCLZIP_OPT_BY_NAME] |
652 | 713 | : explode(',', $options[PCLZIP_OPT_BY_NAME]); |
714 | + } |
|
653 | 715 | foreach ($allowedNames as $name) { |
654 | 716 | // select directory with nested files |
655 | 717 | if (in_array(substr($name, -1), array('/', '\\'))) { |
@@ -670,28 +732,34 @@ discard block |
||
670 | 732 | return self::SELECT_FILTER_REFUSE; |
671 | 733 | }; |
672 | 734 | // <ereg> rule |
673 | - else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg')) |
|
674 | - $selectFilter = function ($key, $value) use ($options) { |
|
735 | + else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg')) { |
|
736 | + $selectFilter = function ($key, $value) use ($options) { |
|
675 | 737 | return (ereg($options[PCLZIP_OPT_BY_EREG], $key) !== false) |
676 | 738 | ? self::SELECT_FILTER_PASS |
677 | 739 | : self::SELECT_FILTER_REFUSE; |
740 | + } |
|
678 | 741 | }; |
679 | 742 | // <preg_match> rule |
680 | - else if (isset($options[PCLZIP_OPT_BY_PREG])) |
|
681 | - $selectFilter = function ($key, $value) use ($options) { |
|
743 | + else if (isset($options[PCLZIP_OPT_BY_PREG])) { |
|
744 | + $selectFilter = function ($key, $value) use ($options) { |
|
682 | 745 | return preg_match($options[PCLZIP_OPT_BY_PREG], $key) |
683 | 746 | ? self::SELECT_FILTER_PASS |
684 | 747 | : self::SELECT_FILTER_REFUSE; |
748 | + } |
|
685 | 749 | }; |
686 | 750 | // index rule |
687 | - else if (isset($options[PCLZIP_OPT_BY_INDEX])) |
|
688 | - $selectFilter = function ($key, $value, $index) use ($options) { |
|
751 | + else if (isset($options[PCLZIP_OPT_BY_INDEX])) { |
|
752 | + $selectFilter = function ($key, $value, $index) use ($options) { |
|
689 | 753 | $allowedIndexes = array(); |
754 | + } |
|
690 | 755 | foreach ($options[PCLZIP_OPT_BY_INDEX] as $rule) { |
691 | 756 | $parts = explode('-', $rule); |
692 | - if (count($parts) == 1) $allowedIndexes[] = $rule; |
|
693 | - else $allowedIndexes = array_merge( |
|
757 | + if (count($parts) == 1) { |
|
758 | + $allowedIndexes[] = $rule; |
|
759 | + } else { |
|
760 | + $allowedIndexes = array_merge( |
|
694 | 761 | range($parts[0], $parts[1]), $allowedIndexes); |
762 | + } |
|
695 | 763 | } |
696 | 764 | |
697 | 765 | return in_array($index, $allowedIndexes) |
@@ -699,8 +767,10 @@ discard block |
||
699 | 767 | : self::SELECT_FILTER_REFUSE; |
700 | 768 | }; |
701 | 769 | // no rule |
702 | - else |
|
703 | - $selectFilter = function () { return self::SELECT_FILTER_PASS; }; |
|
770 | + else { |
|
771 | + $selectFilter = function () { return self::SELECT_FILTER_PASS; |
|
772 | + } |
|
773 | + }; |
|
704 | 774 | |
705 | 775 | foreach ($this->listContent() as $file_header) { |
706 | 776 | // select by select rule |
@@ -752,8 +822,12 @@ discard block |
||
752 | 822 | } |
753 | 823 | |
754 | 824 | $tempDir = tempnam(PCLZIP_TEMPORARY_DIR, 'merging'); |
755 | - if (file_exists($tempDir)) unlink($tempDir); |
|
756 | - if (!mkdir($tempDir)) return 0; |
|
825 | + if (file_exists($tempDir)) { |
|
826 | + unlink($tempDir); |
|
827 | + } |
|
828 | + if (!mkdir($tempDir)) { |
|
829 | + return 0; |
|
830 | + } |
|
757 | 831 | |
758 | 832 | // go through archive content list and copy all files |
759 | 833 | foreach ($a->getFileNames() as $filename) { |
@@ -782,8 +856,11 @@ discard block |
||
782 | 856 | |
783 | 857 | call_user_func(function ($directory) { |
784 | 858 | foreach (glob($directory.'/*') as $f) { |
785 | - if (is_dir($f)) call_user_func(__FUNCTION__, $f); |
|
786 | - else unlink($f); |
|
859 | + if (is_dir($f)) { |
|
860 | + call_user_func(__FUNCTION__, $f); |
|
861 | + } else { |
|
862 | + unlink($f); |
|
863 | + } |
|
787 | 864 | } |
788 | 865 | }, $tempDir); |
789 | 866 |
@@ -258,12 +258,14 @@ discard block |
||
258 | 258 | { |
259 | 259 | |
260 | 260 | static::retrieveAllFormats(); |
261 | - if (!static::canOpen($format)) |
|
262 | - return false; |
|
261 | + if (!static::canOpen($format)) { |
|
262 | + return false; |
|
263 | + } |
|
263 | 264 | |
264 | 265 | foreach (static::$formatsSupport[$format] as $driver) { |
265 | - if ($driver::$function($format)) |
|
266 | - return true; |
|
266 | + if ($driver::$function($format)) { |
|
267 | + return true; |
|
268 | + } |
|
267 | 269 | } |
268 | 270 | |
269 | 271 | return false; |
@@ -278,15 +280,18 @@ discard block |
||
278 | 280 | { |
279 | 281 | static::retrieveAllFormats(); |
280 | 282 | |
281 | - if (!static::canOpen($format)) |
|
282 | - throw new UnsupportedArchiveException('Unsupported archive type: '.$format.' of archive '); |
|
283 | + if (!static::canOpen($format)) { |
|
284 | + throw new UnsupportedArchiveException('Unsupported archive type: '.$format.' of archive '); |
|
285 | + } |
|
283 | 286 | |
284 | - if (!$createAbility) |
|
285 | - return current(static::$formatsSupport[$format]); |
|
287 | + if (!$createAbility) { |
|
288 | + return current(static::$formatsSupport[$format]); |
|
289 | + } |
|
286 | 290 | |
287 | 291 | foreach (static::$formatsSupport[$format] as $driver) { |
288 | - if ($driver::canCreateArchive($format)) |
|
289 | - return $driver; |
|
292 | + if ($driver::canCreateArchive($format)) { |
|
293 | + return $driver; |
|
294 | + } |
|
290 | 295 | } |
291 | 296 | return false; |
292 | 297 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public static function open($fileName, $password = null) |
56 | 56 | { |
57 | 57 | if (!file_exists($fileName) || !is_readable($fileName)) { |
58 | - throw new InvalidArgumentException('Could not open file: ' . $fileName); |
|
58 | + throw new InvalidArgumentException('Could not open file: '.$fileName); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | $format = Formats::detectArchiveFormat($fileName); |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | public function getFileData($fileName) |
215 | 215 | { |
216 | 216 | if (!in_array($fileName, $this->files, true)) { |
217 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
217 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | return $this->archive->getFileData($fileName); |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | public function getFileContent($fileName) |
231 | 231 | { |
232 | 232 | if (!in_array($fileName, $this->files, true)) { |
233 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
233 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | return $this->archive->getFileContent($fileName); |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | public function getFileStream($fileName) |
247 | 247 | { |
248 | 248 | if (!in_array($fileName, $this->files, true)) { |
249 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
249 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | return $this->archive->getFileStream($fileName); |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | public static function archiveFile($file, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE) |
502 | 502 | { |
503 | 503 | if (!is_file($file)) { |
504 | - throw new InvalidArgumentException($file . ' is not a valid file to archive'); |
|
504 | + throw new InvalidArgumentException($file.' is not a valid file to archive'); |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | return static::archiveFiles($file, $archiveName, $compressionLevel) === 1; |
@@ -326,8 +326,9 @@ discard block |
||
326 | 326 | { |
327 | 327 | $files_list = static::createFilesList($fileOrFiles); |
328 | 328 | |
329 | - if (empty($files_list)) |
|
330 | - throw new EmptyFileListException('Files list is empty!'); |
|
329 | + if (empty($files_list)) { |
|
330 | + throw new EmptyFileListException('Files list is empty!'); |
|
331 | + } |
|
331 | 332 | |
332 | 333 | $result = $this->archive->addFiles($files_list); |
333 | 334 | $this->scanArchive(); |
@@ -346,8 +347,9 @@ discard block |
||
346 | 347 | */ |
347 | 348 | public function addFile($file, $inArchiveName = null) |
348 | 349 | { |
349 | - if (!is_file($file)) |
|
350 | - throw new InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
350 | + if (!is_file($file)) { |
|
351 | + throw new InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
352 | + } |
|
351 | 353 | |
352 | 354 | return ($inArchiveName !== null |
353 | 355 | ? $this->addFiles([$inArchiveName => $file]) |
@@ -380,8 +382,9 @@ discard block |
||
380 | 382 | */ |
381 | 383 | public function addDirectory($directory, $inArchivePath = null) |
382 | 384 | { |
383 | - if (!is_dir($directory) || !is_readable($directory)) |
|
384 | - throw new InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
385 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
386 | + throw new InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
387 | + } |
|
385 | 388 | |
386 | 389 | return ($inArchivePath !== null |
387 | 390 | ? $this->addFiles([$inArchivePath => $directory]) |
@@ -421,13 +424,15 @@ discard block |
||
421 | 424 | { |
422 | 425 | $archiveType = Formats::detectArchiveFormat($archiveName, false); |
423 | 426 | |
424 | - if ($archiveType === false) |
|
425 | - throw new UnsupportedArchiveException('Could not detect archive type for name "'.$archiveName.'"'); |
|
427 | + if ($archiveType === false) { |
|
428 | + throw new UnsupportedArchiveException('Could not detect archive type for name "'.$archiveName.'"'); |
|
429 | + } |
|
426 | 430 | |
427 | 431 | $files_list = static::createFilesList($fileOrFiles); |
428 | 432 | |
429 | - if (empty($files_list)) |
|
430 | - throw new EmptyFileListException('Files list is empty!'); |
|
433 | + if (empty($files_list)) { |
|
434 | + throw new EmptyFileListException('Files list is empty!'); |
|
435 | + } |
|
431 | 436 | |
432 | 437 | $totalSize = 0; |
433 | 438 | foreach ($files_list as $fn) { |
@@ -471,16 +476,19 @@ discard block |
||
471 | 476 | */ |
472 | 477 | public static function archiveFiles($fileOrFiles, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
473 | 478 | { |
474 | - if (file_exists($archiveName)) |
|
475 | - throw new FileAlreadyExistsException('Archive '.$archiveName.' already exists!'); |
|
479 | + if (file_exists($archiveName)) { |
|
480 | + throw new FileAlreadyExistsException('Archive '.$archiveName.' already exists!'); |
|
481 | + } |
|
476 | 482 | |
477 | 483 | $info = static::prepareForArchiving($fileOrFiles, $archiveName); |
478 | 484 | |
479 | - if (!Formats::canCreate($info['type'])) |
|
480 | - throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '.$archiveName); |
|
485 | + if (!Formats::canCreate($info['type'])) { |
|
486 | + throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '.$archiveName); |
|
487 | + } |
|
481 | 488 | |
482 | - if ($password !== null && !Formats::canEncrypt($info['type'])) |
|
483 | - throw new UnsupportedOperationException('Archive type '.$info['type'].' can not be encrypted'); |
|
489 | + if ($password !== null && !Formats::canEncrypt($info['type'])) { |
|
490 | + throw new UnsupportedOperationException('Archive type '.$info['type'].' can not be encrypted'); |
|
491 | + } |
|
484 | 492 | |
485 | 493 | /** @var BasicDriver $handler_class */ |
486 | 494 | $driver = Formats::getFormatDriver($info['type'], true); |
@@ -519,8 +527,9 @@ discard block |
||
519 | 527 | */ |
520 | 528 | public static function archiveDirectory($directory, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE) |
521 | 529 | { |
522 | - if (!is_dir($directory) || !is_readable($directory)) |
|
523 | - throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
530 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
531 | + throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
532 | + } |
|
524 | 533 | |
525 | 534 | return static::archiveFiles($directory, $archiveName) > 0; |
526 | 535 | } |
@@ -555,26 +564,29 @@ discard block |
||
555 | 564 | // passed an extended list |
556 | 565 | if (is_array($nodes)) { |
557 | 566 | foreach ($nodes as $destination => $source) { |
558 | - if (is_numeric($destination)) |
|
559 | - $destination = $source; |
|
567 | + if (is_numeric($destination)) { |
|
568 | + $destination = $source; |
|
569 | + } |
|
560 | 570 | |
561 | 571 | $destination = rtrim($destination, '/\\*'); |
562 | 572 | |
563 | 573 | // if is directory |
564 | - if (is_dir($source)) |
|
565 | - static::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
574 | + if (is_dir($source)) { |
|
575 | + static::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
566 | 576 | !empty($destination) ? $destination.'/' : null, true, $files); |
567 | - else if (is_file($source)) |
|
568 | - $files[$destination] = $source; |
|
577 | + } else if (is_file($source)) { |
|
578 | + $files[$destination] = $source; |
|
579 | + } |
|
569 | 580 | } |
570 | 581 | |
571 | 582 | } else if (is_string($nodes)) { // passed one file or directory |
572 | 583 | // if is directory |
573 | - if (is_dir($nodes)) |
|
574 | - static::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
584 | + if (is_dir($nodes)) { |
|
585 | + static::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
575 | 586 | $files); |
576 | - else if (is_file($nodes)) |
|
577 | - $files[basename($nodes)] = $nodes; |
|
587 | + } else if (is_file($nodes)) { |
|
588 | + $files[basename($nodes)] = $nodes; |
|
589 | + } |
|
578 | 590 | } |
579 | 591 | |
580 | 592 | return $files; |
@@ -591,8 +603,9 @@ discard block |
||
591 | 603 | // $map[$destination] = rtrim($source, '/*'); |
592 | 604 | // do not map root archive folder |
593 | 605 | |
594 | - if ($destination !== null) |
|
595 | - $map[$destination] = null; |
|
606 | + if ($destination !== null) { |
|
607 | + $map[$destination] = null; |
|
608 | + } |
|
596 | 609 | |
597 | 610 | foreach (glob($source, GLOB_MARK) as $node) { |
598 | 611 | if (in_array(substr($node, -1), ['/', '\\'], true) && $recursive) { |
@@ -100,7 +100,9 @@ discard block |
||
100 | 100 | { |
101 | 101 | $information = new ArchiveInformation(); |
102 | 102 | foreach ($this->rar->getEntries() as $i => $entry) { |
103 | - if ($entry->isDirectory()) continue; |
|
103 | + if ($entry->isDirectory()) { |
|
104 | + continue; |
|
105 | + } |
|
104 | 106 | $information->files[] = $entry->getName(); |
105 | 107 | $information->compressedFilesSize += $entry->getPackedSize(); |
106 | 108 | $information->uncompressedFilesSize += $entry->getUnpackedSize(); |
@@ -115,7 +117,9 @@ discard block |
||
115 | 117 | { |
116 | 118 | $files = []; |
117 | 119 | foreach ($this->rar->getEntries() as $i => $entry) { |
118 | - if ($entry->isDirectory()) continue; |
|
120 | + if ($entry->isDirectory()) { |
|
121 | + continue; |
|
122 | + } |
|
119 | 123 | $files[] = $entry->getName(); |
120 | 124 | } |
121 | 125 | return $files; |
@@ -151,7 +155,9 @@ discard block |
||
151 | 155 | public function getFileContent($fileName) |
152 | 156 | { |
153 | 157 | $entry = $this->rar->getEntry($fileName); |
154 | - if ($entry->isDirectory()) return false; |
|
158 | + if ($entry->isDirectory()) { |
|
159 | + return false; |
|
160 | + } |
|
155 | 161 | return stream_get_contents($entry->getStream()); |
156 | 162 | } |
157 | 163 | |
@@ -163,7 +169,9 @@ discard block |
||
163 | 169 | public function getFileStream($fileName) |
164 | 170 | { |
165 | 171 | $entry = $this->rar->getEntry($fileName); |
166 | - if ($entry->isDirectory()) return false; |
|
172 | + if ($entry->isDirectory()) { |
|
173 | + return false; |
|
174 | + } |
|
167 | 175 | return $entry->getStream(); |
168 | 176 | } |
169 | 177 |
@@ -60,8 +60,9 @@ |
||
60 | 60 | */ |
61 | 61 | public function __construct($archiveFileName, $format, $password = null) |
62 | 62 | { |
63 | - if ($password !== null) |
|
64 | - throw new UnsupportedOperationException('Cab archive does not support password!'); |
|
63 | + if ($password !== null) { |
|
64 | + throw new UnsupportedOperationException('Cab archive does not support password!'); |
|
65 | + } |
|
65 | 66 | $this->open($archiveFileName); |
66 | 67 | } |
67 | 68 |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $compression = 'lzma2'; |
120 | 120 | break; |
121 | 121 | case 'z': |
122 | - $tar_aname = 'compress.lzw://' . $archiveFileName; |
|
122 | + $tar_aname = 'compress.lzw://'.$archiveFileName; |
|
123 | 123 | break; |
124 | 124 | } |
125 | 125 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | |
172 | 172 | case Formats::TAR_LZW: |
173 | 173 | LzwStreamWrapper::registerWrapper(); |
174 | - $this->tar = new Archive_Tar('compress.lzw://' . $this->archiveFileName); |
|
174 | + $this->tar = new Archive_Tar('compress.lzw://'.$this->archiveFileName); |
|
175 | 175 | break; |
176 | 176 | |
177 | 177 | default: |
@@ -123,21 +123,24 @@ discard block |
||
123 | 123 | break; |
124 | 124 | } |
125 | 125 | |
126 | - if (isset($tar_aname)) |
|
127 | - $tar = new Archive_Tar($tar_aname, $compression); |
|
128 | - else |
|
129 | - $tar = new Archive_Tar($archiveFileName, $compression); |
|
126 | + if (isset($tar_aname)) { |
|
127 | + $tar = new Archive_Tar($tar_aname, $compression); |
|
128 | + } else { |
|
129 | + $tar = new Archive_Tar($archiveFileName, $compression); |
|
130 | + } |
|
130 | 131 | |
131 | 132 | foreach ($files as $localName => $filename) { |
132 | 133 | $remove_dir = dirname($filename); |
133 | 134 | $add_dir = dirname($localName); |
134 | 135 | |
135 | 136 | if (is_null($filename)) { |
136 | - if ($tar->addString($localName, '') === false) |
|
137 | - throw new ArchiveCreationException('Error when adding directory '.$localName.' to archive'); |
|
137 | + if ($tar->addString($localName, '') === false) { |
|
138 | + throw new ArchiveCreationException('Error when adding directory '.$localName.' to archive'); |
|
139 | + } |
|
138 | 140 | } else { |
139 | - if ($tar->addModify($filename, $add_dir, $remove_dir) === false) |
|
140 | - throw new ArchiveCreationException('Error when adding file '.$filename.' to archive'); |
|
141 | + if ($tar->addModify($filename, $add_dir, $remove_dir) === false) { |
|
142 | + throw new ArchiveCreationException('Error when adding file '.$filename.' to archive'); |
|
143 | + } |
|
141 | 144 | } |
142 | 145 | } |
143 | 146 | $tar = null; |
@@ -194,8 +197,9 @@ discard block |
||
194 | 197 | continue; |
195 | 198 | } |
196 | 199 | // skip directories |
197 | - if ($file['typeflag'] == '5' || substr($file['filename'], -1) === '/') |
|
198 | - continue; |
|
200 | + if ($file['typeflag'] == '5' || substr($file['filename'], -1) === '/') { |
|
201 | + continue; |
|
202 | + } |
|
199 | 203 | $information->files[] = $file['filename']; |
200 | 204 | $information->uncompressedFilesSize += $file['size']; |
201 | 205 | $this->pearFilesIndex[$file['filename']] = $i; |
@@ -240,14 +244,16 @@ discard block |
||
240 | 244 | */ |
241 | 245 | public function getFileData($fileName) |
242 | 246 | { |
243 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
244 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
247 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
248 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
249 | + } |
|
245 | 250 | |
246 | 251 | $index = $this->pearFilesIndex[$fileName]; |
247 | 252 | |
248 | 253 | $files_list = $this->tar->listContent(); |
249 | - if (!isset($files_list[$index])) |
|
250 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in Tar archive'); |
|
254 | + if (!isset($files_list[$index])) { |
|
255 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in Tar archive'); |
|
256 | + } |
|
251 | 257 | |
252 | 258 | $data = $files_list[$index]; |
253 | 259 | unset($files_list); |
@@ -262,8 +268,9 @@ discard block |
||
262 | 268 | */ |
263 | 269 | public function getFileContent($fileName) |
264 | 270 | { |
265 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
266 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
271 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
272 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
273 | + } |
|
267 | 274 | |
268 | 275 | return $this->tar->extractInString($fileName); |
269 | 276 | } |
@@ -273,8 +280,9 @@ discard block |
||
273 | 280 | */ |
274 | 281 | public function getFileStream($fileName) |
275 | 282 | { |
276 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
277 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
283 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
284 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
285 | + } |
|
278 | 286 | |
279 | 287 | return self::wrapStringInStream($this->tar->extractInString($fileName)); |
280 | 288 | } |
@@ -203,8 +203,9 @@ |
||
203 | 203 | $deleted = 0; |
204 | 204 | |
205 | 205 | foreach ($files as $i => $file) { |
206 | - if ($this->tar->delete($file)) |
|
207 | - $deleted++; |
|
206 | + if ($this->tar->delete($file)) { |
|
207 | + $deleted++; |
|
208 | + } |
|
208 | 209 | } |
209 | 210 | |
210 | 211 | $this->tar = null; |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | $this->files[$file->Location] = $directory.$file->strd_FileId; |
121 | 121 | $this->filesSize += $file->DataLen; |
122 | 122 | |
123 | - $this->filesData[$directory . $file->strd_FileId] = |
|
123 | + $this->filesData[$directory.$file->strd_FileId] = |
|
124 | 124 | [ |
125 | 125 | 'size' => $file->DataLen, |
126 | 126 | 'mtime' => |
127 | - strtotime((string)$file->isoRecDate), |
|
127 | + strtotime((string) $file->isoRecDate), |
|
128 | 128 | ]; |
129 | 129 | } |
130 | 130 | } |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | return false; |
173 | 173 | |
174 | 174 | return new ArchiveEntry($fileName, $this->filesData[$fileName]['size'], |
175 | - $this->filesData[$fileName]['size'], $this->filesData[$fileName]['mtime'],false); |
|
175 | + $this->filesData[$fileName]['size'], $this->filesData[$fileName]['mtime'], false); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -69,8 +69,9 @@ discard block |
||
69 | 69 | public function __construct($archiveFileName, $format, $password = null) |
70 | 70 | { |
71 | 71 | $this->open($archiveFileName); |
72 | - if ($password !== null) |
|
73 | - throw new UnsupportedOperationException('Iso archive does not support password!'); |
|
72 | + if ($password !== null) { |
|
73 | + throw new UnsupportedOperationException('Iso archive does not support password!'); |
|
74 | + } |
|
74 | 75 | } |
75 | 76 | |
76 | 77 | /** |
@@ -93,8 +94,9 @@ discard block |
||
93 | 94 | |
94 | 95 | /** @var \CVolumeDescriptor $usedDesc */ |
95 | 96 | $usedDesc = $this->iso->GetDescriptor(SUPPLEMENTARY_VOLUME_DESC); |
96 | - if (!$usedDesc) |
|
97 | - $usedDesc = $this->iso->GetDescriptor(PRIMARY_VOLUME_DESC); |
|
97 | + if (!$usedDesc) { |
|
98 | + $usedDesc = $this->iso->GetDescriptor(PRIMARY_VOLUME_DESC); |
|
99 | + } |
|
98 | 100 | $this->blockSize = $usedDesc->iBlockSize; |
99 | 101 | $directories = $usedDesc->LoadMPathTable($this->iso); |
100 | 102 | // iterate over all directories |
@@ -115,8 +117,9 @@ discard block |
||
115 | 117 | if ($files) { |
116 | 118 | /** @var \CFileDirDescriptors $file */ |
117 | 119 | foreach ($files as $file) { |
118 | - if (in_array($file->strd_FileId, ['.', '..']) || $file->IsDirectory()) |
|
119 | - continue; |
|
120 | + if (in_array($file->strd_FileId, ['.', '..']) || $file->IsDirectory()) { |
|
121 | + continue; |
|
122 | + } |
|
120 | 123 | $this->files[$file->Location] = $directory.$file->strd_FileId; |
121 | 124 | $this->filesSize += $file->DataLen; |
122 | 125 | |
@@ -168,8 +171,9 @@ discard block |
||
168 | 171 | */ |
169 | 172 | public function getFileData($fileName) |
170 | 173 | { |
171 | - if (!isset($this->filesData[$fileName])) |
|
172 | - return false; |
|
174 | + if (!isset($this->filesData[$fileName])) { |
|
175 | + return false; |
|
176 | + } |
|
173 | 177 | |
174 | 178 | return new ArchiveEntry($fileName, $this->filesData[$fileName]['size'], |
175 | 179 | $this->filesData[$fileName]['size'], $this->filesData[$fileName]['mtime'],false); |
@@ -204,11 +208,14 @@ discard block |
||
204 | 208 | protected function prepareForFileExtracting($fileName) |
205 | 209 | { |
206 | 210 | $Location = array_search($fileName, $this->files, true); |
207 | - if (!isset($this->filesData[$fileName])) return false; |
|
211 | + if (!isset($this->filesData[$fileName])) { |
|
212 | + return false; |
|
213 | + } |
|
208 | 214 | $data = $this->filesData[$fileName]; |
209 | 215 | $Location_Real = $Location * $this->blockSize; |
210 | - if ($this->iso->Seek($Location_Real, SEEK_SET) === false) |
|
211 | - return false; |
|
216 | + if ($this->iso->Seek($Location_Real, SEEK_SET) === false) { |
|
217 | + return false; |
|
218 | + } |
|
212 | 219 | return $data; |
213 | 220 | } |
214 | 221 |