|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kalanis\kw_files\Processing\Storage\Nodes; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use DateTimeInterface; |
|
7
|
|
|
use kalanis\kw_files\FilesException; |
|
8
|
|
|
use kalanis\kw_files\Interfaces\IFLTranslations; |
|
9
|
|
|
use kalanis\kw_files\Traits\TToString; |
|
10
|
|
|
use kalanis\kw_storage\Interfaces\IStorage; |
|
11
|
|
|
use kalanis\kw_storage\StorageException; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class Basic |
|
16
|
|
|
* @package kalanis\kw_files\Processing\Storage\Nodes |
|
17
|
|
|
* Process dirs via lookup |
|
18
|
|
|
*/ |
|
19
|
|
|
class Basic extends ANodes |
|
20
|
|
|
{ |
|
21
|
|
|
use TToString; |
|
22
|
|
|
|
|
23
|
|
|
protected IStorage $storage; |
|
24
|
|
|
|
|
25
|
13 |
|
public function __construct(IStorage $storage, ?IFLTranslations $lang = null) |
|
26
|
|
|
{ |
|
27
|
13 |
|
$this->storage = $storage; |
|
28
|
13 |
|
$this->setFlLang($lang); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
8 |
|
public function exists(array $entry): bool |
|
32
|
|
|
{ |
|
33
|
8 |
|
$path = $this->compactName($entry, $this->getStorageSeparator()); |
|
34
|
8 |
|
$path = empty($entry) ? $path : $this->getStorageSeparator() . $path; |
|
35
|
|
|
try { |
|
36
|
8 |
|
return $this->storage->exists($path); |
|
37
|
1 |
|
} catch (StorageException $ex) { |
|
38
|
1 |
|
throw new FilesException($this->getFlLang()->flCannotProcessNode($path), $ex->getCode(), $ex); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
public function isReadable(array $entry): bool |
|
43
|
|
|
{ |
|
44
|
1 |
|
return true; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
1 |
|
public function isWritable(array $entry): bool |
|
48
|
|
|
{ |
|
49
|
1 |
|
return true; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
8 |
|
public function isDir(array $entry): bool |
|
53
|
|
|
{ |
|
54
|
8 |
|
$path = $this->compactName($entry, $this->getStorageSeparator()); |
|
55
|
8 |
|
$path = empty($entry) ? $path : $this->getStorageSeparator() . $path; |
|
56
|
|
|
try { |
|
57
|
8 |
|
return $this->storage->exists($path) && static::STORAGE_NODE_KEY === $this->toString($path, $this->storage->read($path)); |
|
58
|
1 |
|
} catch (StorageException $ex) { |
|
59
|
1 |
|
throw new FilesException($this->getFlLang()->flCannotProcessNode($path), $ex->getCode(), $ex); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
4 |
|
public function isFile(array $entry): bool |
|
64
|
|
|
{ |
|
65
|
4 |
|
$path = $this->compactName($entry, $this->getStorageSeparator()); |
|
66
|
4 |
|
$path = empty($entry) ? $path : $this->getStorageSeparator() . $path; |
|
67
|
|
|
try { |
|
68
|
4 |
|
return $this->storage->exists($path) && static::STORAGE_NODE_KEY !== $this->toString($path, $this->storage->read($path)); |
|
69
|
1 |
|
} catch (StorageException $ex) { |
|
70
|
1 |
|
throw new FilesException($this->getFlLang()->flCannotProcessNode($path), $ex->getCode(), $ex); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
3 |
|
public function size(array $entry): ?int |
|
75
|
|
|
{ |
|
76
|
3 |
|
$path = $this->getStorageSeparator() . $this->compactName($entry, $this->getStorageSeparator()); |
|
77
|
|
|
try { |
|
78
|
3 |
|
if (!$this->storage->exists($path)) { |
|
79
|
2 |
|
return null; |
|
80
|
|
|
} |
|
81
|
1 |
|
return strlen($this->storage->read($path)); |
|
82
|
1 |
|
} catch (StorageException $ex) { |
|
83
|
1 |
|
throw new FilesException($this->getFlLang()->flCannotProcessNode($path), $ex->getCode(), $ex); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
2 |
|
public function created(array $entry): ?DateTimeInterface |
|
88
|
|
|
{ |
|
89
|
2 |
|
return null; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return string |
|
94
|
|
|
* @codeCoverageIgnore only when path fails |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function noDirectoryDelimiterSet(): string |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->getFlLang()->flNoDirectoryDelimiterSet(); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|