1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_images\Content; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_files\FilesException; |
7
|
|
|
use kalanis\kw_images\ImagesException; |
8
|
|
|
use kalanis\kw_images\Interfaces\IIMTranslations; |
9
|
|
|
use kalanis\kw_images\Sources; |
10
|
|
|
use kalanis\kw_images\TLang; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Dirs |
15
|
|
|
* Create specific content |
16
|
|
|
* @package kalanis\kw_images\Content |
17
|
|
|
*/ |
18
|
|
|
class Dirs |
19
|
|
|
{ |
20
|
|
|
use TLang; |
21
|
|
|
|
22
|
|
|
/** @var ImageSize */ |
23
|
|
|
protected $libSizes = null; |
24
|
|
|
/** @var Sources\Thumb */ |
25
|
|
|
protected $libThumb = null; |
26
|
|
|
/** @var Sources\DirDesc */ |
27
|
|
|
protected $libDirDesc = null; |
28
|
|
|
/** @var Sources\DirThumb */ |
29
|
|
|
protected $libDirThumb = null; |
30
|
|
|
|
31
|
3 |
|
public function __construct(ImageSize $sizes, Sources\Thumb $thumb, Sources\DirDesc $dirDesc, Sources\DirThumb $dirThumb, ?IIMTranslations $lang = null) |
32
|
|
|
{ |
33
|
3 |
|
$this->setLang($lang); |
34
|
3 |
|
$this->libThumb = $thumb; |
35
|
3 |
|
$this->libDirDesc = $dirDesc; |
36
|
3 |
|
$this->libDirThumb = $dirThumb; |
37
|
3 |
|
$this->libSizes = $sizes; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string[] $path |
42
|
|
|
* @throws FilesException |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
1 |
|
public function getDescription(array $path): string |
46
|
|
|
{ |
47
|
1 |
|
return $this->libDirDesc->get($path); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string[] $path |
52
|
|
|
* @param string $description |
53
|
|
|
* @throws FilesException |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
1 |
|
public function updateDescription(array $path, string $description = ''): bool |
57
|
|
|
{ |
58
|
1 |
|
if (!empty($description)) { |
59
|
1 |
|
return $this->libDirDesc->set($path, $description); |
60
|
|
|
} else { |
61
|
1 |
|
return $this->libDirDesc->remove($path); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string[] $path |
67
|
|
|
* @return string|resource |
68
|
|
|
*/ |
69
|
1 |
|
public function getThumb(array $path) |
70
|
|
|
{ |
71
|
|
|
try { |
72
|
1 |
|
return $this->libDirThumb->get($path); |
73
|
1 |
|
} catch (FilesException $ex) { |
74
|
1 |
|
return ''; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string[] $path |
80
|
|
|
* @param string $fromWhichFile |
81
|
|
|
* @throws FilesException |
82
|
|
|
* @throws ImagesException |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
2 |
|
public function updateThumb(array $path, string $fromWhichFile): bool |
86
|
|
|
{ |
87
|
2 |
|
return $this->libSizes->process( |
88
|
2 |
|
$this->libThumb->getPath(array_merge($path, [$fromWhichFile])), |
89
|
2 |
|
$this->libDirThumb->getPath($path) |
90
|
2 |
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string[] $path |
95
|
|
|
* @throws FilesException |
96
|
|
|
* @return bool |
97
|
|
|
*/ |
98
|
2 |
|
public function removeThumb(array $path): bool |
99
|
|
|
{ |
100
|
2 |
|
if ($this->libDirThumb->isHere($path)) { |
101
|
2 |
|
if (!$this->libDirThumb->delete($path)) { |
102
|
1 |
|
throw new FilesException($this->getLang()->imDirThumbCannotRemoveCurrent()); |
103
|
|
|
} |
104
|
|
|
} |
105
|
1 |
|
return true; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|