1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-08-29 17:59:55 +02:00

Implemented the ability to override the instance of ZipContainer.

ZipContainer will be cloned before writing the zip file.
Tested custom ZipWriter, ZipReader, ZipContainer and ZipFile.
This commit is contained in:
Ne-Lexa
2020-01-21 14:10:47 +03:00
parent e0da8c94be
commit 5ec656fde4
15 changed files with 472 additions and 7 deletions

View File

@@ -39,7 +39,9 @@ class ZipWriter
*/
public function __construct(ZipContainer $container)
{
$this->zipContainer = $container;
// we clone the container so that the changes made to
// it do not affect the data in the ZipFile class
$this->zipContainer = clone $container;
}
/**

View File

@@ -20,6 +20,7 @@ use PhpZip\IO\ZipReader;
use PhpZip\IO\ZipWriter;
use PhpZip\Model\Data\ZipFileData;
use PhpZip\Model\Data\ZipNewData;
use PhpZip\Model\ImmutableZipContainer;
use PhpZip\Model\ZipContainer;
use PhpZip\Model\ZipEntry;
use PhpZip\Model\ZipEntryMatcher;
@@ -68,7 +69,7 @@ class ZipFile implements ZipFileInterface
*/
public function __construct()
{
$this->zipContainer = new ZipContainer();
$this->zipContainer = $this->createZipContainer(null);
}
/**
@@ -90,6 +91,16 @@ class ZipFile implements ZipFileInterface
return new ZipWriter($this->zipContainer);
}
/**
* @param ImmutableZipContainer|null $sourceContainer
*
* @return ZipContainer
*/
protected function createZipContainer(ImmutableZipContainer $sourceContainer = null)
{
return new ZipContainer($sourceContainer);
}
/**
* Open zip archive from file.
*
@@ -151,7 +162,7 @@ class ZipFile implements ZipFileInterface
public function openFromStream($handle, array $options = [])
{
$this->reader = $this->createZipReader($handle, $options);
$this->zipContainer = new ZipContainer($this->reader->read());
$this->zipContainer = $this->createZipContainer($this->reader->read());
return $this;
}
@@ -1769,7 +1780,7 @@ class ZipFile implements ZipFileInterface
if ($this->reader !== null) {
$this->reader->close();
$this->reader = null;
$this->zipContainer = new ZipContainer();
$this->zipContainer = $this->createZipContainer(null);
}
}