1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_files\Processing\Volume; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use DateTimeInterface; |
7
|
|
|
use kalanis\kw_files\Interfaces\IFLTranslations; |
8
|
|
|
use kalanis\kw_files\Interfaces\IProcessNodes; |
9
|
|
|
use kalanis\kw_files\Processing\TPath; |
10
|
|
|
use kalanis\kw_files\Traits\TLang; |
11
|
|
|
use kalanis\kw_paths\Extras\TPathTransform; |
12
|
|
|
use kalanis\kw_paths\PathsException; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class ProcessNode |
17
|
|
|
* @package kalanis\kw_files\Processing\Volume |
18
|
|
|
* Process nodes in basic ways |
19
|
|
|
*/ |
20
|
|
|
class ProcessNode implements IProcessNodes |
21
|
|
|
{ |
22
|
|
|
use TLang; |
23
|
|
|
use TPath; |
24
|
|
|
use TPathTransform; |
25
|
|
|
|
26
|
5 |
|
public function __construct(string $path = '', ?IFLTranslations $lang = null) |
27
|
|
|
{ |
28
|
5 |
|
$this->setPath($path); |
29
|
5 |
|
$this->setFlLang($lang); |
30
|
|
|
} |
31
|
|
|
|
32
|
1 |
|
public function exists(array $entry): bool |
33
|
|
|
{ |
34
|
1 |
|
return @file_exists($this->fullPath($entry)); |
35
|
|
|
} |
36
|
|
|
|
37
|
1 |
|
public function isReadable(array $entry): bool |
38
|
|
|
{ |
39
|
1 |
|
return @is_readable($this->fullPath($entry)); |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
public function isWritable(array $entry): bool |
43
|
|
|
{ |
44
|
1 |
|
return @is_writable($this->fullPath($entry)); |
45
|
|
|
} |
46
|
|
|
|
47
|
1 |
|
public function isDir(array $entry): bool |
48
|
|
|
{ |
49
|
1 |
|
return @is_dir($this->fullPath($entry)); |
50
|
|
|
} |
51
|
|
|
|
52
|
1 |
|
public function isFile(array $entry): bool |
53
|
|
|
{ |
54
|
1 |
|
return @is_file($this->fullPath($entry)); |
55
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
public function size(array $entry): ?int |
58
|
|
|
{ |
59
|
1 |
|
$path = $this->fullPath($entry); |
60
|
1 |
|
$size = @filesize($path); |
61
|
1 |
|
return (false === $size) ? null : $size; |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
public function created(array $entry): ?DateTimeInterface |
65
|
|
|
{ |
66
|
1 |
|
$path = $this->fullPath($entry); |
67
|
1 |
|
$created = @filemtime($path); |
68
|
1 |
|
$dateObj = (false === $created) ? false : date_create_immutable('@' . $created); |
69
|
1 |
|
return (false === $dateObj) ? null : $dateObj; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param array<string> $path |
74
|
|
|
* @throws PathsException |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
1 |
|
protected function fullPath(array $path): string |
78
|
|
|
{ |
79
|
1 |
|
return $this->getPath() . DIRECTORY_SEPARATOR . $this->compactName($path); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string |
84
|
|
|
* @codeCoverageIgnore only when path fails |
85
|
|
|
*/ |
86
|
|
|
protected function noDirectoryDelimiterSet(): string |
87
|
|
|
{ |
88
|
|
|
return $this->getFlLang()->flNoDirectoryDelimiterSet(); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|