|
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
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class Thumb |
|
13
|
|
|
* File thumbnail |
|
14
|
|
|
* @package kalanis\kw_images\Sources |
|
15
|
|
|
*/ |
|
16
|
|
|
class Thumb extends AFiles |
|
17
|
|
|
{ |
|
18
|
|
|
use TToString; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param string[] $path |
|
22
|
|
|
* @throws FilesException |
|
23
|
|
|
* @throws PathsException |
|
24
|
|
|
* @return string|resource |
|
25
|
|
|
*/ |
|
26
|
4 |
|
public function get(array $path) |
|
27
|
|
|
{ |
|
28
|
4 |
|
return $this->lib->readFile($this->getPath($path)); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param string[] $path |
|
33
|
|
|
* @param string|resource $content |
|
34
|
|
|
* @throws FilesException |
|
35
|
|
|
* @throws PathsException |
|
36
|
|
|
* @return bool |
|
37
|
|
|
*/ |
|
38
|
11 |
|
public function set(array $path, $content): bool |
|
39
|
|
|
{ |
|
40
|
11 |
|
return $this->lib->saveFile($this->getPath($path), $this->toString(implode(DIRECTORY_SEPARATOR, $path), $content)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param string $fileName |
|
45
|
|
|
* @param string[] $sourceDir |
|
46
|
|
|
* @param string[] $targetDir |
|
47
|
|
|
* @param bool $overwrite |
|
48
|
|
|
* @throws FilesException |
|
49
|
|
|
* @throws PathsException |
|
50
|
|
|
* @return bool |
|
51
|
|
|
*/ |
|
52
|
3 |
|
public function copy(string $fileName, array $sourceDir, array $targetDir, bool $overwrite = false): bool |
|
53
|
|
|
{ |
|
54
|
3 |
|
return $this->dataCopy( |
|
55
|
3 |
|
array_merge($sourceDir, [$this->config->getThumbDir(), $fileName]), |
|
56
|
3 |
|
array_merge($targetDir, [$this->config->getThumbDir(), $fileName]), |
|
57
|
3 |
|
$overwrite, |
|
58
|
3 |
|
$this->getImLang()->imThumbCannotFind(), |
|
59
|
3 |
|
$this->getImLang()->imThumbAlreadyExistsHere(), |
|
60
|
3 |
|
$this->getImLang()->imThumbCannotRemoveOld(), |
|
61
|
3 |
|
$this->getImLang()->imThumbCannotCopyBase() |
|
62
|
3 |
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param string $fileName |
|
67
|
|
|
* @param string[] $sourceDir |
|
68
|
|
|
* @param string[] $targetDir |
|
69
|
|
|
* @param bool $overwrite |
|
70
|
|
|
* @throws FilesException |
|
71
|
|
|
* @throws PathsException |
|
72
|
|
|
* @return bool |
|
73
|
|
|
*/ |
|
74
|
3 |
|
public function move(string $fileName, array $sourceDir, array $targetDir, bool $overwrite = false): bool |
|
75
|
|
|
{ |
|
76
|
3 |
|
return $this->dataRename( |
|
77
|
3 |
|
array_merge($sourceDir, [$this->config->getThumbDir(), $fileName]), |
|
78
|
3 |
|
array_merge($targetDir, [$this->config->getThumbDir(), $fileName]), |
|
79
|
3 |
|
$overwrite, |
|
80
|
3 |
|
$this->getImLang()->imThumbCannotFind(), |
|
81
|
3 |
|
$this->getImLang()->imThumbAlreadyExistsHere(), |
|
82
|
3 |
|
$this->getImLang()->imThumbCannotRemoveOld(), |
|
83
|
3 |
|
$this->getImLang()->imThumbCannotMoveBase() |
|
84
|
3 |
|
); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param string[] $path |
|
89
|
|
|
* @param string $sourceName |
|
90
|
|
|
* @param string $targetName |
|
91
|
|
|
* @param bool $overwrite |
|
92
|
|
|
* @throws FilesException |
|
93
|
|
|
* @throws PathsException |
|
94
|
|
|
* @return bool |
|
95
|
|
|
*/ |
|
96
|
3 |
|
public function rename(array $path, string $sourceName, string $targetName, bool $overwrite = false): bool |
|
97
|
|
|
{ |
|
98
|
3 |
|
return $this->dataRename( |
|
99
|
3 |
|
array_merge($path, [$this->config->getThumbDir(), $sourceName]), |
|
100
|
3 |
|
array_merge($path, [$this->config->getThumbDir(), $targetName]), |
|
101
|
3 |
|
$overwrite, |
|
102
|
3 |
|
$this->getImLang()->imThumbCannotFind(), |
|
103
|
3 |
|
$this->getImLang()->imThumbAlreadyExistsHere(), |
|
104
|
3 |
|
$this->getImLang()->imThumbCannotRemoveOld(), |
|
105
|
3 |
|
$this->getImLang()->imThumbCannotRenameBase() |
|
106
|
3 |
|
); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param string[] $sourceDir |
|
111
|
|
|
* @param string $fileName |
|
112
|
|
|
* @throws FilesException |
|
113
|
|
|
* @throws PathsException |
|
114
|
|
|
* @return bool |
|
115
|
|
|
*/ |
|
116
|
7 |
|
public function delete(array $sourceDir, string $fileName): bool |
|
117
|
|
|
{ |
|
118
|
7 |
|
return $this->dataRemove( |
|
119
|
7 |
|
$this->getPath(array_merge($sourceDir, [$fileName])), |
|
120
|
7 |
|
$this->getImLang()->imThumbCannotRemove() |
|
121
|
7 |
|
); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
17 |
|
public function getPath(array $path): array |
|
125
|
|
|
{ |
|
126
|
17 |
|
$fileName = strval(array_pop($path)); |
|
127
|
17 |
|
return array_merge($path, [$this->config->getThumbDir(), $fileName]); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|