Passed
Push — master ( 3a1e90...7b8289 )
by Morris
24:40 queued 12:55
created

Application   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 44
c 1
b 0
f 0
dl 0
loc 77
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 36 2
A registerBackendDependents() 0 7 1
A __construct() 0 24 1
A register() 0 1 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Roger Szabo <[email protected]>
4
 *
5
 * @author Arthur Schiwon <[email protected]>
6
 * @author Christoph Wurst <[email protected]>
7
 * @author Morris Jobke <[email protected]>
8
 * @author Roger Szabo <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\User_LDAP\AppInfo;
28
29
use OCA\Files_External\Service\BackendService;
30
use OCA\User_LDAP\Controller\RenewPasswordController;
31
use OCA\User_LDAP\Group_Proxy;
32
use OCA\User_LDAP\GroupPluginManager;
33
use OCA\User_LDAP\Handler\ExtStorageConfigHandler;
34
use OCA\User_LDAP\Helper;
35
use OCA\User_LDAP\ILDAPWrapper;
36
use OCA\User_LDAP\LDAP;
37
use OCA\User_LDAP\Notification\Notifier;
38
use OCA\User_LDAP\User_Proxy;
39
use OCA\User_LDAP\UserPluginManager;
40
use OCP\AppFramework\App;
41
use OCP\AppFramework\Bootstrap\IBootContext;
42
use OCP\AppFramework\Bootstrap\IBootstrap;
43
use OCP\AppFramework\Bootstrap\IRegistrationContext;
44
use OCP\AppFramework\IAppContainer;
45
use OCP\IL10N;
46
47
class Application extends App implements IBootstrap {
48
	public function __construct() {
49
		parent::__construct('user_ldap');
50
		$container = $this->getContainer();
51
52
		/**
53
		 * Controller
54
		 */
55
		$container->registerService('RenewPasswordController', function (IAppContainer $c) {
56
			/** @var \OC\Server $server */
57
			$server = $c->query('ServerContainer');
58
59
			return new RenewPasswordController(
60
				$c->getAppName(),
61
				$server->getRequest(),
62
				$c->query('UserManager'),
63
				$server->getConfig(),
64
				$c->query(IL10N::class),
65
				$c->query('Session'),
66
				$server->getURLGenerator()
67
			);
68
		});
69
70
		$container->registerService(ILDAPWrapper::class, function () {
71
			return new LDAP();
72
		});
73
	}
74
75
	public function register(IRegistrationContext $context): void {
76
	}
77
78
	public function boot(IBootContext $context): void {
79
		$server = $context->getServerContainer();
80
		$config = $server->getConfig();
81
82
		$helper = new Helper($config);
83
		$configPrefixes = $helper->getServerConfigurationPrefixes(true);
84
		if (count($configPrefixes) > 0) {
85
			$ldapWrapper = new LDAP();
86
87
			$notificationManager = $server->getNotificationManager();
88
			$notificationManager->registerNotifierService(Notifier::class);
89
			$userSession = $server->getUserSession();
90
91
			$userPluginManager = $server->query(UserPluginManager::class);
92
			$groupPluginManager = $server->query(GroupPluginManager::class);
93
94
			$userBackend  = new User_Proxy(
95
				$configPrefixes, $ldapWrapper, $config, $notificationManager, $userSession, $userPluginManager
96
			);
97
			$groupBackend  = new Group_Proxy($configPrefixes, $ldapWrapper, $groupPluginManager);
98
			// register user backend
99
			\OC_User::useBackend($userBackend);
100
101
			// Hook to allow plugins to work on registered backends
102
			$server->getEventDispatcher()->dispatch('OCA\\User_LDAP\\User\\User::postLDAPBackendAdded');
0 ignored issues
show
Bug introduced by
'OCA\User_LDAP\User\User::postLDAPBackendAdded' of type string is incompatible with the type object expected by parameter $event of Symfony\Contracts\EventD...erInterface::dispatch(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

102
			$server->getEventDispatcher()->dispatch(/** @scrutinizer ignore-type */ 'OCA\\User_LDAP\\User\\User::postLDAPBackendAdded');
Loading history...
Deprecated Code introduced by
The function OCP\IServerContainer::getEventDispatcher() has been deprecated: 20.0.0 use \OCP\EventDispatcher\IEventDispatcher ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

102
			/** @scrutinizer ignore-deprecated */ $server->getEventDispatcher()->dispatch('OCA\\User_LDAP\\User\\User::postLDAPBackendAdded');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
103
104
			$server->getGroupManager()->addBackend($groupBackend);
105
106
			$this->registerBackendDependents($context->getAppContainer());
107
		}
108
109
		\OCP\Util::connectHook(
110
			'\OCA\Files_Sharing\API\Server2Server',
111
			'preLoginNameUsedAsUserName',
112
			'\OCA\User_LDAP\Helper',
113
			'loginName2UserName'
114
		);
115
	}
116
117
	public function registerBackendDependents(IAppContainer $appContainer) {
118
		$appContainer->getServer()->getEventDispatcher()->addListener(
0 ignored issues
show
Deprecated Code introduced by
The function OCP\IServerContainer::getEventDispatcher() has been deprecated: 20.0.0 use \OCP\EventDispatcher\IEventDispatcher ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

118
		/** @scrutinizer ignore-deprecated */ $appContainer->getServer()->getEventDispatcher()->addListener(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
119
			'OCA\\Files_External::loadAdditionalBackends',
120
			function () use ($appContainer) {
121
				$storagesBackendService = $appContainer->query(BackendService::class);
122
				$storagesBackendService->registerConfigHandler('home', function () use ($appContainer) {
123
					return $appContainer->query(ExtStorageConfigHandler::class);
124
				});
125
			}
126
		);
127
	}
128
}
129