1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* apparat-server |
5
|
|
|
* |
6
|
|
|
* @category Apparat |
7
|
|
|
* @package Apparat\Server |
8
|
|
|
* @subpackage Apparat\Server |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/*********************************************************************************** |
15
|
|
|
* The MIT License (MIT) |
16
|
|
|
* |
17
|
|
|
* Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
18
|
|
|
* |
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
21
|
|
|
* the Software without restriction, including without limitation the rights to |
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
24
|
|
|
* subject to the following conditions: |
25
|
|
|
* |
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
27
|
|
|
* copies or substantial portions of the Software. |
28
|
|
|
* |
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
35
|
|
|
***********************************************************************************/ |
36
|
|
|
|
37
|
|
|
namespace Apparat\Server; |
38
|
|
|
|
39
|
|
|
use Apparat\Kernel\Ports\AbstractModule; |
40
|
|
|
use Apparat\Kernel\Ports\Contract\DependencyInjectionContainerInterface; |
41
|
|
|
use Apparat\Server\Application\Factory\PayloadFactory; |
42
|
|
|
use Apparat\Server\Domain\Contract\PayloadFactoryInterface; |
43
|
|
|
use Apparat\Server\Domain\Contract\ResponderInterface; |
44
|
|
|
use Apparat\Server\Domain\Contract\RouterContainerInterface; |
45
|
|
|
use Apparat\Server\Domain\Model\Server; |
46
|
|
|
use Apparat\Server\Domain\Service\AbstractService; |
47
|
|
|
use Apparat\Server\Domain\Service\ServiceInterface; |
48
|
|
|
use Apparat\Server\Infrastructure\Action\DayAction; |
49
|
|
|
use Apparat\Server\Infrastructure\Action\ErrorAction; |
50
|
|
|
use Apparat\Server\Infrastructure\Action\HourAction; |
51
|
|
|
use Apparat\Server\Infrastructure\Action\MinuteAction; |
52
|
|
|
use Apparat\Server\Infrastructure\Action\MonthAction; |
53
|
|
|
use Apparat\Server\Infrastructure\Action\ObjectAction; |
54
|
|
|
use Apparat\Server\Infrastructure\Action\SecondAction; |
55
|
|
|
use Apparat\Server\Infrastructure\Action\TypeAction; |
56
|
|
|
use Apparat\Server\Infrastructure\Action\YearAction; |
57
|
|
|
use Apparat\Server\Infrastructure\Responder\DayResponder; |
58
|
|
|
use Apparat\Server\Infrastructure\Responder\ErrorResponder; |
59
|
|
|
use Apparat\Server\Infrastructure\Responder\HourResponder; |
60
|
|
|
use Apparat\Server\Infrastructure\Responder\MinuteResponder; |
61
|
|
|
use Apparat\Server\Infrastructure\Responder\MonthResponder; |
62
|
|
|
use Apparat\Server\Infrastructure\Responder\ObjectResponder; |
63
|
|
|
use Apparat\Server\Infrastructure\Responder\SecondResponder; |
64
|
|
|
use Apparat\Server\Infrastructure\Responder\TypeResponder; |
65
|
|
|
use Apparat\Server\Infrastructure\Responder\YearResponder; |
66
|
|
|
use Apparat\Server\Infrastructure\Route\AuraRouterAdapter; |
67
|
|
|
use Apparat\Server\Infrastructure\Service\DayService; |
68
|
|
|
use Apparat\Server\Infrastructure\Service\ErrorService; |
69
|
|
|
use Apparat\Server\Infrastructure\Service\HourService; |
70
|
|
|
use Apparat\Server\Infrastructure\Service\MinuteService; |
71
|
|
|
use Apparat\Server\Infrastructure\Service\MonthService; |
72
|
|
|
use Apparat\Server\Infrastructure\Service\ObjectService; |
73
|
|
|
use Apparat\Server\Infrastructure\Service\SecondService; |
74
|
|
|
use Apparat\Server\Infrastructure\Service\TypeService; |
75
|
|
|
use Apparat\Server\Infrastructure\Service\YearService; |
76
|
|
|
use Apparat\Server\Ports\Responder\AbstractResponder; |
77
|
|
|
use Apparat\Server\Ports\View\TYPO3FluidView; |
78
|
|
|
use Apparat\Server\Ports\View\ViewInterface; |
79
|
|
|
use Aura\Router\RouterContainer; |
80
|
|
|
use Dotenv\Dotenv; |
81
|
|
|
use Psr\Http\Message\ResponseInterface; |
82
|
|
|
use TYPO3Fluid\Fluid\View\AbstractTemplateView; |
83
|
|
|
use Zend\Diactoros\Response; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Object module |
87
|
|
|
* |
88
|
|
|
* @package Apparat\Object |
89
|
|
|
* @subpackage Apparat\Object |
90
|
|
|
*/ |
91
|
|
|
class Module extends AbstractModule |
92
|
|
|
{ |
93
|
|
|
/** |
94
|
|
|
* Module name |
95
|
|
|
* |
96
|
|
|
* @var string |
97
|
|
|
*/ |
98
|
|
|
const NAME = 'server'; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Validate the environment |
102
|
|
|
* |
103
|
|
|
* @param Dotenv $environment Environment |
104
|
|
|
*/ |
105
|
1 |
|
protected static function validateEnvironment(Dotenv $environment) |
106
|
|
|
{ |
107
|
1 |
|
parent::validateEnvironment($environment); |
108
|
|
|
|
109
|
|
|
// Validate the required environment variables |
110
|
|
|
// $environment->required('APPARAT_BASE_URL')->notEmpty(); |
111
|
|
|
// $environment->required('OBJECT_DATE_PRECISION')->isInteger()->allowedValues([0, 1, 2, 3, 4, 5, 6]); |
112
|
1 |
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Configure the dependency injection container |
116
|
|
|
* |
117
|
|
|
* @param DependencyInjectionContainerInterface $diContainer Dependency injection container |
118
|
|
|
* @return void |
119
|
|
|
*/ |
120
|
1 |
|
public function configureDependencyInjection(DependencyInjectionContainerInterface $diContainer) |
121
|
|
|
{ |
122
|
1 |
|
parent::configureDependencyInjection($diContainer); |
123
|
|
|
|
124
|
|
|
// Configure the server |
125
|
1 |
|
$diContainer->register(Server::class, [ |
126
|
1 |
|
'shared' => true, |
127
|
|
|
'substitutions' => [ |
128
|
|
|
RouterContainerInterface::class => [ |
129
|
1 |
|
'instance' => AuraRouterAdapter::class, |
130
|
|
|
] |
131
|
1 |
|
] |
132
|
1 |
|
]); |
133
|
|
|
|
134
|
|
|
// Configure the router |
135
|
1 |
|
$diContainer->register(RouterContainer::class, [ |
136
|
|
|
'constructParams' => [ |
137
|
1 |
|
parse_url(getenv('APPARAT_BASE_URL'), PHP_URL_PATH) ?: null |
138
|
1 |
|
] |
139
|
1 |
|
]); |
140
|
|
|
|
141
|
|
|
// Configure the service |
142
|
1 |
|
$diContainer->register(AbstractService::class, [ |
143
|
|
|
'substitutions' => [ |
144
|
|
|
PayloadFactoryInterface::class => [ |
145
|
1 |
|
'instance' => PayloadFactory::class, |
146
|
|
|
] |
147
|
1 |
|
] |
148
|
1 |
|
]); |
149
|
|
|
|
150
|
|
|
// Configure the responder: Diactoros Response and TYPO3Fluid template view |
151
|
1 |
|
$diContainer->register(AbstractResponder::class, [ |
152
|
|
|
'substitutions' => [ |
153
|
|
|
ResponseInterface::class => [ |
154
|
1 |
|
'instance' => Response::class, |
155
|
1 |
|
], |
156
|
|
|
ViewInterface::class => [ |
157
|
1 |
|
'instance' => TYPO3FluidView::class, |
158
|
|
|
] |
159
|
1 |
|
] |
160
|
1 |
|
]); |
161
|
|
|
|
162
|
|
|
// Configure the TYPO3Fluid template view |
163
|
1 |
|
$diContainer->register(AbstractTemplateView::class, [ |
164
|
1 |
|
'constructParams' => [null] |
165
|
1 |
|
]); |
166
|
|
|
|
167
|
|
|
// Configure the action dependencies |
168
|
1 |
|
$this->configureActionDependencies($diContainer); |
169
|
1 |
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Configure the action dependencies |
173
|
|
|
* |
174
|
|
|
* @param DependencyInjectionContainerInterface $diContainer Dependency injection container |
175
|
|
|
*/ |
176
|
1 |
|
protected function configureActionDependencies(DependencyInjectionContainerInterface $diContainer) |
177
|
|
|
{ |
178
|
1 |
|
$diContainer->register(YearAction::class, [ |
179
|
|
|
'substitutions' => [ |
180
|
|
|
ServiceInterface::class => [ |
181
|
1 |
|
'instance' => YearService::class, |
182
|
1 |
|
], |
183
|
|
|
ResponderInterface::class => [ |
184
|
1 |
|
'instance' => YearResponder::class, |
185
|
|
|
] |
186
|
1 |
|
] |
187
|
1 |
|
]); |
188
|
1 |
|
$diContainer->register(MonthAction::class, [ |
189
|
|
|
'substitutions' => [ |
190
|
|
|
ServiceInterface::class => [ |
191
|
1 |
|
'instance' => MonthService::class, |
192
|
1 |
|
], |
193
|
|
|
ResponderInterface::class => [ |
194
|
1 |
|
'instance' => MonthResponder::class, |
195
|
|
|
] |
196
|
1 |
|
] |
197
|
1 |
|
]); |
198
|
1 |
|
$diContainer->register(DayAction::class, [ |
199
|
|
|
'substitutions' => [ |
200
|
|
|
ServiceInterface::class => [ |
201
|
1 |
|
'instance' => DayService::class, |
202
|
1 |
|
], |
203
|
|
|
ResponderInterface::class => [ |
204
|
1 |
|
'instance' => DayResponder::class, |
205
|
|
|
] |
206
|
1 |
|
] |
207
|
1 |
|
]); |
208
|
1 |
|
$diContainer->register(HourAction::class, [ |
209
|
|
|
'substitutions' => [ |
210
|
|
|
ServiceInterface::class => [ |
211
|
1 |
|
'instance' => HourService::class, |
212
|
1 |
|
], |
213
|
|
|
ResponderInterface::class => [ |
214
|
1 |
|
'instance' => HourResponder::class, |
215
|
|
|
] |
216
|
1 |
|
] |
217
|
1 |
|
]); |
218
|
1 |
|
$diContainer->register(MinuteAction::class, [ |
219
|
|
|
'substitutions' => [ |
220
|
|
|
ServiceInterface::class => [ |
221
|
1 |
|
'instance' => MinuteService::class, |
222
|
1 |
|
], |
223
|
|
|
ResponderInterface::class => [ |
224
|
1 |
|
'instance' => MinuteResponder::class, |
225
|
|
|
] |
226
|
1 |
|
] |
227
|
1 |
|
]); |
228
|
1 |
|
$diContainer->register(SecondAction::class, [ |
229
|
|
|
'substitutions' => [ |
230
|
|
|
ServiceInterface::class => [ |
231
|
1 |
|
'instance' => SecondService::class, |
232
|
1 |
|
], |
233
|
|
|
ResponderInterface::class => [ |
234
|
1 |
|
'instance' => SecondResponder::class, |
235
|
|
|
] |
236
|
1 |
|
] |
237
|
1 |
|
]); |
238
|
1 |
|
$diContainer->register(ObjectAction::class, [ |
239
|
|
|
'substitutions' => [ |
240
|
|
|
ServiceInterface::class => [ |
241
|
1 |
|
'instance' => ObjectService::class, |
242
|
1 |
|
], |
243
|
|
|
ResponderInterface::class => [ |
244
|
1 |
|
'instance' => ObjectResponder::class, |
245
|
|
|
] |
246
|
1 |
|
] |
247
|
1 |
|
]); |
248
|
1 |
|
$diContainer->register(TypeAction::class, [ |
249
|
|
|
'substitutions' => [ |
250
|
|
|
ServiceInterface::class => [ |
251
|
1 |
|
'instance' => TypeService::class, |
252
|
1 |
|
], |
253
|
|
|
ResponderInterface::class => [ |
254
|
1 |
|
'instance' => TypeResponder::class, |
255
|
|
|
] |
256
|
1 |
|
] |
257
|
1 |
|
]); |
258
|
1 |
|
$diContainer->register(ErrorAction::class, [ |
259
|
|
|
'substitutions' => [ |
260
|
|
|
ServiceInterface::class => [ |
261
|
1 |
|
'instance' => ErrorService::class, |
262
|
1 |
|
], |
263
|
|
|
ResponderInterface::class => [ |
264
|
1 |
|
'instance' => ErrorResponder::class, |
265
|
|
|
] |
266
|
1 |
|
] |
267
|
1 |
|
]); |
268
|
1 |
|
} |
269
|
|
|
} |
270
|
|
|
|