1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Filesystem; |
6
|
|
|
|
7
|
|
|
use League\Flysystem\DirectoryListing; |
8
|
|
|
use League\Flysystem\Filesystem as LeagueFilesystem; |
9
|
|
|
use League\Flysystem\FilesystemAdapter; |
10
|
|
|
use League\Flysystem\PathNormalizer; |
11
|
|
|
use Yiisoft\Aliases\Aliases; |
12
|
|
|
|
13
|
|
|
final class Filesystem extends LeagueFilesystem implements FilesystemInterface |
14
|
|
|
{ |
15
|
|
|
private Aliases $aliases; |
16
|
|
|
|
17
|
|
|
public function __construct( |
18
|
|
|
FilesystemAdapter $adapter, |
19
|
|
|
array $aliases = [], |
20
|
|
|
array $config = [], |
21
|
|
|
PathNormalizer $pathNormalizer = null |
22
|
|
|
) { |
23
|
|
|
$this->prepareAliases($aliases); |
24
|
|
|
|
25
|
|
|
parent::__construct($adapter, $config, $pathNormalizer); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function fileExists(string $location): bool |
29
|
|
|
{ |
30
|
|
|
$location = $this->aliases->get($location); |
31
|
|
|
return parent::fileExists($location); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function write(string $location, string $contents, array $config = []): void |
35
|
|
|
{ |
36
|
|
|
$location = $this->aliases->get($location); |
37
|
|
|
parent::write($location, $contents, $config); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function writeStream(string $location, $contents, array $config = []): void |
41
|
|
|
{ |
42
|
|
|
$location = $this->aliases->get($location); |
43
|
|
|
parent::writeStream($location, $contents, $config); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function read(string $location): string |
47
|
|
|
{ |
48
|
|
|
$location = $this->aliases->get($location); |
49
|
|
|
return parent::read($location); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function readStream(string $location) |
53
|
|
|
{ |
54
|
|
|
$location = $this->aliases->get($location); |
55
|
|
|
return parent::readStream($location); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function delete(string $location): void |
59
|
|
|
{ |
60
|
|
|
$location = $this->aliases->get($location); |
61
|
|
|
parent::delete($location); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function createDirectory(string $location, array $config = []): void |
65
|
|
|
{ |
66
|
|
|
$location = $this->aliases->get($location); |
67
|
|
|
parent::createDirectory($location, $config); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function deleteDirectory(string $location): void |
71
|
|
|
{ |
72
|
|
|
$location = $this->aliases->get($location); |
73
|
|
|
parent::deleteDirectory($location); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function copy(string $source, string $destination, array $config = []): void |
77
|
|
|
{ |
78
|
|
|
$source = $this->aliases->get($source); |
79
|
|
|
$destination = $this->aliases->get($destination); |
80
|
|
|
parent::copy($source, $destination, $config); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function move(string $source, string $destination, array $config = []): void |
84
|
|
|
{ |
85
|
|
|
$source = $this->aliases->get($source); |
86
|
|
|
$destination = $this->aliases->get($destination); |
87
|
|
|
parent::move($source, $destination, $config); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function setVisibility(string $path, string $visibility): void |
91
|
|
|
{ |
92
|
|
|
$path = $this->aliases->get($path); |
93
|
|
|
parent::setVisibility($path, $visibility); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function visibility(string $path): string |
97
|
|
|
{ |
98
|
|
|
$path = $this->aliases->get($path); |
99
|
|
|
return parent::visibility($path); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function mimeType(string $path): string |
103
|
|
|
{ |
104
|
|
|
$path = $this->aliases->get($path); |
105
|
|
|
return parent::mimeType($path); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function lastModified(string $path): int |
109
|
|
|
{ |
110
|
|
|
$path = $this->aliases->get($path); |
111
|
|
|
return parent::lastModified($path); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function listContents(string $location, bool $deep = LeagueFilesystem::LIST_SHALLOW): DirectoryListing |
115
|
|
|
{ |
116
|
|
|
$location = $this->aliases->get($location); |
117
|
|
|
return parent::listContents($location, $deep); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function fileSize(string $path): int |
121
|
|
|
{ |
122
|
|
|
$path = $this->aliases->get($path); |
123
|
|
|
return parent::fileSize($path); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
private function prepareAliases(array $aliases): void |
127
|
|
|
{ |
128
|
|
|
if ($aliases !== []) { |
129
|
|
|
$aliases = array_merge(['@root' => ''], $aliases); |
130
|
|
|
$aliases['@root'] = ''; |
131
|
|
|
} |
132
|
|
|
$this->aliases = new Aliases($aliases); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|