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