diff --git a/Utils/IO/Zip/ArchiveInterface.php b/Utils/IO/Zip/ArchiveInterface.php index ac4edbc05..361a14557 100644 --- a/Utils/IO/Zip/ArchiveInterface.php +++ b/Utils/IO/Zip/ArchiveInterface.php @@ -31,7 +31,7 @@ interface ArchiveInterface /** * Create archive. * - * @param string[] $sources Files and directories to compress + * @param string $sources Files and directories to compress * @param string $destination Output destination * @param bool $overwrite Overwrite if destination is existing * @@ -40,7 +40,7 @@ interface ArchiveInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function pack($sources, string $destination, bool $overwrite = true) : bool + public static function pack($sources, string $destination, bool $overwrite = true) : bool; /** * Unpack archive. diff --git a/Utils/IO/Zip/Gz.php b/Utils/IO/Zip/Gz.php index 3be1221de..330e1383f 100644 --- a/Utils/IO/Zip/Gz.php +++ b/Utils/IO/Zip/Gz.php @@ -31,16 +31,7 @@ namespace phpOMS\Utils\IO\Zip; class Gz implements ArchiveInterface { /** - * Create zip. - * - * @param string $sources Files and directories to compress - * @param string $destination Output destination - * @param bool $overwrite Overwrite if destination is existing - * - * @return bool - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public static function pack(string $source, string $destination, bool $overwrite = true) : bool { @@ -63,6 +54,9 @@ class Gz implements ArchiveInterface return gzclose($gz); } + /** + * {@inheritdoc} + */ public static function unpack(string $source, string $destination) : bool { $destination = str_replace('\\', '/', realpath($destination)); diff --git a/Utils/IO/Zip/Tar.php b/Utils/IO/Zip/Tar.php index 8b1378917..69834dc6c 100644 --- a/Utils/IO/Zip/Tar.php +++ b/Utils/IO/Zip/Tar.php @@ -1 +1,85 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace phpOMS\Utils\IO\Zip; +/** + * Zip class for handling zip files. + * + * Providing basic zip support + * + * @category Framework + * @package phpOMS\Asset + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Tar implements ArchiveInterface +{ + /** + * {@inheritdoc} + */ + public static function pack(array $source, string $destination, bool $overwrite = true) : bool + { + $destination = str_replace('\\', '/', realpath($destination)); + if (!$overwrite && file_exists($destination)) { + return false; + } + + foreach ($sources as $source) { + $source = str_replace('\\', '/', realpath($source)); + + if (!file_exists($source)) { + continue; + } + + if (is_dir($source)) { + $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST); + + foreach ($files as $file) { + $file = str_replace('\\', '/', $file); + + /* Ignore . and .. */ + if (in_array(mb_substr($file, mb_strrpos($file, '/') + 1), ['.', '..'])) { + continue; + } + + $file = realpath($file); + + if (is_dir($file)) { + // todo: do work here + } elseif (is_file($file)) { + // todo: do work here + } + } + } elseif (is_file($source)) { + // todo: do work here + } + } + + fwrite($tar, pack('a1024', '')); + } + + /** + * {@inheritdoc} + */ + public static function unpack(string $source, string $destination) : bool + { + + } +} diff --git a/Utils/IO/Zip/TarGz.php b/Utils/IO/Zip/TarGz.php index 8b1378917..81f3e27ae 100644 --- a/Utils/IO/Zip/TarGz.php +++ b/Utils/IO/Zip/TarGz.php @@ -1 +1,62 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace phpOMS\Utils\IO\Zip; +/** + * Zip class for handling zip files. + * + * Providing basic zip support + * + * @category Framework + * @package phpOMS\Asset + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class TarGz implements ArchiveInterface +{ + /** + * {@inheritdoc} + */ + public static function pack(array $source, string $destination, bool $overwrite = true) : bool + { + if(!Tar::pack($source, $destination . '.tmp', $overwrite)) { + return false; + } + $pack = Gz::pack($destination . '.tmp', $destination, $overwrite); + unlink($destination . '.tmp'); + + return $pack; + } + + /** + * {@inheritdoc} + */ + public static function unpack(string $source, string $destination) : bool + { + if(!Gz::unpack($source, $destination . '.tmp')) { + return false; + } + + $unpacked = Tar::unpack($destination . '.tmp', $destination); + unlink($destination . '.tmp'); + + return $unpacked; + } +} diff --git a/Utils/IO/Zip/Zip.php b/Utils/IO/Zip/Zip.php index f13b17fa0..7cb6a7f68 100644 --- a/Utils/IO/Zip/Zip.php +++ b/Utils/IO/Zip/Zip.php @@ -34,16 +34,7 @@ class Zip implements ArchiveInterface { /** - * Create zip. - * - * @param string[] $sources Files and directories to compress - * @param string $destination Output destination - * @param bool $overwrite Overwrite if destination is existing - * - * @return bool - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public static function pack(array $sources, string $destination, bool $overwrite = true) : bool { @@ -92,6 +83,9 @@ class Zip implements ArchiveInterface return $zip->close(); } + /** + * {@inheritdoc} + */ public static function unpack(string $source, string $destination) : bool { $destination = str_replace('\\', '/', realpath($destination));