2026-06-04 20:40:07 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @package MokoJoomBackup
|
2026-06-06 14:52:27 -05:00
|
|
|
* @subpackage com_mokojoombackup
|
2026-06-04 20:40:07 -05:00
|
|
|
* @author Moko Consulting <hello@mokoconsulting.tech>
|
|
|
|
|
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
|
|
|
|
* @license GNU General Public License version 3 or later; see LICENSE
|
|
|
|
|
*/
|
|
|
|
|
|
2026-06-06 14:52:27 -05:00
|
|
|
namespace Joomla\Component\MokoJoomBackup\Administrator\Engine;
|
2026-06-04 20:40:07 -05:00
|
|
|
|
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
|
|
|
|
|
|
class ZipArchiver implements ArchiverInterface
|
|
|
|
|
{
|
|
|
|
|
private \ZipArchive $zip;
|
|
|
|
|
|
|
|
|
|
public function open(string $path): void
|
|
|
|
|
{
|
|
|
|
|
$this->zip = new \ZipArchive();
|
|
|
|
|
|
|
|
|
|
if ($this->zip->open($path, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) !== true) {
|
|
|
|
|
throw new \RuntimeException('Cannot create ZIP archive: ' . $path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addFromString(string $localName, string $contents): void
|
|
|
|
|
{
|
|
|
|
|
$this->zip->addFromString($localName, $contents);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addFile(string $filePath, string $localName): void
|
|
|
|
|
{
|
|
|
|
|
$this->zip->addFile($filePath, $localName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function close(): void
|
|
|
|
|
{
|
|
|
|
|
$this->zip->close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getExtension(): string
|
|
|
|
|
{
|
|
|
|
|
return 'zip';
|
|
|
|
|
}
|
|
|
|
|
}
|