1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_images\Sources; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_files\FilesException; |
7
|
|
|
use kalanis\kw_files\Traits\TToString; |
8
|
|
|
use kalanis\kw_paths\PathsException; |
9
|
|
|
use kalanis\kw_paths\Stuff; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Desc |
14
|
|
|
* Content description |
15
|
|
|
* @package kalanis\kw_images\Sources |
16
|
|
|
*/ |
17
|
|
|
class Desc extends AFiles |
18
|
|
|
{ |
19
|
|
|
use TToString; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param string[] $path |
23
|
|
|
* @param bool $errorOnFail |
24
|
|
|
* @throws FilesException |
25
|
|
|
* @throws PathsException |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
2 |
|
public function get(array $path, bool $errorOnFail = false): string |
29
|
|
|
{ |
30
|
|
|
try { |
31
|
2 |
|
return $this->toString(Stuff::arrayToPath($path), $this->lib->readFile($this->getPath($path))); |
32
|
2 |
|
} catch (FilesException $ex) { |
33
|
2 |
|
if (!$errorOnFail) { |
34
|
2 |
|
return ''; |
35
|
|
|
} |
36
|
1 |
|
throw $ex; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string[] $path |
42
|
|
|
* @param string $content |
43
|
|
|
* @throws FilesException |
44
|
|
|
* @throws PathsException |
45
|
|
|
* @return bool |
46
|
|
|
*/ |
47
|
13 |
|
public function set(array $path, string $content): bool |
48
|
|
|
{ |
49
|
13 |
|
return $this->lib->saveFile($this->getPath($path), $content); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $fileName |
54
|
|
|
* @param string[] $sourceDir |
55
|
|
|
* @param string[] $targetDir |
56
|
|
|
* @param bool $overwrite |
57
|
|
|
* @throws FilesException |
58
|
|
|
* @throws PathsException |
59
|
|
|
* @return bool |
60
|
|
|
*/ |
61
|
2 |
|
public function copy(string $fileName, array $sourceDir, array $targetDir, bool $overwrite = false): bool |
62
|
|
|
{ |
63
|
2 |
|
return $this->dataCopy( |
64
|
2 |
|
array_merge($sourceDir, [$this->config->getDescDir(), $fileName . $this->config->getDescExt()]), |
65
|
2 |
|
array_merge($targetDir, [$this->config->getDescDir(), $fileName . $this->config->getDescExt()]), |
66
|
2 |
|
$overwrite, |
67
|
2 |
|
$this->getImLang()->imDescCannotFind(), |
68
|
2 |
|
$this->getImLang()->imDescAlreadyExistsHere(), |
69
|
2 |
|
$this->getImLang()->imDescCannotRemoveOld(), |
70
|
2 |
|
$this->getImLang()->imDescCannotCopyBase() |
71
|
2 |
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $fileName |
76
|
|
|
* @param string[] $sourceDir |
77
|
|
|
* @param string[] $targetDir |
78
|
|
|
* @param bool $overwrite |
79
|
|
|
* @throws FilesException |
80
|
|
|
* @throws PathsException |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
2 |
|
public function move(string $fileName, array $sourceDir, array $targetDir, bool $overwrite = false): bool |
84
|
|
|
{ |
85
|
2 |
|
return $this->dataRename( |
86
|
2 |
|
array_merge($sourceDir, [$this->config->getDescDir(), $fileName . $this->config->getDescExt()]), |
87
|
2 |
|
array_merge($targetDir, [$this->config->getDescDir(), $fileName . $this->config->getDescExt()]), |
88
|
2 |
|
$overwrite, |
89
|
2 |
|
$this->getImLang()->imDescCannotFind(), |
90
|
2 |
|
$this->getImLang()->imDescAlreadyExistsHere(), |
91
|
2 |
|
$this->getImLang()->imDescCannotRemoveOld(), |
92
|
2 |
|
$this->getImLang()->imDescCannotMoveBase() |
93
|
2 |
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string[] $path |
98
|
|
|
* @param string $sourceName |
99
|
|
|
* @param string $targetName |
100
|
|
|
* @param bool $overwrite |
101
|
|
|
* @throws FilesException |
102
|
|
|
* @throws PathsException |
103
|
|
|
* @return bool |
104
|
|
|
*/ |
105
|
2 |
|
public function rename(array $path, string $sourceName, string $targetName, bool $overwrite = false): bool |
106
|
|
|
{ |
107
|
2 |
|
return $this->dataRename( |
108
|
2 |
|
array_merge($path, [$this->config->getDescDir(), $sourceName . $this->config->getDescExt()]), |
109
|
2 |
|
array_merge($path, [$this->config->getDescDir(), $targetName . $this->config->getDescExt()]), |
110
|
2 |
|
$overwrite, |
111
|
2 |
|
$this->getImLang()->imDescCannotFind(), |
112
|
2 |
|
$this->getImLang()->imDescAlreadyExistsHere(), |
113
|
2 |
|
$this->getImLang()->imDescCannotRemoveOld(), |
114
|
2 |
|
$this->getImLang()->imDescCannotRenameBase() |
115
|
2 |
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param string[] $sourceDir |
120
|
|
|
* @param string $fileName |
121
|
|
|
* @throws FilesException |
122
|
|
|
* @throws PathsException |
123
|
|
|
* @return bool |
124
|
|
|
*/ |
125
|
3 |
|
public function delete(array $sourceDir, string $fileName): bool |
126
|
|
|
{ |
127
|
3 |
|
return $this->dataRemove( |
128
|
3 |
|
array_merge($sourceDir, [$this->config->getDescDir(), $fileName . $this->config->getDescExt()]), |
129
|
3 |
|
$this->getImLang()->imDescCannotRemove() |
130
|
3 |
|
); |
131
|
|
|
} |
132
|
|
|
|
133
|
13 |
|
public function getPath(array $path): array |
134
|
|
|
{ |
135
|
13 |
|
$fileName = array_pop($path); |
136
|
13 |
|
return array_merge($path, [$this->config->getDescDir(), $fileName . $this->config->getDescExt()]); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|