mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-19 13:08:40 +00:00
Draft archives
This commit is contained in:
parent
9898c478d2
commit
ac5f327293
|
|
@ -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 <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function pack($sources, string $destination, bool $overwrite = true) : bool
|
||||
public static function pack($sources, string $destination, bool $overwrite = true) : bool;
|
||||
|
||||
/**
|
||||
* Unpack archive.
|
||||
|
|
|
|||
|
|
@ -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 <d.eichhorn@oms.com>
|
||||
* {@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));
|
||||
|
|
|
|||
|
|
@ -1 +1,85 @@
|
|||
<?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;
|
||||
/**
|
||||
* Zip class for handling zip files.
|
||||
*
|
||||
* Providing basic zip support
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Asset
|
||||
* @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
|
||||
*/
|
||||
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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,62 @@
|
|||
<?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;
|
||||
/**
|
||||
* Zip class for handling zip files.
|
||||
*
|
||||
* Providing basic zip support
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Asset
|
||||
* @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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <d.eichhorn@oms.com>
|
||||
* {@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));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user