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\Configs; |
10
|
|
|
use kalanis\kw_images\Content\BasicOperations; |
11
|
|
|
use kalanis\kw_images\Content\Dirs; |
12
|
|
|
use kalanis\kw_images\Content\Images; |
13
|
|
|
use kalanis\kw_images\Content\ImageUpload; |
14
|
|
|
use kalanis\kw_images\ImagesException; |
15
|
|
|
use kalanis\kw_images\Interfaces\IIMTranslations; |
16
|
|
|
use kalanis\kw_images\Traits\TLang; |
17
|
|
|
use kalanis\kw_images\Content; |
18
|
|
|
use kalanis\kw_images\Graphics; |
19
|
|
|
use kalanis\kw_images\Sources; |
20
|
|
|
use kalanis\kw_mime\Check; |
21
|
|
|
use kalanis\kw_mime\Interfaces\IMime; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class Files |
26
|
|
|
* Operations over files |
27
|
|
|
* @package kalanis\kw_images\Access |
28
|
|
|
*/ |
29
|
|
|
class Factory |
30
|
|
|
{ |
31
|
|
|
use TLang; |
32
|
|
|
|
33
|
|
|
protected CompositeAdapter $composite; |
34
|
|
|
protected Configs\ConfigFactory $configFactory; |
35
|
|
|
protected Config $fileConfig; |
36
|
|
|
protected IMime $mime; |
37
|
|
|
|
38
|
4 |
|
public function __construct( |
39
|
|
|
CompositeAdapter $compositeAdapter, |
40
|
|
|
?IMime $mime = null, |
41
|
|
|
?Configs\ConfigFactory $configFactory = null, |
42
|
|
|
?Config $fileConfig = null, |
43
|
|
|
?IIMTranslations $imLang = null |
44
|
|
|
) |
45
|
|
|
{ |
46
|
4 |
|
$this->setImLang($imLang); |
47
|
4 |
|
$this->composite = $compositeAdapter; |
48
|
4 |
|
$this->configFactory = $configFactory ?: new Configs\ConfigFactory(); |
49
|
4 |
|
$this->fileConfig = $fileConfig ?: new Config(); |
50
|
4 |
|
$this->mime = $mime ?: new Check\CustomList(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param array<string, string|int> $params |
55
|
|
|
* @return BasicOperations |
56
|
|
|
*/ |
57
|
1 |
|
public function getOperations(array $params = []): BasicOperations |
58
|
|
|
{ |
59
|
1 |
|
$fileConf = $this->fileConfig->setData($params); |
60
|
1 |
|
return new BasicOperations( // operations with images |
61
|
1 |
|
new Sources\Image($this->composite, $fileConf, $this->getImLang()), |
62
|
1 |
|
new Sources\Thumb($this->composite, $fileConf, $this->getImLang()), |
63
|
1 |
|
new Sources\Desc($this->composite, $fileConf, $this->getImLang()) |
64
|
1 |
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param array<string, string|int> $params |
69
|
|
|
* @throws ImagesException |
70
|
|
|
* @return Dirs |
71
|
|
|
*/ |
72
|
1 |
|
public function getDirs(array $params = []): Dirs |
73
|
|
|
{ |
74
|
1 |
|
$this->configFactory->setData($params); |
75
|
1 |
|
$fileConf = $this->fileConfig->setData($params); |
76
|
1 |
|
return new Dirs( |
77
|
1 |
|
new Content\ImageSize( |
78
|
1 |
|
new Graphics( |
79
|
1 |
|
new Graphics\Processor( |
80
|
1 |
|
new Graphics\Format\Factory(), |
81
|
1 |
|
$this->getImLang() |
82
|
1 |
|
), |
83
|
1 |
|
$this->mime, |
84
|
1 |
|
$this->getImLang() |
85
|
1 |
|
), |
86
|
1 |
|
$this->configFactory->getThumb(), |
87
|
1 |
|
new Sources\Image($this->composite, $fileConf, $this->getImLang()), |
88
|
1 |
|
$this->getImLang() |
89
|
1 |
|
), |
90
|
1 |
|
new Sources\Thumb($this->composite, $fileConf, $this->getImLang()), |
91
|
1 |
|
new Sources\DirDesc($this->composite, $fileConf, $this->getImLang()), |
92
|
1 |
|
new Sources\DirThumb($this->composite, $fileConf, $this->getImLang()), |
93
|
1 |
|
new Processor($this->composite, $fileConf), |
94
|
1 |
|
$this->getImLang() |
95
|
1 |
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param array<string, string|int> $params |
100
|
|
|
* @throws ImagesException |
101
|
|
|
* @return Images |
102
|
|
|
*/ |
103
|
1 |
|
public function getImages(array $params = []): Images |
104
|
|
|
{ |
105
|
1 |
|
$this->configFactory->setData($params); |
106
|
1 |
|
$fileConf = $this->fileConfig->setData($params); |
107
|
1 |
|
$image = new Sources\Image($this->composite, $fileConf, $this->getImLang()); |
108
|
1 |
|
$graphics = new Graphics( |
109
|
1 |
|
new Graphics\Processor( |
110
|
1 |
|
new Graphics\Format\Factory(), |
111
|
1 |
|
$this->getImLang() |
112
|
1 |
|
), |
113
|
1 |
|
$this->mime, |
114
|
1 |
|
$this->getImLang() |
115
|
1 |
|
); |
116
|
1 |
|
return new Images( |
117
|
1 |
|
new Content\ImageSize( |
118
|
1 |
|
$graphics, |
119
|
1 |
|
$this->configFactory->getThumb(), |
120
|
1 |
|
$image, |
121
|
1 |
|
$this->getImLang() |
122
|
1 |
|
), |
123
|
1 |
|
new Content\ImageRotate( |
124
|
1 |
|
$graphics, |
125
|
1 |
|
$this->configFactory->getThumb(), |
126
|
1 |
|
$image, |
127
|
1 |
|
$this->getImLang() |
128
|
1 |
|
), |
129
|
1 |
|
$image, |
130
|
1 |
|
new Sources\Thumb($this->composite, $fileConf, $this->getImLang()), |
131
|
1 |
|
new Sources\Desc($this->composite, $fileConf, $this->getImLang()) |
132
|
1 |
|
); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param array<string, string|int> $params |
137
|
|
|
* @throws ImagesException |
138
|
|
|
* @return ImageUpload |
139
|
|
|
*/ |
140
|
1 |
|
public function getUpload(array $params = []): ImageUpload |
141
|
|
|
{ |
142
|
1 |
|
$this->configFactory->setData($params); |
143
|
1 |
|
$fileConf = $this->fileConfig->setData($params); |
144
|
1 |
|
$graphics = new Graphics( |
145
|
1 |
|
new Graphics\Processor( |
146
|
1 |
|
new Graphics\Format\Factory(), |
147
|
1 |
|
$this->getImLang() |
148
|
1 |
|
), |
149
|
1 |
|
$this->mime, |
150
|
1 |
|
$this->getImLang() |
151
|
1 |
|
); |
152
|
1 |
|
$image = new Sources\Image($this->composite, $fileConf, $this->getImLang()); |
153
|
1 |
|
return new ImageUpload( // process uploaded images |
154
|
1 |
|
$graphics, |
155
|
1 |
|
$image, |
156
|
1 |
|
$this->configFactory->getImage(), |
157
|
1 |
|
new Images( |
158
|
1 |
|
new Content\ImageSize( |
159
|
1 |
|
$graphics, |
160
|
1 |
|
$this->configFactory->getThumb(), |
161
|
1 |
|
$image, |
162
|
1 |
|
$this->getImLang() |
163
|
1 |
|
), |
164
|
1 |
|
new Content\ImageRotate( |
165
|
1 |
|
$graphics, |
166
|
1 |
|
$this->configFactory->getThumb(), |
167
|
1 |
|
$image, |
168
|
1 |
|
$this->getImLang() |
169
|
1 |
|
), |
170
|
1 |
|
new Sources\Image($this->composite, $fileConf, $this->getImLang()), |
171
|
1 |
|
new Sources\Thumb($this->composite, $fileConf, $this->getImLang()), |
172
|
1 |
|
new Sources\Desc($this->composite, $fileConf, $this->getImLang()) |
173
|
1 |
|
), |
174
|
1 |
|
$this->configFactory->getProcessor(), |
175
|
1 |
|
new Content\ImageOrientate( |
176
|
1 |
|
$graphics, |
177
|
1 |
|
$this->configFactory->getImage(), |
178
|
1 |
|
$image, |
179
|
1 |
|
$this->getImLang() |
180
|
1 |
|
), |
181
|
1 |
|
new Content\ImageSize( |
182
|
1 |
|
$graphics, |
183
|
1 |
|
$this->configFactory->getImage(), |
184
|
1 |
|
$image, |
185
|
1 |
|
$this->getImLang() |
186
|
1 |
|
), |
187
|
1 |
|
); |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
|