From 43bcc9adf893e3a5033f2ba661625452c528adf3 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 22 Nov 2021 11:11:54 +0100 Subject: [PATCH] wip #4895 @0.5 --- src/Files/Files.php | 13 ++++++++++--- src/Zip.php | 13 +++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Files/Files.php b/src/Files/Files.php index cb4f9f7..233b627 100644 --- a/src/Files/Files.php +++ b/src/Files/Files.php @@ -8,6 +8,12 @@ class Files public static function rmdir($dir) { + if (PHP_OS_FAMILY !== 'Windows') { + `rm -rf $dir`; + if (!file_exists($dir)) { + return; + } + } $files = self::getRecursiveDirectoryIterator($dir, \RecursiveIteratorIterator::CHILD_FIRST); foreach ($files as $file) { @@ -33,11 +39,12 @@ class Files throw new \RuntimeException(sprintf('Directory "%s" was not created. %s', $path, $e->getMessage())); } } - return realpath($path).'/'; + return realpath($path) . '/'; } - public static function emptyDir($path){ - if(file_exists($path)){ + public static function emptyDir($path) + { + if (file_exists($path)) { self::rmdir($path); } return self::mkdir($path); diff --git a/src/Zip.php b/src/Zip.php index d6eb0d2..667fe40 100644 --- a/src/Zip.php +++ b/src/Zip.php @@ -31,16 +31,24 @@ class Zip } /** - * @param $source string + * @param $source string|array * @param $zip string + * @param int $compression * @return CommandLine */ - public static function archive($source, $zip) + public static function archive($source, $zip, $compression = 0) { $zipexe = 'zip'; + if (!is_numeric($compression)) { + $compression = 0; + } + $compression = round($compression); + $compression = max(0, min(9, $compression)); + $cl = new CommandLine($zipexe); if (is_array($source)) { + $cl->setArg($compression); $cl->setArg('j'); $cl->setArg(null, $zip); foreach ($source as $item) { @@ -48,6 +56,7 @@ class Zip } } else if (@is_dir($source)) { $cl->cd($source); + $cl->setArg($compression); $cl->setArg('r'); $cl->setArg(null, $zip); $cl->setArg(null, '*'); -- 2.39.5