mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-13 10:38:40 +00:00
86 lines
2.1 KiB
PHP
86 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* Orange Management
|
|
*
|
|
* PHP Version 7.2
|
|
*
|
|
* @package TBD
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 1.0
|
|
* @version 1.0.0
|
|
* @link http://website.orange-management.de
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace phpOMS\Utils\IO\Zip;
|
|
|
|
/**
|
|
* Zip class for handling zip files.
|
|
*
|
|
* Providing basic zip support
|
|
*
|
|
* @package Framework
|
|
* @license OMS License 1.0
|
|
* @link http://website.orange-management.de
|
|
* @since 1.0.0
|
|
*/
|
|
class Tar implements ArchiveInterface
|
|
{
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public static function pack($sources, string $destination, bool $overwrite = true) : bool
|
|
{
|
|
$destination = str_replace('\\', '/', realpath($destination));
|
|
|
|
if (!$overwrite && file_exists($destination)) {
|
|
return false;
|
|
}
|
|
|
|
/** @var array $sources */
|
|
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
|
|
{
|
|
|
|
}
|
|
}
|