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