From 4986a5d64e4ff92dc02eaac1f96cb00aabcb193b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 12 Jul 2017 10:59:36 +0200 Subject: [PATCH] Added unpack function --- Utils/IO/Zip/Zip.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Utils/IO/Zip/Zip.php b/Utils/IO/Zip/Zip.php index c7ee52889..f2588b727 100644 --- a/Utils/IO/Zip/Zip.php +++ b/Utils/IO/Zip/Zip.php @@ -45,7 +45,7 @@ class Zip * @since 1.0.0 * @author Dennis Eichhorn */ - public static function create(array $sources, string $destination, bool $overwrite = true) : bool + public static function pack(array $sources, string $destination, bool $overwrite = true) : bool { $destination = str_replace('\\', '/', realpath($destination)); @@ -91,4 +91,22 @@ class Zip return $zip->close(); } + + public static function unpack(string $source, string $destination) : bool + { + $destination = str_replace('\\', '/', realpath($destination)); + + if (file_exists($destination)) { + return false; + } + + $zip = new \ZipArchive(); + if (!$zip->open($destination)) { + return false; + } + + $zip->extractTo($destination); + + return $zip->close(); + } }