Completed
Push — master ( e4436e...70eef2 )
by Lukas
14:47
created

Application   C

Complexity

Total Complexity 3

Size/Duplication

Total Lines 132
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 19

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 132
rs 6.875
wmc 3
lcom 0
cbo 19

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerMountProviders() 0 7 1
B __construct() 0 122 2
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Bjoern Schiessle <[email protected]>
6
 * @author Björn Schießle <[email protected]>
7
 * @author Joas Schilling <[email protected]>
8
 * @author Lukas Reschke <[email protected]>
9
 * @author Robin Appelman <[email protected]>
10
 * @author Roeland Jago Douma <[email protected]>
11
 *
12
 * @license AGPL-3.0
13
 *
14
 * This code is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License, version 3,
16
 * as published by the Free Software Foundation.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
 * GNU Affero General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License, version 3,
24
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
25
 *
26
 */
27
28
namespace OCA\Files_Sharing\AppInfo;
29
30
use OCA\FederatedFileSharing\DiscoveryManager;
31
use OCA\Files_Sharing\API\Share20OCS;
32
use OCA\Files_Sharing\Middleware\OCSShareAPIMiddleware;
33
use OCA\Files_Sharing\MountProvider;
34
use OCP\AppFramework\App;
35
use OC\AppFramework\Utility\SimpleContainer;
36
use OCA\Files_Sharing\Controllers\ExternalSharesController;
37
use OCA\Files_Sharing\Controllers\ShareController;
38
use OCA\Files_Sharing\Middleware\SharingCheckMiddleware;
39
use \OCP\IContainer;
40
41
class Application extends App {
42
	public function __construct(array $urlParams = array()) {
43
		parent::__construct('files_sharing', $urlParams);
44
45
		$container = $this->getContainer();
46
		$server = $container->getServer();
47
48
		/**
49
		 * Controllers
50
		 */
51
		$container->registerService('ShareController', function (SimpleContainer $c) use ($server) {
52
			$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
53
			return new ShareController(
54
				$c->query('AppName'),
55
				$c->query('Request'),
56
				$server->getConfig(),
57
				$server->getURLGenerator(),
58
				$server->getUserManager(),
59
				$server->getLogger(),
60
				$server->getActivityManager(),
61
				$server->getShareManager(),
62
				$server->getSession(),
63
				$server->getPreviewManager(),
64
				$server->getRootFolder(),
65
				$federatedSharingApp->getFederatedShareProvider(),
66
				$server->getEventDispatcher()
67
			);
68
		});
69
		$container->registerService('ExternalSharesController', function (SimpleContainer $c) {
70
			return new ExternalSharesController(
71
				$c->query('AppName'),
72
				$c->query('Request'),
73
				$c->query('ExternalManager'),
74
				$c->query('HttpClientService')
75
			);
76
		});
77
		$container->registerService('ShareAPIController', function (SimpleContainer $c) use ($server) {
78
			return new Share20OCS(
79
				$c->query('AppName'),
80
				$c->query('Request'),
81
				$server->getShareManager(),
82
				$server->getGroupManager(),
83
				$server->getUserManager(),
84
				$server->getRootFolder(),
85
				$server->getURLGenerator(),
86
				$server->getUserSession()->getUser(),
87
				$server->getL10N($c->query('AppName'))
88
			);
89
		});
90
91
		/**
92
		 * Core class wrappers
93
		 */
94
		$container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
95
			return $server->getHTTPClientService();
96
		});
97
		$container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
98
			$user = $server->getUserSession()->getUser();
99
			$uid = $user ? $user->getUID() : null;
100
			$discoveryManager = new DiscoveryManager(
101
				\OC::$server->getMemCacheFactory(),
102
				\OC::$server->getHTTPClientService()
103
			);
104
			return new \OCA\Files_Sharing\External\Manager(
105
				$server->getDatabaseConnection(),
106
				\OC\Files\Filesystem::getMountManager(),
107
				\OC\Files\Filesystem::getLoader(),
108
				$server->getHTTPHelper(),
109
				$server->getNotificationManager(),
110
				$discoveryManager,
111
				$uid
112
			);
113
		});
114
115
		/**
116
		 * Middleware
117
		 */
118
		$container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) {
119
			return new SharingCheckMiddleware(
120
				$c->query('AppName'),
121
				$server->getConfig(),
122
				$server->getAppManager(),
123
				$c['ControllerMethodReflector']
124
			);
125
		});
126
127
		$container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) {
128
			return new OCSShareAPIMiddleware(
129
				$server->getShareManager(),
130
				$server->getL10N($c->query('AppName'))
131
			);
132
		});
133
134
		// Execute middlewares
135
		$container->registerMiddleware('SharingCheckMiddleware');
136
		$container->registerMiddleWare('OCSShareAPIMiddleware');
137
138
		$container->registerService('MountProvider', function (IContainer $c) {
139
			/** @var \OCP\IServerContainer $server */
140
			$server = $c->query('ServerContainer');
141
			return new MountProvider(
142
				$server->getConfig(),
143
				$server->getShareManager(),
144
				$server->getLogger()
145
			);
146
		});
147
148
		$container->registerService('ExternalMountProvider', function (IContainer $c) {
149
			/** @var \OCP\IServerContainer $server */
150
			$server = $c->query('ServerContainer');
151
			return new \OCA\Files_Sharing\External\MountProvider(
152
				$server->getDatabaseConnection(),
153
				function() use ($c) {
154
					return $c->query('ExternalManager');
155
				}
156
			);
157
		});
158
159
		/*
160
		 * Register capabilities
161
		 */
162
		$container->registerCapability('OCA\Files_Sharing\Capabilities');
163
	}
164
165
	public function registerMountProviders() {
166
		/** @var \OCP\IServerContainer $server */
167
		$server = $this->getContainer()->query('ServerContainer');
168
		$mountProviderCollection = $server->getMountProviderCollection();
169
		$mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider'));
170
		$mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider'));
171
	}
172
}
173