1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_images\Content; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_files\Extended\Processor; |
7
|
|
|
use kalanis\kw_files\FilesException; |
8
|
|
|
use kalanis\kw_images\ImagesException; |
9
|
|
|
use kalanis\kw_images\Interfaces\IIMTranslations; |
10
|
|
|
use kalanis\kw_images\Sources; |
11
|
|
|
use kalanis\kw_images\Traits\TLang; |
12
|
|
|
use kalanis\kw_mime\MimeException; |
13
|
|
|
use kalanis\kw_paths\PathsException; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Dirs |
18
|
|
|
* Create specific content |
19
|
|
|
* @package kalanis\kw_images\Content |
20
|
|
|
*/ |
21
|
|
|
class Dirs |
22
|
|
|
{ |
23
|
|
|
use TLang; |
24
|
|
|
|
25
|
|
|
protected ImageSize $libSizes; |
26
|
|
|
protected Sources\Thumb $libThumb; |
27
|
|
|
protected Sources\DirDesc $libDirDesc; |
28
|
|
|
protected Sources\DirThumb $libDirThumb; |
29
|
|
|
protected Processor $libExt; |
30
|
|
|
|
31
|
6 |
|
public function __construct(ImageSize $sizes, Sources\Thumb $thumb, Sources\DirDesc $dirDesc, Sources\DirThumb $dirThumb, Processor $ext, ?IIMTranslations $lang = null) |
32
|
|
|
{ |
33
|
6 |
|
$this->setImLang($lang); |
34
|
6 |
|
$this->libThumb = $thumb; |
35
|
6 |
|
$this->libDirDesc = $dirDesc; |
36
|
6 |
|
$this->libDirThumb = $dirThumb; |
37
|
6 |
|
$this->libExt = $ext; |
38
|
6 |
|
$this->libSizes = $sizes; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string[] $path |
43
|
|
|
* @throws FilesException |
44
|
|
|
* @throws PathsException |
45
|
|
|
* @return bool |
46
|
|
|
*/ |
47
|
3 |
|
public function exists(array $path): bool |
48
|
|
|
{ |
49
|
3 |
|
return $this->libExt->dirExists($path); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string[] $path |
54
|
|
|
* @throws FilesException |
55
|
|
|
* @throws PathsException |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
1 |
|
public function getDescription(array $path): string |
59
|
|
|
{ |
60
|
1 |
|
return $this->libDirDesc->get($path); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string[] $path |
65
|
|
|
* @param string $description |
66
|
|
|
* @throws FilesException |
67
|
|
|
* @throws PathsException |
68
|
|
|
* @return bool |
69
|
|
|
*/ |
70
|
1 |
|
public function updateDescription(array $path, string $description = ''): bool |
71
|
|
|
{ |
72
|
1 |
|
if (!empty($description)) { |
73
|
1 |
|
return $this->libDirDesc->set($path, $description); |
74
|
|
|
} else { |
75
|
1 |
|
return $this->libDirDesc->remove($path); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string[] $path |
81
|
|
|
* @throws PathsException |
82
|
|
|
* @return string|resource |
83
|
|
|
*/ |
84
|
1 |
|
public function getThumb(array $path) |
85
|
|
|
{ |
86
|
|
|
try { |
87
|
1 |
|
return $this->libDirThumb->get($path); |
88
|
1 |
|
} catch (FilesException $ex) { |
89
|
1 |
|
return ''; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string[] $path |
95
|
|
|
* @param string $fromWhichFile |
96
|
|
|
* @throws FilesException |
97
|
|
|
* @throws ImagesException |
98
|
|
|
* @throws MimeException |
99
|
|
|
* @throws PathsException |
100
|
|
|
* @return bool |
101
|
|
|
*/ |
102
|
2 |
|
public function updateThumb(array $path, string $fromWhichFile): bool |
103
|
|
|
{ |
104
|
2 |
|
return $this->libSizes->process( |
105
|
2 |
|
$this->libThumb->getPath(array_merge($path, [$fromWhichFile])), |
106
|
2 |
|
$this->libDirThumb->getPath($path) |
107
|
2 |
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param string[] $path |
112
|
|
|
* @throws FilesException |
113
|
|
|
* @throws PathsException |
114
|
|
|
* @return bool |
115
|
|
|
*/ |
116
|
2 |
|
public function removeThumb(array $path): bool |
117
|
|
|
{ |
118
|
2 |
|
if ($this->libDirThumb->isHere($path)) { |
119
|
2 |
|
if (!$this->libDirThumb->delete($path)) { |
120
|
1 |
|
throw new FilesException($this->getImLang()->imDirThumbCannotRemoveCurrent()); |
121
|
|
|
} |
122
|
|
|
} |
123
|
1 |
|
return true; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param string[] $path |
128
|
|
|
* @throws FilesException |
129
|
|
|
* @throws PathsException |
130
|
|
|
* @return bool |
131
|
|
|
*/ |
132
|
2 |
|
public function canUse(array $path): bool |
133
|
|
|
{ |
134
|
2 |
|
return $this->libExt->isExtended($path); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param string[] $path |
139
|
|
|
* @throws FilesException |
140
|
|
|
* @throws PathsException |
141
|
|
|
* @return bool |
142
|
|
|
*/ |
143
|
1 |
|
public function create(array $path): bool |
144
|
|
|
{ |
145
|
1 |
|
return $this->libExt->createDir($path, true); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param string[] $path |
150
|
|
|
* @throws FilesException |
151
|
|
|
* @throws PathsException |
152
|
|
|
* @return bool |
153
|
|
|
*/ |
154
|
1 |
|
public function createExtra(array $path): bool |
155
|
|
|
{ |
156
|
1 |
|
return $this->libExt->makeExtended($path); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|