Chart::registerServices()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 10
Bugs 3 Features 1
Metric Value
c 10
b 3
f 1
dl 0
loc 35
rs 8.8571
cc 1
eloc 23
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (c) 2014 - Arno van Rossum <[email protected]>
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to deal
7
 * in the Software without restriction, including without limitation the rights
8
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in
13
 * all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 */
23
24
namespace OCA\ocUsageCharts\AppInfo;
25
26
use OCA\ocUsageCharts\ChartTypeAdapterFactory;
27
use OCA\ocUsageCharts\Controller\ChartApiController;
28
use OCA\ocUsageCharts\Controller\ChartController;
29
use OCA\ocUsageCharts\DataProviderFactory;
30
use OCA\ocUsageCharts\DataProviders\ChartUsageHelper;
31
use OCA\ocUsageCharts\Entity\Activity\ActivityUsageRepository;
32
use OCA\ocUsageCharts\Entity\ChartConfigRepository;
33
use OCA\ocUsageCharts\Entity\Storage\StorageUsageRepository;
34
use OCA\ocUsageCharts\Owncloud\Storage;
35
use OCA\ocUsageCharts\Owncloud\User;
36
use OCA\ocUsageCharts\Owncloud\Users;
37
use OCA\ocUsageCharts\Service\ChartConfigService;
38
use OCA\ocUsageCharts\Service\ChartCreator;
39
use OCA\ocUsageCharts\Service\ChartDataProvider;
40
use OCA\ocUsageCharts\Service\ChartService;
41
use OCA\ocUsageCharts\Service\ChartUpdaterService;
42
use \OCP\AppFramework\App;
43
use OCP\AppFramework\IAppContainer;
44
45
/**
46
 * @author Arno van Rossum <[email protected]>
47
 */
48
class Chart extends App
49
{
50
    /**
51
     * @var IAppContainer
52
     */
53
    private $container;
54
55
    public function __construct(array $urlParams = array())
56
    {
57
        parent::__construct('ocusagecharts', $urlParams);
58
        $this->container = $this->getContainer();
59
        $this->registerRepositories();
60
        $this->registerOwncloudDependencies();
61
        $this->registerVarious();
62
        $this->registerServices();
63
    }
64
65
    /**
66
     * Owncloud dependencies, cause i don't want them in my code
67
     * @return void
68
     */
69
    private function registerOwncloudDependencies()
70
    {
71
        // Plural form
72
        $this->container->registerService('OwncloudUsers', function() {
73
            return new Users();
74
        });
75
        $this->container->registerService('OwncloudUser', function() {
76
            return new User();
77
        });
78
        $this->container->registerService('OwncloudStorage', function($c) {
79
            return new Storage(
80
                $c->query('OwncloudUser')
81
            );
82
        });
83
    }
84
85
    /**
86
     * Register all repositories
87
     * @return void
88
     */
89
    private function registerRepositories()
90
    {
91
        $this->container->registerService('ActivityUsageRepository', function($c) {
92
            return new ActivityUsageRepository(
93
                $c->query('ServerContainer')->getDb()
94
            );
95
        });
96
97
        $this->container->registerService('StorageUsageRepository', function($c) {
98
            return new StorageUsageRepository(
99
                $c->query('ServerContainer')->getDb()
100
            );
101
        });
102
        $this->container->registerService('ChartConfigRepository', function($c) {
103
            return new ChartConfigRepository(
104
                $c->query('ServerContainer')->getDb()
105
            );
106
        });
107
    }
108
109
    /**
110
     * @return void
111
     */
112
    private function registerVarious()
113
    {
114
        $this->container->registerService('ChartController', function($c) {
115
            return new ChartController(
116
                $c->query('AppName'),
117
                $c->query('Request'),
118
                $c->query('ChartService'),
119
                $c->query('ChartConfigService'),
120
                $c->query('ChartCreator'),
121
                $c->query('OwncloudUser')
122
            );
123
        });
124
        $this->container->registerService('ChartApiController', function($c) {
125
            return new ChartApiController(
126
                $c->query('AppName'),
127
                $c->query('Request'),
128
                $c->query('ChartService')
129
            );
130
        });
131
132
        $this->container->registerService('ChartTypeAdapterFactory', function($c) {
133
            return new ChartTypeAdapterFactory(
134
                $c->query('OwncloudUser')
135
            );
136
        });
137
        $this->container->registerService('DataProviderFactory', function($c) {
138
            return new DataProviderFactory(
139
                $c->query('StorageUsageRepository'),
140
                $c->query('ActivityUsageRepository'),
141
                $c->query('OwncloudUser'),
142
                $c->query('OwncloudStorage'),
143
                $c->query('ChartUsageHelper'),
144
                $c->query('OwncloudUsers')
145
            );
146
        });
147
        $this->container->registerService('ChartUsageHelper', function() {
148
            return new ChartUsageHelper();
149
        });
150
151
    }
152
153
    /**
154
     * Register all services
155
     * @return void
156
     */
157
    private function registerServices()
158
    {
159
        $this->container->registerService('ChartUpdaterService', function($c) {
160
            return new ChartUpdaterService(
161
                $c->query('ChartDataProvider'),
162
                $c->query('ChartConfigService'),
163
                $c->query('OwncloudUsers')
164
            );
165
        });
166
        $this->container->registerService('ChartCreator', function($c) {
167
            return new ChartCreator(
168
                $c->query('ChartConfigRepository'),
169
                $c->query('OwncloudUsers')
170
            );
171
        });
172
        $this->container->registerService('ChartConfigService', function($c) {
173
            return new ChartConfigService(
174
                $c->query('ChartConfigRepository'),
175
                $c->query('OwncloudUser')
176
            );
177
        });
178
        $this->container->registerService('ChartService', function($c) {
179
            return new ChartService(
180
                $c->query('ChartDataProvider'),
181
                $c->query('ChartConfigService'),
182
                $c->query('ChartTypeAdapterFactory')
183
            );
184
        });
185
        $this->container->registerService('ChartDataProvider', function($c) {
186
            return new ChartDataProvider(
187
                $c->query('DataProviderFactory'),
188
                $c->query('ChartTypeAdapterFactory')
189
            );
190
        });
191
    }
192
}