1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace diecoding\flysystem\adapter; |
6
|
|
|
|
7
|
|
|
use diecoding\flysystem\traits\ChecksumAdapterTrait; |
8
|
|
|
use diecoding\flysystem\traits\UrlGeneratorAdapterTrait; |
9
|
|
|
use League\Flysystem\ChecksumProvider; |
10
|
|
|
use League\Flysystem\Config; |
11
|
|
|
use League\Flysystem\FileAttributes; |
12
|
|
|
use League\Flysystem\FilesystemAdapter; |
13
|
|
|
use League\Flysystem\UnixVisibility\VisibilityConverter; |
14
|
|
|
use League\Flysystem\UrlGeneration\PublicUrlGenerator; |
15
|
|
|
use League\Flysystem\UrlGeneration\TemporaryUrlGenerator; |
16
|
|
|
use League\Flysystem\ZipArchive\ZipArchiveAdapter as LeagueZipArchiveAdapter; |
17
|
|
|
use League\Flysystem\ZipArchive\ZipArchiveProvider; |
18
|
|
|
use League\MimeTypeDetection\MimeTypeDetector; |
19
|
|
|
|
20
|
|
|
final class ZipArchiveAdapter implements FilesystemAdapter, ChecksumProvider, PublicUrlGenerator, TemporaryUrlGenerator |
21
|
|
|
{ |
22
|
|
|
use UrlGeneratorAdapterTrait, ChecksumAdapterTrait; |
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
protected $skipPrefixer = true; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var LeagueZipArchiveAdapter |
31
|
|
|
*/ |
32
|
|
|
private $_adapter; |
33
|
|
|
|
34
|
|
|
public function __construct( |
35
|
|
|
private ZipArchiveProvider $zipArchiveProvider, |
36
|
|
|
string $root = '', |
37
|
|
|
?MimeTypeDetector $mimeTypeDetector = null, |
38
|
|
|
?VisibilityConverter $visibility = null, |
39
|
|
|
private bool $detectMimeTypeUsingPath = false, |
40
|
|
|
) { |
41
|
|
|
$this->setAdapter(new LeagueZipArchiveAdapter($zipArchiveProvider, $root, $mimeTypeDetector, $visibility, $detectMimeTypeUsingPath)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return LeagueZipArchiveAdapter |
46
|
|
|
*/ |
47
|
|
|
public function getAdapter() |
48
|
|
|
{ |
49
|
|
|
return $this->_adapter; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param LeagueZipArchiveAdapter $value |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
public function setAdapter(LeagueZipArchiveAdapter $value) |
57
|
|
|
{ |
58
|
|
|
$this->_adapter = $value; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function fileExists(string $path): bool |
62
|
|
|
{ |
63
|
|
|
return $this->getAdapter()->fileExists($path); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function write(string $path, string $contents, Config $config): void |
67
|
|
|
{ |
68
|
|
|
$this->getAdapter()->write($path, $contents, $config); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function writeStream(string $path, $contents, Config $config): void |
72
|
|
|
{ |
73
|
|
|
$this->getAdapter()->writeStream($path, $contents, $config); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function read(string $path): string |
77
|
|
|
{ |
78
|
|
|
return $this->getAdapter()->read($path); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function readStream(string $path) |
82
|
|
|
{ |
83
|
|
|
return $this->getAdapter()->readStream($path); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function delete(string $path): void |
87
|
|
|
{ |
88
|
|
|
$this->getAdapter()->delete($path); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function deleteDirectory(string $path): void |
92
|
|
|
{ |
93
|
|
|
$this->getAdapter()->deleteDirectory($path); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function createDirectory(string $path, Config $config): void |
97
|
|
|
{ |
98
|
|
|
$this->getAdapter()->createDirectory($path, $config); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function directoryExists(string $path): bool |
102
|
|
|
{ |
103
|
|
|
return $this->getAdapter()->directoryExists($path); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function setVisibility(string $path, string $visibility): void |
107
|
|
|
{ |
108
|
|
|
$this->getAdapter()->setVisibility($path, $visibility); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function visibility(string $path): FileAttributes |
112
|
|
|
{ |
113
|
|
|
return $this->getAdapter()->visibility($path); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function mimeType(string $path): FileAttributes |
117
|
|
|
{ |
118
|
|
|
return $this->getAdapter()->mimeType($path); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function lastModified(string $path): FileAttributes |
122
|
|
|
{ |
123
|
|
|
return $this->getAdapter()->lastModified($path); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function fileSize(string $path): FileAttributes |
127
|
|
|
{ |
128
|
|
|
return $this->getAdapter()->fileSize($path); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function listContents(string $path, bool $deep): iterable |
132
|
|
|
{ |
133
|
|
|
return $this->getAdapter()->listContents($path, $deep); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function move(string $source, string $destination, Config $config): void |
137
|
|
|
{ |
138
|
|
|
$this->getAdapter()->move($source, $destination, $config); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function copy(string $source, string $destination, Config $config): void |
142
|
|
|
{ |
143
|
|
|
$this->getAdapter()->copy($source, $destination, $config); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|