Application.php 4.6 KB
Newer Older
1
2
<?php
/**
Thomas Müller's avatar
Thomas Müller committed
3
 * @author Joas Schilling <coding@schilljs.com>
Jenkins for ownCloud's avatar
Jenkins for ownCloud committed
4
 * @author Morris Jobke <hey@morrisjobke.de>
Lukas Reschke's avatar
Lukas Reschke committed
5
 * @author Robin Appelman <icewind@owncloud.com>
Thomas Müller's avatar
Thomas Müller committed
6
 * @author Robin McCorkell <robin@mccorkell.me.uk>
Lukas Reschke's avatar
Lukas Reschke committed
7
 * @author Roeland Jago Douma <rullzer@owncloud.com>
Jenkins for ownCloud's avatar
Jenkins for ownCloud committed
8
9
10
 * @author Ross Nicoll <jrn@jrn.me.uk>
 * @author Vincent Petry <pvince81@owncloud.com>
 *
Thomas Müller's avatar
Thomas Müller committed
11
 * @copyright Copyright (c) 2016, ownCloud GmbH.
Jenkins for ownCloud's avatar
Jenkins for ownCloud committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
26
 */
27

28
namespace OCA\Files_External\AppInfo;
29
30

use \OCP\AppFramework\App;
31
use OCP\AppFramework\IAppContainer;
32
use \OCP\IContainer;
33
34
35
use \OCP\Files\External\IStoragesBackendService;
use \OCP\Files\External\Config\IBackendProvider;
use \OCP\Files\External\Config\IAuthMechanismProvider;
36

37
/**
38
 * @package OCA\Files_External\AppInfo
39
 */
40
41
class Application extends App implements IBackendProvider, IAuthMechanismProvider {

Thomas Müller's avatar
Thomas Müller committed
42
	public function __construct(array $urlParams = []) {
43
		parent::__construct('files_external', $urlParams);
44

45
46
47
		$container = $this->getContainer();

		$container->registerService('OCP\Files\Config\IUserMountCache', function (IAppContainer $c) {
48
49
			return $c->getServer()->query('UserMountCache');
		});
50
51
52
53
54
55
56
57
58
59
60
61
		$container->registerService('OCP\Files\External\IStoragesBackendService', function (IAppContainer $c) {
			return $c->getServer()->query('StoragesBackendService');
		});
		$container->registerService('OCP\Files\External\Service\IGlobalStoragesService', function (IAppContainer $c) {
			return $c->getServer()->query('OCP\Files\External\Service\IGlobalStoragesService');
		});
		$container->registerService('OCP\Files\External\Service\IUserGlobalStoragesService', function (IAppContainer $c) {
			return $c->getServer()->query('OCP\Files\External\Service\IUserGlobalStoragesService');
		});
		$container->registerService('OCP\Files\External\Service\IUserStoragesService', function (IAppContainer $c) {
			return $c->getServer()->query('OCP\Files\External\Service\IUserStoragesService');
		});
62

63
		$backendService = $container->getServer()->query('StoragesBackendService');
64
65
		$backendService->registerBackendProvider($this);
		$backendService->registerAuthMechanismProvider($this);
66
	}
67

68
69
70
71
72
	/**
	 * Register settings templates
	 */
	public function registerSettings() {
		\OCP\App::registerAdmin('files_external', 'settings');
73
		\OCP\App::registerPersonal('files_external', 'personal');
74
75
	}

76
	/**
77
	 * @{inheritdoc}
78
	 */
79
	public function getBackends() {
80
		$container = $this->getContainer();
81

82
		$backends = [
83
			$container->query('OCA\Files_External\Lib\Backend\DAV'),
84
			$container->query('OCA\Files_External\Lib\Backend\OwnCloud'),
85
			$container->query('OCA\Files_External\Lib\Backend\SFTP'),
86
			$container->query('OCA\Files_External\Lib\Backend\AmazonS3'),
87
			$container->query('OCA\Files_External\Lib\Backend\Dropbox'),
88
			$container->query('OCA\Files_External\Lib\Backend\Google'),
89
			$container->query('OCA\Files_External\Lib\Backend\Swift'),
90
			$container->query('OCA\Files_External\Lib\Backend\SFTP_Key'),
91
92
			$container->query('OCA\Files_External\Lib\Backend\SMB'),
			$container->query('OCA\Files_External\Lib\Backend\SMB_OC'),
93
		];
94

95
96
97
98
99
		$this->allowLocalMounts = \OC::$server->getConfig()->getSystemValue('files_external_allow_local', true);
		if ($this->allowLocalMounts === true) {
			$backends[] = $container->query('OCA\Files_External\Lib\Backend\Local');
		};

100
		return $backends;
101
102
	}

103
	/**
104
	 * @{inheritdoc}
105
	 */
106
	public function getAuthMechanisms() {
107
108
		$container = $this->getContainer();

109
		return [
110
111
112
			// AuthMechanism::SCHEME_OAUTH1 mechanisms
			$container->query('OCA\Files_External\Lib\Auth\OAuth1\OAuth1'),

113
114
115
			// AuthMechanism::SCHEME_OAUTH2 mechanisms
			$container->query('OCA\Files_External\Lib\Auth\OAuth2\OAuth2'),

116
117
118
			// AuthMechanism::SCHEME_PUBLICKEY mechanisms
			$container->query('OCA\Files_External\Lib\Auth\PublicKey\RSA'),

119
120
121
122
			// AuthMechanism::SCHEME_OPENSTACK mechanisms
			$container->query('OCA\Files_External\Lib\Auth\OpenStack\OpenStack'),
			$container->query('OCA\Files_External\Lib\Auth\OpenStack\Rackspace'),

123
124
			// Specialized mechanisms
			$container->query('OCA\Files_External\Lib\Auth\AmazonS3\AccessKey'),
125
		];
126
127
	}

128
}