1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SlayerBirden\DataFlowServer\Db; |
5
|
|
|
|
6
|
|
|
use Psr\Log\LoggerInterface; |
7
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Middleware\TokenMiddleware; |
8
|
|
|
use SlayerBirden\DataFlowServer\Db\Controller\AddConfigAction; |
9
|
|
|
use SlayerBirden\DataFlowServer\Db\Controller\DeleteConfigAction; |
10
|
|
|
use SlayerBirden\DataFlowServer\Db\Controller\GetConfigAction; |
11
|
|
|
use SlayerBirden\DataFlowServer\Db\Controller\GetConfigsAction; |
12
|
|
|
use SlayerBirden\DataFlowServer\Db\Controller\UpdateConfigAction; |
13
|
|
|
use SlayerBirden\DataFlowServer\Db\Factory\DbConfigHydratorFactory; |
14
|
|
|
use SlayerBirden\DataFlowServer\Db\Factory\DbConfigResourceMiddlewareFactory; |
15
|
|
|
use SlayerBirden\DataFlowServer\Db\Repository\DbConfigurationRepository; |
16
|
|
|
use SlayerBirden\DataFlowServer\Db\Validation\ConfigValidator; |
17
|
|
|
use SlayerBirden\DataFlowServer\Doctrine\Persistence\EntityManagerRegistry; |
18
|
|
|
use SlayerBirden\DataFlowServer\Domain\Middleware\SetOwnerMiddleware; |
19
|
|
|
use SlayerBirden\DataFlowServer\Domain\Middleware\ValidateOwnerMiddleware; |
20
|
|
|
use SlayerBirden\DataFlowServer\Zend\InputFilter\ProxyFilterManagerFactory; |
21
|
|
|
use Zend\Expressive\Helper\BodyParams\BodyParamsMiddleware; |
22
|
|
|
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory; |
23
|
|
|
use Zend\ServiceManager\Factory\InvokableFactory; |
24
|
|
|
|
25
|
|
|
class ConfigProvider |
26
|
|
|
{ |
27
|
|
|
public function __invoke(): array |
28
|
|
|
{ |
29
|
|
|
return [ |
30
|
|
|
ConfigAbstractFactory::class => $this->getAbstractFactoryConfig(), |
31
|
|
|
'dependencies' => $this->getDependenciesConfig(), |
32
|
|
|
'doctrine' => $this->getDoctrineConfig(), |
33
|
|
|
'validators' => $this->getValidatorsConfig(), |
34
|
|
|
'input_filter_specs' => [ |
35
|
|
|
'ConfigInputFilter' => $this->getConfigInputFilterSpec(), |
36
|
|
|
], |
37
|
|
|
'routes' => $this->getRoutesConfig(), |
38
|
|
|
]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
private function getConfigInputFilterSpec(): array |
42
|
|
|
{ |
43
|
|
|
return [ |
44
|
|
|
'title' => [ |
45
|
|
|
'filters' => [ |
46
|
|
|
[ |
47
|
|
|
'name' => 'stringtrim', |
48
|
|
|
] |
49
|
|
|
], |
50
|
|
|
'validators' => [ |
51
|
|
|
[ |
52
|
|
|
'name' => 'notempty', |
53
|
|
|
], |
54
|
|
|
] |
55
|
|
|
], |
56
|
|
|
'dbname' => [ |
57
|
|
|
'required' => false, |
58
|
|
|
'continue_if_empty' => true, |
59
|
|
|
'filters' => [ |
60
|
|
|
[ |
61
|
|
|
'name' => 'stringtrim', |
62
|
|
|
] |
63
|
|
|
], |
64
|
|
|
'validators' => [ |
65
|
|
|
[ |
66
|
|
|
'name' => 'configValidator', |
67
|
|
|
] |
68
|
|
|
] |
69
|
|
|
], |
70
|
|
|
'user' => [ |
71
|
|
|
'required' => false, |
72
|
|
|
'continue_if_empty' => true, |
73
|
|
|
'filters' => [ |
74
|
|
|
[ |
75
|
|
|
'name' => 'stringtrim', |
76
|
|
|
] |
77
|
|
|
], |
78
|
|
|
'validators' => [ |
79
|
|
|
[ |
80
|
|
|
'name' => 'configValidator', |
81
|
|
|
] |
82
|
|
|
] |
83
|
|
|
], |
84
|
|
|
'password' => [ |
85
|
|
|
'required' => false, |
86
|
|
|
'continue_if_empty' => true, |
87
|
|
|
'filters' => [ |
88
|
|
|
[ |
89
|
|
|
'name' => 'stringtrim', |
90
|
|
|
] |
91
|
|
|
], |
92
|
|
|
'validators' => [ |
93
|
|
|
[ |
94
|
|
|
'name' => 'configValidator', |
95
|
|
|
] |
96
|
|
|
] |
97
|
|
|
], |
98
|
|
|
'host' => [ |
99
|
|
|
'required' => false, |
100
|
|
|
'continue_if_empty' => true, |
101
|
|
|
'filters' => [ |
102
|
|
|
[ |
103
|
|
|
'name' => 'stringtrim', |
104
|
|
|
] |
105
|
|
|
], |
106
|
|
|
'validators' => [ |
107
|
|
|
[ |
108
|
|
|
'name' => 'configValidator', |
109
|
|
|
] |
110
|
|
|
] |
111
|
|
|
], |
112
|
|
|
'driver' => [ |
113
|
|
|
'required' => false, |
114
|
|
|
'continue_if_empty' => true, |
115
|
|
|
'filters' => [ |
116
|
|
|
[ |
117
|
|
|
'name' => 'stringtrim', |
118
|
|
|
] |
119
|
|
|
], |
120
|
|
|
'validators' => [ |
121
|
|
|
[ |
122
|
|
|
'name' => 'configValidator', |
123
|
|
|
] |
124
|
|
|
] |
125
|
|
|
], |
126
|
|
|
'port' => [ |
127
|
|
|
'required' => false, |
128
|
|
|
'continue_if_empty' => true, |
129
|
|
|
'filters' => [ |
130
|
|
|
[ |
131
|
|
|
'name' => 'stringtrim', |
132
|
|
|
] |
133
|
|
|
], |
134
|
|
|
'validators' => [ |
135
|
|
|
[ |
136
|
|
|
'name' => 'configValidator', |
137
|
|
|
] |
138
|
|
|
] |
139
|
|
|
], |
140
|
|
|
'url' => [ |
141
|
|
|
'required' => false, |
142
|
|
|
'filters' => [ |
143
|
|
|
[ |
144
|
|
|
'name' => 'stringtrim', |
145
|
|
|
] |
146
|
|
|
], |
147
|
|
|
], |
148
|
|
|
]; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
private function getAbstractFactoryConfig(): array |
152
|
|
|
{ |
153
|
|
|
return [ |
154
|
|
|
DbConfigurationRepository::class => [ |
155
|
|
|
EntityManagerRegistry::class, |
156
|
|
|
], |
157
|
|
|
AddConfigAction::class => [ |
158
|
|
|
EntityManagerRegistry::class, |
159
|
|
|
'DbConfigHydrator', |
160
|
|
|
'ConfigInputFilter', |
161
|
|
|
LoggerInterface::class, |
162
|
|
|
], |
163
|
|
|
UpdateConfigAction::class => [ |
164
|
|
|
EntityManagerRegistry::class, |
165
|
|
|
'DbConfigHydrator', |
166
|
|
|
'ConfigInputFilter', |
167
|
|
|
LoggerInterface::class, |
168
|
|
|
], |
169
|
|
|
GetConfigsAction::class => [ |
170
|
|
|
DbConfigurationRepository::class, |
171
|
|
|
LoggerInterface::class, |
172
|
|
|
'DbConfigHydrator', |
173
|
|
|
], |
174
|
|
|
GetConfigAction::class => [ |
175
|
|
|
'DbConfigHydrator', |
176
|
|
|
], |
177
|
|
|
DeleteConfigAction::class => [ |
178
|
|
|
EntityManagerRegistry::class, |
179
|
|
|
LoggerInterface::class, |
180
|
|
|
'DbConfigHydrator', |
181
|
|
|
], |
182
|
|
|
]; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function getDependenciesConfig(): array |
186
|
|
|
{ |
187
|
|
|
return [ |
188
|
|
|
'factories' => [ |
189
|
|
|
'DbConfigHydrator' => DbConfigHydratorFactory::class, |
190
|
|
|
'ConfigInputFilter' => ProxyFilterManagerFactory::class, |
191
|
|
|
'DbConfigResourceMiddleware' => DbConfigResourceMiddlewareFactory::class, |
192
|
|
|
], |
193
|
|
|
]; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function getDoctrineConfig(): array |
197
|
|
|
{ |
198
|
|
|
return [ |
199
|
|
|
'entity_managers' => [ |
200
|
|
|
'default' => [ |
201
|
|
|
'paths' => [ |
202
|
|
|
'src/Db/Entities', |
203
|
|
|
], |
204
|
|
|
], |
205
|
|
|
], |
206
|
|
|
]; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function getValidatorsConfig(): array |
210
|
|
|
{ |
211
|
|
|
return [ |
212
|
|
|
'aliases' => [ |
213
|
|
|
'configValidator' => ConfigValidator::class, |
214
|
|
|
], |
215
|
|
|
'factories' => [ |
216
|
|
|
ConfigValidator::class => InvokableFactory::class, |
217
|
|
|
], |
218
|
|
|
]; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
public function getRoutesConfig(): array |
222
|
|
|
{ |
223
|
|
|
return [ |
224
|
|
|
[ |
225
|
|
|
'path' => '/config/{id:\d+}', |
226
|
|
|
'middleware' => [ |
227
|
|
|
TokenMiddleware::class, |
228
|
|
|
'DbConfigResourceMiddleware', |
229
|
|
|
GetConfigAction::class, |
230
|
|
|
], |
231
|
|
|
'name' => 'get_config', |
232
|
|
|
'allowed_methods' => ['GET'], |
233
|
|
|
], |
234
|
|
|
[ |
235
|
|
|
'path' => '/configs', |
236
|
|
|
'middleware' => [ |
237
|
|
|
TokenMiddleware::class, |
238
|
|
|
GetConfigsAction::class, |
239
|
|
|
], |
240
|
|
|
'name' => 'get_configs', |
241
|
|
|
'allowed_methods' => ['GET'], |
242
|
|
|
], |
243
|
|
|
[ |
244
|
|
|
'path' => '/config', |
245
|
|
|
'middleware' => [ |
246
|
|
|
TokenMiddleware::class, |
247
|
|
|
BodyParamsMiddleware::class, |
248
|
|
|
SetOwnerMiddleware::class, |
249
|
|
|
AddConfigAction::class, |
250
|
|
|
], |
251
|
|
|
'name' => 'add_config', |
252
|
|
|
'allowed_methods' => ['POST'], |
253
|
|
|
], |
254
|
|
|
[ |
255
|
|
|
'path' => '/config/{id:\d+}', |
256
|
|
|
'middleware' => [ |
257
|
|
|
TokenMiddleware::class, |
258
|
|
|
'DbConfigResourceMiddleware', |
259
|
|
|
ValidateOwnerMiddleware::class, |
260
|
|
|
BodyParamsMiddleware::class, |
261
|
|
|
SetOwnerMiddleware::class, |
262
|
|
|
UpdateConfigAction::class, |
263
|
|
|
], |
264
|
|
|
'name' => 'update_config', |
265
|
|
|
'allowed_methods' => ['PUT'], |
266
|
|
|
], |
267
|
|
|
[ |
268
|
|
|
'path' => '/config/{id:\d+}', |
269
|
|
|
'middleware' => [ |
270
|
|
|
TokenMiddleware::class, |
271
|
|
|
'DbConfigResourceMiddleware', |
272
|
|
|
ValidateOwnerMiddleware::class, |
273
|
|
|
DeleteConfigAction::class, |
274
|
|
|
], |
275
|
|
|
'name' => 'delete_config', |
276
|
|
|
'allowed_methods' => ['DELETE'], |
277
|
|
|
], |
278
|
|
|
]; |
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
|