|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kalanis\kw_images\Sources; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use DateTimeInterface; |
|
7
|
|
|
use kalanis\kw_files\Extended\FindFreeName; |
|
8
|
|
|
use kalanis\kw_files\FilesException; |
|
9
|
|
|
use kalanis\kw_files\Traits\TToString; |
|
10
|
|
|
use kalanis\kw_paths\PathsException; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class Image |
|
15
|
|
|
* Main image itself |
|
16
|
|
|
* @package kalanis\kw_images\Sources |
|
17
|
|
|
*/ |
|
18
|
|
|
class Image extends AFiles |
|
19
|
|
|
{ |
|
20
|
|
|
use TToString; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param string[] $path |
|
24
|
|
|
* @param string $fileName |
|
25
|
|
|
* @param string $ext |
|
26
|
|
|
* @throws FilesException |
|
27
|
|
|
* @throws PathsException |
|
28
|
|
|
* @return string |
|
29
|
|
|
*/ |
|
30
|
2 |
|
public function findFreeName(array $path, string $fileName, string $ext): string |
|
31
|
|
|
{ |
|
32
|
2 |
|
$libFinder = new FindFreeName($this->lib->getNode()); |
|
33
|
2 |
|
return $libFinder->findFreeName($path, $fileName, $ext); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string[] $path |
|
38
|
|
|
* @throws FilesException |
|
39
|
|
|
* @throws PathsException |
|
40
|
|
|
* @return DateTimeInterface|null |
|
41
|
|
|
*/ |
|
42
|
2 |
|
public function getCreated(array $path): ?DateTimeInterface |
|
43
|
|
|
{ |
|
44
|
2 |
|
return $this->lib->created($this->getPath($path)); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param string[] $path |
|
49
|
|
|
* @throws FilesException |
|
50
|
|
|
* @throws PathsException |
|
51
|
|
|
* @return string|resource |
|
52
|
|
|
*/ |
|
53
|
17 |
|
public function get(array $path) |
|
54
|
|
|
{ |
|
55
|
17 |
|
return $this->lib->readFile($this->getPath($path)); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param string[] $path |
|
60
|
|
|
* @param string|resource $content |
|
61
|
|
|
* @throws FilesException |
|
62
|
|
|
* @throws PathsException |
|
63
|
|
|
* @return bool |
|
64
|
|
|
*/ |
|
65
|
24 |
|
public function set(array $path, $content): bool |
|
66
|
|
|
{ |
|
67
|
24 |
|
return $this->lib->saveFile($this->getPath($path), $this->toString(implode(DIRECTORY_SEPARATOR, $path), $content)); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param string $fileName |
|
72
|
|
|
* @param string[] $sourceDir |
|
73
|
|
|
* @param string[] $targetDir |
|
74
|
|
|
* @param bool $overwrite |
|
75
|
|
|
* @throws FilesException |
|
76
|
|
|
* @throws PathsException |
|
77
|
|
|
* @return bool |
|
78
|
|
|
*/ |
|
79
|
4 |
|
public function copy(string $fileName, array $sourceDir, array $targetDir, bool $overwrite = false): bool |
|
80
|
|
|
{ |
|
81
|
4 |
|
return $this->dataCopy( |
|
82
|
4 |
|
array_merge($sourceDir, [$fileName]), |
|
83
|
4 |
|
array_merge($targetDir, [$fileName]), |
|
84
|
4 |
|
$overwrite, |
|
85
|
4 |
|
$this->getImLang()->imImageCannotFind(), |
|
86
|
4 |
|
$this->getImLang()->imImageAlreadyExistsHere(), |
|
87
|
4 |
|
$this->getImLang()->imImageCannotRemoveOld(), |
|
88
|
4 |
|
$this->getImLang()->imImageCannotCopyBase() |
|
89
|
4 |
|
); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param string $fileName |
|
94
|
|
|
* @param string[] $sourceDir |
|
95
|
|
|
* @param string[] $targetDir |
|
96
|
|
|
* @param bool $overwrite |
|
97
|
|
|
* @throws FilesException |
|
98
|
|
|
* @throws PathsException |
|
99
|
|
|
* @return bool |
|
100
|
|
|
*/ |
|
101
|
4 |
|
public function move(string $fileName, array $sourceDir, array $targetDir, bool $overwrite = false): bool |
|
102
|
|
|
{ |
|
103
|
4 |
|
return $this->dataRename( |
|
104
|
4 |
|
array_merge($sourceDir, [$fileName]), |
|
105
|
4 |
|
array_merge($targetDir, [$fileName]), |
|
106
|
4 |
|
$overwrite, |
|
107
|
4 |
|
$this->getImLang()->imImageCannotFind(), |
|
108
|
4 |
|
$this->getImLang()->imImageAlreadyExistsHere(), |
|
109
|
4 |
|
$this->getImLang()->imImageCannotRemoveOld(), |
|
110
|
4 |
|
$this->getImLang()->imImageCannotMoveBase() |
|
111
|
4 |
|
); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param string[] $path |
|
116
|
|
|
* @param string $targetName |
|
117
|
|
|
* @param string $sourceName |
|
118
|
|
|
* @param bool $overwrite |
|
119
|
|
|
* @throws FilesException |
|
120
|
|
|
* @throws PathsException |
|
121
|
|
|
* @return bool |
|
122
|
|
|
*/ |
|
123
|
4 |
|
public function rename(array $path, string $sourceName, string $targetName, bool $overwrite = false): bool |
|
124
|
|
|
{ |
|
125
|
4 |
|
return $this->dataRename( |
|
126
|
4 |
|
array_merge($path, [$sourceName]), |
|
127
|
4 |
|
array_merge($path, [$targetName]), |
|
128
|
4 |
|
$overwrite, |
|
129
|
4 |
|
$this->getImLang()->imImageCannotFind(), |
|
130
|
4 |
|
$this->getImLang()->imImageAlreadyExistsHere(), |
|
131
|
4 |
|
$this->getImLang()->imImageCannotRemoveOld(), |
|
132
|
4 |
|
$this->getImLang()->imImageCannotRenameBase() |
|
133
|
4 |
|
); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @param string[] $sourceDir |
|
138
|
|
|
* @param string $fileName |
|
139
|
|
|
* @throws FilesException |
|
140
|
|
|
* @throws PathsException |
|
141
|
|
|
* @return bool |
|
142
|
|
|
*/ |
|
143
|
5 |
|
public function delete(array $sourceDir, string $fileName): bool |
|
144
|
|
|
{ |
|
145
|
5 |
|
$whatPath = $this->getPath(array_merge($sourceDir, [$fileName])); |
|
146
|
5 |
|
return $this->dataRemove($whatPath, $this->getImLang()->imImageCannotRemove()); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
27 |
|
public function getPath(array $path): array |
|
150
|
|
|
{ |
|
151
|
27 |
|
return $path; |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|