|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kalanis\kw_images\Access; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\kw_files\Access\CompositeAdapter; |
|
7
|
|
|
use kalanis\kw_files\Extended\Config; |
|
8
|
|
|
use kalanis\kw_files\Extended\Processor; |
|
9
|
|
|
use kalanis\kw_images\Content\BasicOperations; |
|
10
|
|
|
use kalanis\kw_images\Content\Dirs; |
|
11
|
|
|
use kalanis\kw_images\Content\Images; |
|
12
|
|
|
use kalanis\kw_images\Content\ImageUpload; |
|
13
|
|
|
use kalanis\kw_images\ImagesException; |
|
14
|
|
|
use kalanis\kw_images\Interfaces\IIMTranslations; |
|
15
|
|
|
use kalanis\kw_images\Traits\TLang; |
|
16
|
|
|
use kalanis\kw_images\Content; |
|
17
|
|
|
use kalanis\kw_images\Graphics; |
|
18
|
|
|
use kalanis\kw_images\Sources; |
|
19
|
|
|
use kalanis\kw_mime\Check; |
|
20
|
|
|
use kalanis\kw_mime\Interfaces\IMime; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class Files |
|
25
|
|
|
* Operations over files |
|
26
|
|
|
* @package kalanis\kw_images\Access |
|
27
|
|
|
*/ |
|
28
|
|
|
class Factory |
|
29
|
|
|
{ |
|
30
|
|
|
use TLang; |
|
31
|
|
|
|
|
32
|
|
|
protected CompositeAdapter $composite; |
|
33
|
|
|
protected IMime $mime; |
|
34
|
|
|
|
|
35
|
|
|
public function __construct( |
|
36
|
|
|
CompositeAdapter $compositeAdapter, |
|
37
|
|
|
?IMime $mime = null, |
|
38
|
|
|
?IIMTranslations $imLang = null |
|
39
|
|
|
) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->setImLang($imLang); |
|
42
|
|
|
$this->composite = $compositeAdapter; |
|
43
|
|
|
$this->mime = $mime ?: new Check\CustomList(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param array<string, string|int> $params |
|
48
|
|
|
* @return BasicOperations |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getOperations(array $params = []): BasicOperations |
|
51
|
|
|
{ |
|
52
|
|
|
$fileConf = (new Config())->setData($params); |
|
53
|
|
|
return new BasicOperations( // operations with images |
|
54
|
|
|
new Sources\Image($this->composite, $fileConf, $this->getImLang()), |
|
55
|
|
|
new Sources\Thumb($this->composite, $fileConf, $this->getImLang()), |
|
56
|
|
|
new Sources\Desc($this->composite, $fileConf, $this->getImLang()) |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param array<string, string|int> $params |
|
62
|
|
|
* @throws ImagesException |
|
63
|
|
|
* @return Dirs |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getDirs(array $params = []): Dirs |
|
66
|
|
|
{ |
|
67
|
|
|
$fileConf = (new Config())->setData($params); |
|
68
|
|
|
return new Dirs( |
|
69
|
|
|
new Content\ImageSize( |
|
70
|
|
|
new Graphics( |
|
71
|
|
|
new Graphics\Processor( |
|
72
|
|
|
new Graphics\Format\Factory(), |
|
73
|
|
|
$this->getImLang() |
|
74
|
|
|
), |
|
75
|
|
|
$this->mime, |
|
76
|
|
|
$this->getImLang() |
|
77
|
|
|
), |
|
78
|
|
|
(new Graphics\ThumbConfig())->setData($params), |
|
79
|
|
|
new Sources\Image($this->composite, $fileConf, $this->getImLang()), |
|
80
|
|
|
$this->getImLang() |
|
81
|
|
|
), |
|
82
|
|
|
new Sources\Thumb($this->composite, $fileConf, $this->getImLang()), |
|
83
|
|
|
new Sources\DirDesc($this->composite, $fileConf, $this->getImLang()), |
|
84
|
|
|
new Sources\DirThumb($this->composite, $fileConf, $this->getImLang()), |
|
85
|
|
|
new Processor($this->composite, $fileConf), |
|
86
|
|
|
$this->getImLang() |
|
87
|
|
|
); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param array<string, string|int> $params |
|
92
|
|
|
* @throws ImagesException |
|
93
|
|
|
* @return Images |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getImages(array $params = []): Images |
|
96
|
|
|
{ |
|
97
|
|
|
$fileConf = (new Config())->setData($params); |
|
98
|
|
|
$image = new Sources\Image($this->composite, $fileConf, $this->getImLang()); |
|
99
|
|
|
return new Images( |
|
100
|
|
|
new Content\ImageSize( |
|
101
|
|
|
new Graphics( |
|
102
|
|
|
new Graphics\Processor( |
|
103
|
|
|
new Graphics\Format\Factory(), |
|
104
|
|
|
$this->getImLang() |
|
105
|
|
|
), |
|
106
|
|
|
$this->mime, |
|
107
|
|
|
$this->getImLang() |
|
108
|
|
|
), |
|
109
|
|
|
(new Graphics\ThumbConfig())->setData($params), |
|
110
|
|
|
$image, |
|
111
|
|
|
$this->getImLang() |
|
112
|
|
|
), |
|
113
|
|
|
$image, |
|
114
|
|
|
new Sources\Thumb($this->composite, $fileConf, $this->getImLang()), |
|
115
|
|
|
new Sources\Desc($this->composite, $fileConf, $this->getImLang()) |
|
116
|
|
|
); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param array<string, string|int> $params |
|
121
|
|
|
* @throws ImagesException |
|
122
|
|
|
* @return ImageUpload |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getUpload(array $params = []): ImageUpload |
|
125
|
|
|
{ |
|
126
|
|
|
$fileConf = (new Config())->setData($params); |
|
127
|
|
|
$graphics = new Graphics( |
|
128
|
|
|
new Graphics\Processor( |
|
129
|
|
|
new Graphics\Format\Factory(), |
|
130
|
|
|
$this->getImLang() |
|
131
|
|
|
), |
|
132
|
|
|
$this->mime, |
|
133
|
|
|
$this->getImLang() |
|
134
|
|
|
); |
|
135
|
|
|
$image = new Sources\Image($this->composite, $fileConf, $this->getImLang()); |
|
136
|
|
|
return new ImageUpload( // process uploaded images |
|
137
|
|
|
$graphics, |
|
138
|
|
|
$image, |
|
139
|
|
|
(new Graphics\ImageConfig())->setData($params), |
|
140
|
|
|
new Images( |
|
141
|
|
|
new Content\ImageSize( |
|
142
|
|
|
$graphics, |
|
143
|
|
|
(new Graphics\ThumbConfig())->setData($params), |
|
144
|
|
|
$image, |
|
145
|
|
|
$this->getImLang() |
|
146
|
|
|
), |
|
147
|
|
|
new Sources\Image($this->composite, $fileConf, $this->getImLang()), |
|
148
|
|
|
new Sources\Thumb($this->composite, $fileConf, $this->getImLang()), |
|
149
|
|
|
new Sources\Desc($this->composite, $fileConf, $this->getImLang()) |
|
150
|
|
|
) |
|
151
|
|
|
); |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|