-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathStubZipArchiveProvider.php
43 lines (32 loc) · 1 KB
/
StubZipArchiveProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
declare(strict_types=1);
namespace League\Flysystem\ZipArchive;
use ZipArchive;
class StubZipArchiveProvider implements ZipArchiveProvider
{
private FilesystemZipArchiveProvider $provider;
/**
* @var StubZipArchive
*/
private $archive;
public function __construct(private string $filename, int $localDirectoryPermissions = 0700)
{
$this->provider = new FilesystemZipArchiveProvider($filename, $localDirectoryPermissions);
}
public function createZipArchive(): ZipArchive
{
if ( ! $this->archive instanceof StubZipArchive) {
$zipArchive = $this->provider->createZipArchive();
$zipArchive->close();
unset($zipArchive);
$this->archive = new StubZipArchive();
}
$this->archive->open($this->filename, ZipArchive::CREATE);
return $this->archive;
}
public function stubbedZipArchive(): StubZipArchive
{
$this->createZipArchive();
return $this->archive;
}
}