Merge pull request #112 from Orange-Management/master

Rebase
This commit is contained in:
Dennis Eichhorn 2017-07-12 11:47:06 +02:00 committed by GitHub
commit b74f0b18f6
6 changed files with 85 additions and 2 deletions

View File

@ -262,6 +262,11 @@ class Http implements UriInterface
{
return $this->path;
}
public function getPathOffset() : int
{
return substr_count($this->rootPath, '/') - 1;
}
/**
* {@inheritdoc}

View File

@ -0,0 +1,57 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
public static function unpack(string $source, string $destination) : bool;
}

1
Utils/IO/Zip/Gz.php Normal file
View File

@ -0,0 +1 @@

1
Utils/IO/Zip/Tar.php Normal file
View File

@ -0,0 +1 @@

1
Utils/IO/Zip/TarGz.php Normal file
View File

@ -0,0 +1 @@

View File

@ -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 <d.eichhorn@oms.com>
*/
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();
}
}