1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SlayerBirden\DataFlowServer\Domain; |
5
|
|
|
|
6
|
|
|
use Psr\Log\LoggerInterface; |
7
|
|
|
use SlayerBirden\DataFlowServer\Authentication\Middleware\TokenMiddleware; |
8
|
|
|
use SlayerBirden\DataFlowServer\Doctrine\Persistence\EntityManagerRegistry; |
9
|
|
|
use SlayerBirden\DataFlowServer\Domain\Controller\AddUserAction; |
10
|
|
|
use SlayerBirden\DataFlowServer\Domain\Controller\DeleteUserAction; |
11
|
|
|
use SlayerBirden\DataFlowServer\Domain\Controller\GetUserAction; |
12
|
|
|
use SlayerBirden\DataFlowServer\Domain\Controller\GetUsersAction; |
13
|
|
|
use SlayerBirden\DataFlowServer\Domain\Controller\UpdateUserAction; |
14
|
|
|
use SlayerBirden\DataFlowServer\Domain\Factory\UserResourceMiddlewareFactory; |
15
|
|
|
use SlayerBirden\DataFlowServer\Domain\Repository\UserRepository; |
16
|
|
|
use SlayerBirden\DataFlowServer\Zend\InputFilter\ProxyFilterManagerFactory; |
17
|
|
|
use Zend\Expressive\Helper\BodyParams\BodyParamsMiddleware; |
18
|
|
|
use Zend\Hydrator\ClassMethods; |
19
|
|
|
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory; |
20
|
|
|
|
21
|
|
|
class ConfigProvider |
22
|
|
|
{ |
23
|
|
|
public function __invoke(): array |
24
|
|
|
{ |
25
|
|
|
return [ |
26
|
|
|
ConfigAbstractFactory::class => $this->getAbstractFactoryConfig(), |
27
|
|
|
'doctrine' => $this->getDoctrineConfig(), |
28
|
|
|
'dependencies' => $this->getDependenciesConfig(), |
29
|
|
|
'input_filter_specs' => [ |
30
|
|
|
'UserInputFilter' => $this->getUserInputFilterSpec(), |
31
|
|
|
], |
32
|
|
|
'routes' => $this->getRoutesConfig(), |
33
|
|
|
]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
private function getUserInputFilterSpec(): array |
37
|
|
|
{ |
38
|
|
|
return [ |
39
|
|
|
'first' => [ |
40
|
|
|
'required' => true, |
41
|
|
|
'filters' => [ |
42
|
|
|
[ |
43
|
|
|
'name' => 'stringtrim', |
44
|
|
|
] |
45
|
|
|
], |
46
|
|
|
'validators' => [ |
47
|
|
|
[ |
48
|
|
|
'name' => 'notempty', |
49
|
|
|
], |
50
|
|
|
[ |
51
|
|
|
'name' => 'alpha', |
52
|
|
|
], |
53
|
|
|
] |
54
|
|
|
], |
55
|
|
|
'last' => [ |
56
|
|
|
'required' => true, |
57
|
|
|
'filters' => [ |
58
|
|
|
[ |
59
|
|
|
'name' => 'stringtrim', |
60
|
|
|
] |
61
|
|
|
], |
62
|
|
|
'validators' => [ |
63
|
|
|
[ |
64
|
|
|
'name' => 'notempty', |
65
|
|
|
], |
66
|
|
|
[ |
67
|
|
|
'name' => 'alpha', |
68
|
|
|
], |
69
|
|
|
] |
70
|
|
|
], |
71
|
|
|
'email' => [ |
72
|
|
|
'required' => true, |
73
|
|
|
'filters' => [ |
74
|
|
|
[ |
75
|
|
|
'name' => 'stringtrim', |
76
|
|
|
] |
77
|
|
|
], |
78
|
|
|
'validators' => [ |
79
|
|
|
[ |
80
|
|
|
'name' => 'notempty', |
81
|
|
|
], |
82
|
|
|
[ |
83
|
|
|
'name' => 'emailAddress', |
84
|
|
|
], |
85
|
|
|
], |
86
|
|
|
], |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
private function getAbstractFactoryConfig(): array |
91
|
|
|
{ |
92
|
|
|
return [ |
93
|
|
|
UserRepository::class => [ |
94
|
|
|
EntityManagerRegistry::class, |
95
|
|
|
], |
96
|
|
|
AddUserAction::class => [ |
97
|
|
|
EntityManagerRegistry::class, |
98
|
|
|
ClassMethods::class, |
99
|
|
|
'UserInputFilter', |
100
|
|
|
LoggerInterface::class, |
101
|
|
|
], |
102
|
|
|
UpdateUserAction::class => [ |
103
|
|
|
EntityManagerRegistry::class, |
104
|
|
|
ClassMethods::class, |
105
|
|
|
'UserInputFilter', |
106
|
|
|
LoggerInterface::class, |
107
|
|
|
], |
108
|
|
|
GetUserAction::class => [ |
109
|
|
|
ClassMethods::class, |
110
|
|
|
], |
111
|
|
|
GetUsersAction::class => [ |
112
|
|
|
UserRepository::class, |
113
|
|
|
LoggerInterface::class, |
114
|
|
|
ClassMethods::class, |
115
|
|
|
], |
116
|
|
|
DeleteUserAction::class => [ |
117
|
|
|
EntityManagerRegistry::class, |
118
|
|
|
LoggerInterface::class, |
119
|
|
|
ClassMethods::class, |
120
|
|
|
], |
121
|
|
|
]; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
private function getDoctrineConfig(): array |
125
|
|
|
{ |
126
|
|
|
return [ |
127
|
|
|
'entity_managers' => [ |
128
|
|
|
'default' => [ |
129
|
|
|
'paths' => [ |
130
|
|
|
'src/Domain/Entities', |
131
|
|
|
], |
132
|
|
|
], |
133
|
|
|
], |
134
|
|
|
]; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
private function getDependenciesConfig(): array |
138
|
|
|
{ |
139
|
|
|
return [ |
140
|
|
|
'factories' => [ |
141
|
|
|
'UserInputFilter' => ProxyFilterManagerFactory::class, |
142
|
|
|
'UserResourceMiddleware' => UserResourceMiddlewareFactory::class, |
143
|
|
|
], |
144
|
|
|
]; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function getRoutesConfig(): array |
148
|
|
|
{ |
149
|
|
|
return [ |
150
|
|
|
[ |
151
|
|
|
'path' => '/user/{id:\d+}', |
152
|
|
|
'middleware' => [ |
153
|
|
|
TokenMiddleware::class, |
154
|
|
|
'UserResourceMiddleware', |
155
|
|
|
GetUserAction::class, |
156
|
|
|
], |
157
|
|
|
'name' => 'get_user', |
158
|
|
|
'allowed_methods' => ['GET'], |
159
|
|
|
], |
160
|
|
|
[ |
161
|
|
|
'path' => '/users', |
162
|
|
|
'middleware' => [ |
163
|
|
|
TokenMiddleware::class, |
164
|
|
|
GetUsersAction::class, |
165
|
|
|
], |
166
|
|
|
'name' => 'get_users', |
167
|
|
|
'allowed_methods' => ['GET'], |
168
|
|
|
], |
169
|
|
|
[ |
170
|
|
|
'path' => '/user', |
171
|
|
|
'middleware' => [ |
172
|
|
|
TokenMiddleware::class, |
173
|
|
|
BodyParamsMiddleware::class, |
174
|
|
|
AddUserAction::class, |
175
|
|
|
], |
176
|
|
|
'name' => 'add_user', |
177
|
|
|
'allowed_methods' => ['POST'], |
178
|
|
|
], |
179
|
|
|
[ |
180
|
|
|
'path' => '/user/{id:\d+}', |
181
|
|
|
'middleware' => [ |
182
|
|
|
TokenMiddleware::class, |
183
|
|
|
'UserResourceMiddleware', |
184
|
|
|
BodyParamsMiddleware::class, |
185
|
|
|
UpdateUserAction::class, |
186
|
|
|
], |
187
|
|
|
'name' => 'update_user', |
188
|
|
|
'allowed_methods' => ['PUT'], |
189
|
|
|
], |
190
|
|
|
[ |
191
|
|
|
'path' => '/user/{id:\d+}', |
192
|
|
|
'middleware' => [ |
193
|
|
|
TokenMiddleware::class, |
194
|
|
|
'UserResourceMiddleware', |
195
|
|
|
DeleteUserAction::class |
196
|
|
|
], |
197
|
|
|
'name' => 'delete_user', |
198
|
|
|
'allowed_methods' => ['DELETE'], |
199
|
|
|
], |
200
|
|
|
]; |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|