Completed
Push — master ( cc1044...c261ff )
by Joschi
05:08
created

Module::configureDependencyInjection()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 38
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 38
ccs 0
cts 30
cp 0
rs 8.8571
cc 2
eloc 18
nc 1
nop 1
crap 6
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\Infrastructure\AuraRouterAdapter;
44
use Apparat\Server\Ports\Responder\AbstractResponder;
45
use Apparat\Server\Ports\Responder\View\TYPO3FluidView;
46
use Apparat\Server\Ports\Responder\View\ViewInterface;
47
use Aura\Router\RouterContainer;
48
use Dotenv\Dotenv;
49
use Psr\Http\Message\ResponseInterface;
50
use TYPO3Fluid\Fluid\View\AbstractTemplateView;
51
use Zend\Diactoros\Response;
52
53
/**
54
 * Object module
55
 *
56
 * @package Apparat\Object
57
 * @subpackage Apparat\Object
58
 */
59
class Module extends AbstractModule
60
{
61
    /**
62
     * Module name
63
     *
64
     * @var string
65
     */
66
    const NAME = 'server';
67
68
    /**
69
     * Validate the environment
70
     *
71
     * @param Dotenv $environment Environment
72
     */
73
    protected static function validateEnvironment(Dotenv $environment)
74
    {
75
        parent::validateEnvironment($environment);
76
77
        // Validate the required environment variables
78
//        $environment->required('APPARAT_BASE_URL')->notEmpty();
79
//        $environment->required('OBJECT_DATE_PRECISION')->isInteger()->allowedValues([0, 1, 2, 3, 4, 5, 6]);
80
    }
81
82
    /**
83
     * Configure the dependency injection container
84
     *
85
     * @param DependencyInjectionContainerInterface $diContainer Dependency injection container
86
     * @return void
87
     */
88
    public function configureDependencyInjection(DependencyInjectionContainerInterface $diContainer)
89
    {
90
        parent::configureDependencyInjection($diContainer);
91
92
        // Configure the server
93
        $diContainer->register(Server::class, [
94
            'shared' => true,
95
            'substitutions' => [
96
                RouterContainerInterface::class => [
97
                    'instance' => AuraRouterAdapter::class,
98
                ]
99
            ]
100
        ]);
101
102
        // Configure the server
103
        $diContainer->register(RouterContainer::class, [
104
            'constructParams' => [
105
                parse_url(getenv('APPARAT_BASE_URL'), PHP_URL_PATH) ?: null
106
            ]
107
        ]);
108
109
        // Configure the responder: Diactoros Response and TYPO3Fluid template view
110
        $diContainer->register(AbstractResponder::class, [
111
            'substitutions' => [
112
                ResponseInterface::class => [
113
                    'instance' => Response::class,
114
                ],
115
                ViewInterface::class => [
116
                    'instance' => TYPO3FluidView::class,
117
                ]
118
            ]
119
        ]);
120
121
        // Configure the TYPO3Fluid template view
122
        $diContainer->register(AbstractTemplateView::class, [
123
            'constructParams' => [null]
124
        ]);
125
    }
126
}
127