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\RouterContainerInterface; |
44
|
|
|
use Apparat\Server\Domain\Model\Server; |
45
|
|
|
use Apparat\Server\Domain\Service\AbstractService; |
46
|
|
|
use Apparat\Server\Infrastructure\Route\AuraRouterAdapter; |
47
|
|
|
use Apparat\Server\Infrastructure\Traits\DateActionsTrait; |
48
|
|
|
use Apparat\Server\Infrastructure\Traits\ObjectActionsTrait; |
49
|
|
|
use Apparat\Server\Ports\Responder\AbstractResponder; |
50
|
|
|
use Apparat\Server\Ports\View\TYPO3FluidView; |
51
|
|
|
use Apparat\Server\Ports\View\ViewInterface; |
52
|
|
|
use Aura\Router\RouterContainer; |
53
|
|
|
use Dotenv\Dotenv; |
54
|
|
|
use Psr\Http\Message\ResponseInterface; |
55
|
|
|
use TYPO3Fluid\Fluid\View\AbstractTemplateView; |
56
|
|
|
use Zend\Diactoros\Response; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Object module |
60
|
|
|
* |
61
|
|
|
* @package Apparat\Object |
62
|
|
|
* @subpackage Apparat\Object |
63
|
|
|
*/ |
64
|
|
|
class Module extends AbstractModule |
65
|
|
|
{ |
66
|
|
|
/** |
67
|
|
|
* Use external dependency configurations |
68
|
|
|
*/ |
69
|
|
|
use DateActionsTrait, ObjectActionsTrait; |
70
|
|
|
/** |
71
|
|
|
* Module name |
72
|
|
|
* |
73
|
|
|
* @var string |
74
|
|
|
*/ |
75
|
|
|
const NAME = 'server'; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Validate the environment |
79
|
|
|
* |
80
|
|
|
* @param Dotenv $environment Environment |
81
|
|
|
*/ |
82
|
1 |
|
protected static function validateEnvironment(Dotenv $environment) |
83
|
|
|
{ |
84
|
1 |
|
parent::validateEnvironment($environment); |
85
|
1 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Configure the dependency injection container |
89
|
|
|
* |
90
|
|
|
* @param DependencyInjectionContainerInterface $diContainer Dependency injection container |
91
|
|
|
* @return void |
92
|
|
|
*/ |
93
|
1 |
|
public function configureDependencyInjection(DependencyInjectionContainerInterface $diContainer) |
94
|
|
|
{ |
95
|
1 |
|
parent::configureDependencyInjection($diContainer); |
96
|
|
|
|
97
|
|
|
// Configure the server |
98
|
1 |
|
$diContainer->register(Server::class, [ |
99
|
1 |
|
'shared' => false, |
100
|
|
|
'substitutions' => [ |
101
|
|
|
RouterContainerInterface::class => [ |
102
|
1 |
|
'instance' => AuraRouterAdapter::class, |
103
|
|
|
] |
104
|
1 |
|
] |
105
|
1 |
|
]); |
106
|
|
|
|
107
|
|
|
// Configure the router |
108
|
1 |
|
$diContainer->register(RouterContainer::class, [ |
109
|
|
|
'constructParams' => [ |
110
|
1 |
|
rtrim(parse_url(getenv('APPARAT_BASE_URL'), PHP_URL_PATH), '/') ?: null |
111
|
1 |
|
] |
112
|
1 |
|
]); |
113
|
|
|
|
114
|
|
|
// Configure the service |
115
|
1 |
|
$diContainer->register(AbstractService::class, [ |
116
|
|
|
'substitutions' => [ |
117
|
|
|
PayloadFactoryInterface::class => [ |
118
|
1 |
|
'instance' => PayloadFactory::class, |
119
|
|
|
] |
120
|
1 |
|
] |
121
|
1 |
|
]); |
122
|
|
|
|
123
|
|
|
// Configure the responder: Diactoros Response and TYPO3Fluid template view |
124
|
1 |
|
$diContainer->register(AbstractResponder::class, [ |
125
|
|
|
'substitutions' => [ |
126
|
|
|
ResponseInterface::class => [ |
127
|
1 |
|
'instance' => Response::class, |
128
|
1 |
|
], |
129
|
|
|
ViewInterface::class => [ |
130
|
1 |
|
'instance' => TYPO3FluidView::class, |
131
|
|
|
] |
132
|
1 |
|
] |
133
|
1 |
|
]); |
134
|
|
|
|
135
|
|
|
// Configure the TYPO3Fluid template view |
136
|
1 |
|
$diContainer->register(AbstractTemplateView::class, [ |
137
|
1 |
|
'constructParams' => [null] |
138
|
1 |
|
]); |
139
|
|
|
|
140
|
|
|
// Configure the date action dependencies |
141
|
1 |
|
$this->configureDateActionDependencies($diContainer); |
142
|
|
|
|
143
|
|
|
// Configure the object action dependencies |
144
|
1 |
|
$this->configureObjectActionDependencies($diContainer); |
145
|
1 |
|
} |
146
|
|
|
} |
147
|
|
|
|