Completed
Push — master ( 6f32f0...f84bd3 )
by Joschi
02:31
created

Module   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 160
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 6
Bugs 0 Features 1
Metric Value
wmc 4
c 6
b 0
f 1
lcom 0
cbo 2
dl 0
loc 160
ccs 0
cts 34
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validateEnvironment() 0 8 1
B configureDependencyInjection() 0 41 2
B configureActionDependencies() 0 83 1
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\Domain\Contract\RouterContainerInterface;
42
use Apparat\Server\Domain\Model\Server;
43
use Apparat\Server\Domain\Service\DayService;
44
use Apparat\Server\Domain\Service\HourService;
45
use Apparat\Server\Domain\Service\MinuteService;
46
use Apparat\Server\Domain\Service\MonthService;
47
use Apparat\Server\Domain\Service\ObjectService;
48
use Apparat\Server\Domain\Service\SecondService;
49
use Apparat\Server\Domain\Service\ServiceInterface;
50
use Apparat\Server\Domain\Service\TypeService;
51
use Apparat\Server\Domain\Service\YearService;
52
use Apparat\Server\Infrastructure\Action\DayAction;
53
use Apparat\Server\Infrastructure\Action\HourAction;
54
use Apparat\Server\Infrastructure\Action\MinuteAction;
55
use Apparat\Server\Infrastructure\Action\MonthAction;
56
use Apparat\Server\Infrastructure\Action\ObjectAction;
57
use Apparat\Server\Infrastructure\Action\SecondAction;
58
use Apparat\Server\Infrastructure\Action\TypeAction;
59
use Apparat\Server\Infrastructure\Action\YearAction;
60
use Apparat\Server\Infrastructure\AuraRouterAdapter;
61
use Apparat\Server\Infrastructure\Responder\DayResponder;
62
use Apparat\Server\Infrastructure\Responder\HourResponder;
63
use Apparat\Server\Infrastructure\Responder\MinuteResponder;
64
use Apparat\Server\Infrastructure\Responder\MonthResponder;
65
use Apparat\Server\Infrastructure\Responder\ObjectResponder;
66
use Apparat\Server\Infrastructure\Responder\SecondResponder;
67
use Apparat\Server\Infrastructure\Responder\TypeResponder;
68
use Apparat\Server\Infrastructure\Responder\YearResponder;
69
use Apparat\Server\Ports\Responder\AbstractResponder;
70
use Apparat\Server\Ports\Responder\ResponderInterface;
71
use Apparat\Server\Ports\View\TYPO3FluidView;
72
use Apparat\Server\Ports\View\ViewInterface;
73
use Aura\Router\RouterContainer;
74
use Dotenv\Dotenv;
75
use Psr\Http\Message\ResponseInterface;
76
use TYPO3Fluid\Fluid\View\AbstractTemplateView;
77
use Zend\Diactoros\Response;
78
79
/**
80
 * Object module
81
 *
82
 * @package Apparat\Object
83
 * @subpackage Apparat\Object
84
 */
85
class Module extends AbstractModule
86
{
87
    /**
88
     * Module name
89
     *
90
     * @var string
91
     */
92
    const NAME = 'server';
93
94
    /**
95
     * Validate the environment
96
     *
97
     * @param Dotenv $environment Environment
98
     */
99
    protected static function validateEnvironment(Dotenv $environment)
100
    {
101
        parent::validateEnvironment($environment);
102
103
        // Validate the required environment variables
104
//        $environment->required('APPARAT_BASE_URL')->notEmpty();
105
//        $environment->required('OBJECT_DATE_PRECISION')->isInteger()->allowedValues([0, 1, 2, 3, 4, 5, 6]);
106
    }
107
108
    /**
109
     * Configure the dependency injection container
110
     *
111
     * @param DependencyInjectionContainerInterface $diContainer Dependency injection container
112
     * @return void
113
     */
114
    public function configureDependencyInjection(DependencyInjectionContainerInterface $diContainer)
115
    {
116
        parent::configureDependencyInjection($diContainer);
117
118
        // Configure the server
119
        $diContainer->register(Server::class, [
120
            'shared' => true,
121
            'substitutions' => [
122
                RouterContainerInterface::class => [
123
                    'instance' => AuraRouterAdapter::class,
124
                ]
125
            ]
126
        ]);
127
128
        // Configure the router
129
        $diContainer->register(RouterContainer::class, [
130
            'constructParams' => [
131
                parse_url(getenv('APPARAT_BASE_URL'), PHP_URL_PATH) ?: null
132
            ]
133
        ]);
134
135
        // Configure the responder: Diactoros Response and TYPO3Fluid template view
136
        $diContainer->register(AbstractResponder::class, [
137
            'substitutions' => [
138
                ResponseInterface::class => [
139
                    'instance' => Response::class,
140
                ],
141
                ViewInterface::class => [
142
                    'instance' => TYPO3FluidView::class,
143
                ]
144
            ]
145
        ]);
146
147
        // Configure the TYPO3Fluid template view
148
        $diContainer->register(AbstractTemplateView::class, [
149
            'constructParams' => [null]
150
        ]);
151
152
        // Configure the action dependencies
153
        $this->configureActionDependencies($diContainer);
154
    }
155
156
    /**
157
     * Configure the action dependencies
158
     *
159
     * @param DependencyInjectionContainerInterface $diContainer Dependency injection container
160
     */
161
    protected function configureActionDependencies(DependencyInjectionContainerInterface $diContainer)
162
    {
163
        $diContainer->register(YearAction::class, [
164
            'substitutions' => [
165
                ServiceInterface::class => [
166
                    'instance' => YearService::class,
167
                ],
168
                ResponderInterface::class => [
169
                    'instance' => YearResponder::class,
170
                ]
171
            ]
172
        ]);
173
        $diContainer->register(MonthAction::class, [
174
            'substitutions' => [
175
                ServiceInterface::class => [
176
                    'instance' => MonthService::class,
177
                ],
178
                ResponderInterface::class => [
179
                    'instance' => MonthResponder::class,
180
                ]
181
            ]
182
        ]);
183
        $diContainer->register(DayAction::class, [
184
            'substitutions' => [
185
                ServiceInterface::class => [
186
                    'instance' => DayService::class,
187
                ],
188
                ResponderInterface::class => [
189
                    'instance' => DayResponder::class,
190
                ]
191
            ]
192
        ]);
193
        $diContainer->register(HourAction::class, [
194
            'substitutions' => [
195
                ServiceInterface::class => [
196
                    'instance' => HourService::class,
197
                ],
198
                ResponderInterface::class => [
199
                    'instance' => HourResponder::class,
200
                ]
201
            ]
202
        ]);
203
        $diContainer->register(MinuteAction::class, [
204
            'substitutions' => [
205
                ServiceInterface::class => [
206
                    'instance' => MinuteService::class,
207
                ],
208
                ResponderInterface::class => [
209
                    'instance' => MinuteResponder::class,
210
                ]
211
            ]
212
        ]);
213
        $diContainer->register(SecondAction::class, [
214
            'substitutions' => [
215
                ServiceInterface::class => [
216
                    'instance' => SecondService::class,
217
                ],
218
                ResponderInterface::class => [
219
                    'instance' => SecondResponder::class,
220
                ]
221
            ]
222
        ]);
223
        $diContainer->register(ObjectAction::class, [
224
            'substitutions' => [
225
                ServiceInterface::class => [
226
                    'instance' => ObjectService::class,
227
                ],
228
                ResponderInterface::class => [
229
                    'instance' => ObjectResponder::class,
230
                ]
231
            ]
232
        ]);
233
        $diContainer->register(TypeAction::class, [
234
            'substitutions' => [
235
                ServiceInterface::class => [
236
                    'instance' => TypeService::class,
237
                ],
238
                ResponderInterface::class => [
239
                    'instance' => TypeResponder::class,
240
                ]
241
            ]
242
        ]);
243
    }
244
}
245