Completed
Pull Request — master (#1253)
by
unknown
03:26
created

Application   B

Complexity

Total Complexity 2

Size/Duplication

Total Lines 190
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 17

Test Coverage

Coverage 20.83%

Importance

Changes 6
Bugs 3 Features 4
Metric Value
wmc 2
c 6
b 3
f 4
lcom 0
cbo 17
dl 0
loc 190
ccs 25
cts 120
cp 0.2083
rs 7.8571

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 186 2
1
<?php
2
/**
3
 * ownCloud - mail
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Thomas Müller <[email protected]>
9
 * @copyright Thomas Müller 2014
10
 */
11
12
namespace OCA\Mail\AppInfo;
13
14
use OCA\Mail\Controller\AccountsController;
15
use OCA\Mail\Controller\FoldersController;
16
use OCA\Mail\Controller\MessagesController;
17
use OCA\Mail\Controller\ProxyController;
18
use OCA\Mail\Db\MailAccountMapper;
19
use OCA\Mail\Service\AccountService;
20
use OCA\Mail\Service\AutoConfig\AutoConfig;
21
use OCA\Mail\Service\AutoConfig\ImapConnectivityTester;
22
use OCA\Mail\Service\AutoConfig\ImapConnector;
23
use OCA\Mail\Service\AutoConfig\ImapServerDetector;
24
use OCA\Mail\Service\AutoConfig\MozillaIspDb;
25
use OCA\Mail\Service\AutoConfig\MxRecord;
26
use OCA\Mail\Service\AutoConfig\SmtpConnectivityTester;
27
use OCA\Mail\Service\AutoConfig\SmtpServerDetector;
28
use OCA\Mail\Service\ContactsIntegration;
29
use OCA\Mail\Service\Logger;
30
use \OCP\AppFramework\App;
31
use \OCA\Mail\Controller\PageController;
32
use OCP\AppFramework\IAppContainer;
33
34
class Application extends App {
35
36 1
	public function __construct (array $urlParams=array()) {
37 1
		parent::__construct('mail', $urlParams);
38
39 1
		$container = $this->getContainer();
40
41
		/**
42
		 * Controllers
43
		 */
44
		$container->registerService('PageController', function($c) {
45
			/** @var IAppContainer $c */
46
			return new PageController(
47
				$c->query('AppName'),
48
				$c->query('Request'),
49
				$c->query('MailAccountMapper'),
50
				$c->query('ServerContainer')->getURLGenerator(),
51
				$c->query('UserId')
52
			);
53 1
		});
54
55
		$container->registerService('AccountService', function($c) {
56
			/** @var IAppContainer $c */
57
			return new AccountService(
58
				$c->query('MailAccountMapper'),
59
				$c->getServer()->getL10N('mail')
60
			);
61 1
		});
62
63
		$container->registerService('AccountsController', function($c) {
64
			/** @var IAppContainer $c */
65
			return new AccountsController(
66
				$c->query('AppName'),
67
				$c->query('Request'),
68
				$c->query('AccountService'),
69
				$c->query('UserId'),
70
				$c->getServer()->getUserFolder(),
71
				$c->query('ContactsIntegration'),
72
				$c->query('AutoConfig'),
73
				$c->query('Logger'),
74
				$c->getServer()->getL10N('mail'),
75
				$c->getServer()->getCrypto()
76
			);
77 1
		});
78
79
		$container->registerService('FoldersController', function($c) {
80
			/** @var IAppContainer $c */
81
			return new FoldersController(
82
				$c->query('AppName'),
83
				$c->query('Request'),
84
				$c->query('AccountService'),
85
				$c->query('UserId')
86
			);
87 1
		});
88
89
		$container->registerService('MessagesController', function($c) {
90
			/** @var IAppContainer $c */
91
			return new MessagesController(
92
				$c->query('AppName'),
93
				$c->query('Request'),
94
				$c->query('AccountService'),
95
				$c->query('UserId'),
96
				$c->getServer()->getUserFolder(),
97
				$c->query('ContactsIntegration'),
98
				$c->query('Logger'),
99
				$c->getServer()->getL10N('mail')
100
			);
101 1
		});
102
103
		$container->registerService('ProxyController', function($c) {
104
			/** @var IAppContainer $c */
105
			return new ProxyController(
106
				$c->query('AppName'),
107
				$c->query('Request'),
108
				$c->query('ServerContainer')->getURLGenerator(),
109
				$c->query('ServerContainer')->getSession(),
110
				$c->getServer()->getHelper(),
111
				isset($_SERVER['HTTP_REFERER']) ? : null,
112
				\OCP\Util::getServerHostName()
113
			);
114 1
		});
115
116
		/**
117
		 * Mappers
118
		 */
119
		$container->registerService('MailAccountMapper', function ($c) {
120
			/** @var IAppContainer $c */
121
			return new MailAccountMapper($c->getServer()->getDb());
122 1
		});
123
124
		/**
125
		 * Services
126
		 */
127
		$container->registerService('ContactsIntegration', function ($c) {
128
			/** @var IAppContainer $c */
129
			return new ContactsIntegration($c->getServer()->getContactsManager());
130 1
		});
131
132
		$container->registerService('ImapConnectivityTester', function($c) {
133
			/** @var IAppContainer $c */
134 1
			return new ImapConnectivityTester(
135
				$c->query('ImapConnector'),
136
				$c->query('Logger'),
137 1
				$c->query('UserId')
138
			);
139 1
		});
140
141
		$container->registerService('ImapConnector', function($c) {
142
			/** @var IAppContainer $c */
143
			return new ImapConnector(
144
				$c->getServer()->getCrypto(),
145
				$c->query('Logger'),
146
				$c->query('UserId')
147
			);
148 1
		});
149
150
		$container->registerService('ImapServerDetector', function($c) {
151
			/** @var IAppContainer $c */
152
			return new ImapServerDetector(
153
				$c->query('MxRecord'),
154
				$c->query('ImapConnectivityTester')
155
			);
156 1
		});
157
158
		$container->registerService('SmtpConnectivityTester', function($c) {
159
			/** @var IAppContainer $c */
160
			return new SmtpConnectivityTester(
161
				$c->getServer()->getCrypto(),
162
				$c->query('Logger'),
163
				$c->query('UserId')
164
			);
165 1
		});
166
167
		$container->registerService('SmtpServerDetector', function($c) {
168
			$transport = $c->getServer()->getConfig()->getSystemValue('app.mail.transport', 'smtp');
169
			/** @var IAppContainer $c */
170
			return new SmtpServerDetector(
171
				$c->query('MxRecord'),
172
				$c->query('SmtpConnectivityTester'),
173
				$transport === 'smtp'
174
			);
175 1
		});
176
177
		$container->registerService('MozillaIspDb', function($c) {
178
			/** @var IAppContainer $c */
179
			return new MozillaIspDb(
180
				$c->query('Logger')
181
			);
182 1
		});
183
184
		$container->registerService('MxRecord', function($c) {
185
			/** @var IAppContainer $c */
186
			return new MxRecord(
187
				$c->query('Logger')
188
			);
189 1
		});
190
191
		$container->registerService('AutoConfig', function ($c) {
192
			/** @var IAppContainer $c */
193
			return new AutoConfig(
194
				$c->query('Logger'),
195
				$c->query('UserId'),
196
				$c->query('MozillaIspDb'),
197
				$c->query('MxRecord'),
198
				$c->query('ImapConnectivityTester'),
199
				$c->query('ImapServerDetector'),
200
				$c->query('SmtpConnectivityTester'),
201
				$c->query('SmtpServerDetector'),
202
				$c->query('ImapConnector'),
203
				$c->getServer()->getCrypto()
204
			);
205 1
		});
206
207
		$container->registerService('Logger', function ($c) {
208
			/** @var IAppContainer $c */
209
			return new Logger(
210
				$c->query('AppName'),
211
				$c->query('ServerContainer')->getLogger()
212
			);
213 1
		});
214
215
		/**
216
		 * Core
217
		 */
218 1
		$container->registerService('UserId', function() {
219
			return \OCP\User::getUser();
220 1
		});
221 1
	}
222
223
}
224