From f4a8cf761353e3ee934fbeccb09db73807f3c1c5 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 31 May 2017 10:46:00 +0200 Subject: [PATCH 1/7] Added path offset calculation --- Uri/Http.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Uri/Http.php b/Uri/Http.php index b6362eb4e..2530fb28a 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} From 4986a5d64e4ff92dc02eaac1f96cb00aabcb193b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 12 Jul 2017 10:59:36 +0200 Subject: [PATCH 2/7] 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(); + } } From 4d8a7c1969e1096058e323729fad52ad66385204 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 12 Jul 2017 11:36:40 +0200 Subject: [PATCH 3/7] Create Tar.php --- Utils/IO/Zip/Tar.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 Utils/IO/Zip/Tar.php 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 @@ + From a53ec6ded55de1bd8a260a6d5f9dfde43b4a624a Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 12 Jul 2017 11:37:21 +0200 Subject: [PATCH 4/7] Create TarGz.php --- Utils/IO/Zip/TarGz.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 Utils/IO/Zip/TarGz.php 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 @@ + From eb99aeb2401175bd115962b17e6fd0baea422fc0 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 12 Jul 2017 11:38:34 +0200 Subject: [PATCH 5/7] Create Gz.php --- Utils/IO/Zip/Gz.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 Utils/IO/Zip/Gz.php 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 @@ + From c082826d32c04302edde80f2af0214891c01e1de Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 12 Jul 2017 11:42:41 +0200 Subject: [PATCH 6/7] Create ArchiveInterface.php --- Utils/IO/Zip/ArchiveInterface.php | 57 +++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Utils/IO/Zip/ArchiveInterface.php 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; +} From 32184be8d81ffd3d80c83e188938421341833b95 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 12 Jul 2017 11:43:16 +0200 Subject: [PATCH 7/7] Implement interface --- Utils/IO/Zip/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Utils/IO/Zip/Zip.php b/Utils/IO/Zip/Zip.php index f2588b727..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 { /**