mirror of
https://github.com/Ne-Lexa/php-zip.git
synced 2025-07-31 04:30:13 +02:00
Fixed problem with cloning a zip container.
This commit is contained in:
39
tests/Internal/CustomZip/CustomZipWriter.php
Normal file
39
tests/Internal/CustomZip/CustomZipWriter.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Tests\Internal\CustomZip;
|
||||
|
||||
use PhpZip\IO\ZipWriter;
|
||||
use PhpZip\Model\Extra\Fields\NewUnixExtraField;
|
||||
use PhpZip\Model\Extra\Fields\NtfsExtraField;
|
||||
use PhpZip\Model\ZipContainer;
|
||||
|
||||
/**
|
||||
* Class CustomZipWriter.
|
||||
*/
|
||||
class CustomZipWriter extends ZipWriter
|
||||
{
|
||||
/**
|
||||
* ZipWriter constructor.
|
||||
*
|
||||
* @param ZipContainer $container
|
||||
*/
|
||||
public function __construct(ZipContainer $container)
|
||||
{
|
||||
// dump($container);
|
||||
parent::__construct($container);
|
||||
// dd($this->zipContainer);
|
||||
}
|
||||
|
||||
protected function beforeWrite()
|
||||
{
|
||||
parent::beforeWrite();
|
||||
$now = new \DateTimeImmutable();
|
||||
$ntfsTimeExtra = NtfsExtraField::create($now, $now->modify('-1 day'), $now->modify('-10 day'));
|
||||
$unixExtra = new NewUnixExtraField();
|
||||
|
||||
foreach ($this->zipContainer->getEntries() as $entry) {
|
||||
$entry->addExtraField($ntfsTimeExtra);
|
||||
$entry->addExtraField($unixExtra);
|
||||
}
|
||||
}
|
||||
}
|
20
tests/Internal/CustomZip/ZipFileCustomWriter.php
Normal file
20
tests/Internal/CustomZip/ZipFileCustomWriter.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Tests\Internal\CustomZip;
|
||||
|
||||
use PhpZip\IO\ZipWriter;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* Class ZipFileCustomWriter.
|
||||
*/
|
||||
class ZipFileCustomWriter extends ZipFile
|
||||
{
|
||||
/**
|
||||
* @return ZipWriter
|
||||
*/
|
||||
protected function createZipWriter()
|
||||
{
|
||||
return new CustomZipWriter($this->zipContainer);
|
||||
}
|
||||
}
|
28
tests/Internal/CustomZip/ZipFileWithBeforeSave.php
Normal file
28
tests/Internal/CustomZip/ZipFileWithBeforeSave.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Tests\Internal\CustomZip;
|
||||
|
||||
use PhpZip\Model\Extra\Fields\NewUnixExtraField;
|
||||
use PhpZip\Model\Extra\Fields\NtfsExtraField;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* Class ZipFileWithBeforeSave.
|
||||
*/
|
||||
class ZipFileWithBeforeSave extends ZipFile
|
||||
{
|
||||
/**
|
||||
* Event before save or output.
|
||||
*/
|
||||
protected function onBeforeSave()
|
||||
{
|
||||
$now = new \DateTimeImmutable();
|
||||
$ntfsTimeExtra = NtfsExtraField::create($now, $now->modify('-1 day'), $now->modify('-10 day'));
|
||||
$unixExtra = new NewUnixExtraField();
|
||||
|
||||
foreach ($this->zipContainer->getEntries() as $entry) {
|
||||
$entry->addExtraField($ntfsTimeExtra);
|
||||
$entry->addExtraField($unixExtra);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user