diff --git a/Uri/Http.php b/Uri/Http.php index b8755bb94..5d8de7bbf 100644 --- a/Uri/Http.php +++ b/Uri/Http.php @@ -262,6 +262,11 @@ class Http implements UriInterface { return $this->path; } + + public function getPathOffset() : int + { + return substr_count($this->rootPath, '/') - 1; + } /** * {@inheritdoc} diff --git a/Utils/IO/Zip/ArchiveInterface.php b/Utils/IO/Zip/ArchiveInterface.php new file mode 100644 index 000000000..ebfdc544a --- /dev/null +++ b/Utils/IO/Zip/ArchiveInterface.php @@ -0,0 +1,57 @@ + + * @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; +/** + * Archive interface + * + * @category Framework + * @package phpOMS\Utils\IO + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +interface ArchiveInterface +{ + /** + * Create archive. + * + * @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 + */ + public static function pack(array $sources, string $destination, bool $overwrite = true) : bool + + /** + * Unpack archive. + * + * @param string $source File to decompress + * @param string $destination Output destination + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function unpack(string $source, string $destination) : bool; +} diff --git a/Utils/IO/Zip/Gz.php b/Utils/IO/Zip/Gz.php new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Utils/IO/Zip/Gz.php @@ -0,0 +1 @@ + diff --git a/Utils/IO/Zip/Tar.php b/Utils/IO/Zip/Tar.php new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Utils/IO/Zip/Tar.php @@ -0,0 +1 @@ + diff --git a/Utils/IO/Zip/TarGz.php b/Utils/IO/Zip/TarGz.php new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Utils/IO/Zip/TarGz.php @@ -0,0 +1 @@ + diff --git a/Utils/IO/Zip/Zip.php b/Utils/IO/Zip/Zip.php index c7ee52889..f13b17fa0 100644 --- a/Utils/IO/Zip/Zip.php +++ b/Utils/IO/Zip/Zip.php @@ -30,7 +30,7 @@ namespace phpOMS\Utils\IO\Zip; * @link http://orange-management.com * @since 1.0.0 */ -class Zip +class Zip implements ArchiveInterface { /** @@ -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(); + } }