Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
InMemoryFilesystemAdapter | |
0.00% |
0 / 15 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
visibility | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
lastModified | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
copy | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
write | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
createDirectories | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace BrianHenryIE\Strauss\Helpers; |
4 | |
5 | use League\Flysystem\Config; |
6 | use League\Flysystem\FileAttributes; |
7 | use League\Flysystem\InMemory\InMemoryFilesystemAdapter as LeagueInMemoryFilesystemAdapter; |
8 | |
9 | class InMemoryFilesystemAdapter extends LeagueInMemoryFilesystemAdapter |
10 | { |
11 | |
12 | public function visibility(string $path): FileAttributes |
13 | { |
14 | if (!$this->fileExists($path)) { |
15 | // Assume it is a directory. |
16 | |
17 | // Maybe check does the directory exist. |
18 | // $parentDirContents = (array) $this->listContents(dirname($path), false); |
19 | // throw UnableToRetrieveMetadata::visibility($path, 'file does not exist'); |
20 | |
21 | return new FileAttributes($path, null, 'public'); |
22 | } |
23 | |
24 | |
25 | return parent::visibility($path); |
26 | } |
27 | |
28 | public function lastModified(string $path): FileAttributes |
29 | { |
30 | if (!$this->fileExists($path)) { |
31 | // Assume it is a directory |
32 | return new FileAttributes($path, null, null, 0); |
33 | } |
34 | |
35 | return parent::lastModified($path); |
36 | } |
37 | |
38 | public function copy(string $source, string $destination, Config $config): void |
39 | { |
40 | $this->createDirectories($destination, $config); |
41 | |
42 | parent::copy($source, $destination, $config); |
43 | } |
44 | |
45 | public function write(string $path, string $contents, Config $config): void |
46 | { |
47 | // Make sure there is a directory for the file to be written to. |
48 | if (false === strpos($path, '______DUMMY_FILE_FOR_FORCED_LISTING_IN_FLYSYSTEM_TEST')) { |
49 | $this->createDirectories($path, $config); |
50 | } |
51 | |
52 | parent::write($path, $contents, $config); |
53 | } |
54 | |
55 | protected function createDirectories(string $path, Config $config): void |
56 | { |
57 | $pathDirs = explode('/', dirname($path)); |
58 | for ($level = 0; $level < count($pathDirs); $level++) { |
59 | $dir = implode('/', array_slice($pathDirs, 0, $level + 1)); |
60 | $this->createDirectory($dir, $config); |
61 | } |
62 | } |
63 | } |