]> _ Git - cubist_util.git/commitdiff
wip #4895 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 22 Nov 2021 10:11:54 +0000 (11:11 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 22 Nov 2021 10:11:54 +0000 (11:11 +0100)
src/Files/Files.php
src/Zip.php

index cb4f9f7c7fc4abb9720884a38ad1c15cb487c796..233b62710e4e0147e46720f623e36950c8b4e779 100644 (file)
@@ -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);
index d6eb0d2b7725de8dd58f76cec4c47941103683ec..667fe401d7cd670b9af6f868388d7208fc80d22e 100644 (file)
@@ -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, '*');