Completed
Pull Request — master (#4336)
by Lukas
11:09
created
lib/private/Security/RateLimiting/Limiter.php 2 patches
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -30,77 +30,77 @@
 block discarded – undo
30 30
 use OCP\IUserSession;
31 31
 
32 32
 class Limiter {
33
-	/** @var IBackend */
34
-	private $backend;
35
-	/** @var ITimeFactory */
36
-	private $timeFactory;
33
+    /** @var IBackend */
34
+    private $backend;
35
+    /** @var ITimeFactory */
36
+    private $timeFactory;
37 37
 
38
-	/**
39
-	 * @param IUserSession $userSession
40
-	 * @param IRequest $request
41
-	 * @param ITimeFactory $timeFactory
42
-	 * @param IBackend $backend
43
-	 */
44
-	public function __construct(IUserSession $userSession,
45
-								IRequest $request,
46
-								ITimeFactory $timeFactory,
47
-								IBackend $backend) {
48
-		$this->backend = $backend;
49
-		$this->timeFactory = $timeFactory;
50
-	}
38
+    /**
39
+     * @param IUserSession $userSession
40
+     * @param IRequest $request
41
+     * @param ITimeFactory $timeFactory
42
+     * @param IBackend $backend
43
+     */
44
+    public function __construct(IUserSession $userSession,
45
+                                IRequest $request,
46
+                                ITimeFactory $timeFactory,
47
+                                IBackend $backend) {
48
+        $this->backend = $backend;
49
+        $this->timeFactory = $timeFactory;
50
+    }
51 51
 
52
-	/**
53
-	 * @param string $methodIdentifier
54
-	 * @param string $userIdentifier
55
-	 * @param int $period
56
-	 * @param int $limit
57
-	 * @throws RateLimitExceededException
58
-	 */
59
-	private function register($methodIdentifier,
60
-							  $userIdentifier,
61
-							  $period,
62
-							  $limit) {
63
-		$existingAttempts = $this->backend->getAttempts($methodIdentifier, $userIdentifier, (int)$period);
64
-		if ($existingAttempts >= (int)$limit) {
65
-			throw new RateLimitExceededException();
66
-		}
52
+    /**
53
+     * @param string $methodIdentifier
54
+     * @param string $userIdentifier
55
+     * @param int $period
56
+     * @param int $limit
57
+     * @throws RateLimitExceededException
58
+     */
59
+    private function register($methodIdentifier,
60
+                                $userIdentifier,
61
+                                $period,
62
+                                $limit) {
63
+        $existingAttempts = $this->backend->getAttempts($methodIdentifier, $userIdentifier, (int)$period);
64
+        if ($existingAttempts >= (int)$limit) {
65
+            throw new RateLimitExceededException();
66
+        }
67 67
 
68
-		$this->backend->registerAttempt($methodIdentifier, $userIdentifier, $this->timeFactory->getTime());
69
-	}
68
+        $this->backend->registerAttempt($methodIdentifier, $userIdentifier, $this->timeFactory->getTime());
69
+    }
70 70
 
71
-	/**
72
-	 * Registers attempt for an anonymous request
73
-	 *
74
-	 * @param string $identifier
75
-	 * @param int $anonLimit
76
-	 * @param int $anonPeriod
77
-	 * @param string $ip
78
-	 * @throws RateLimitExceededException
79
-	 */
80
-	public function registerAnonRequest($identifier,
81
-										$anonLimit,
82
-										$anonPeriod,
83
-										$ip) {
84
-		$ipSubnet = (new IpAddress($ip))->getSubnet();
71
+    /**
72
+     * Registers attempt for an anonymous request
73
+     *
74
+     * @param string $identifier
75
+     * @param int $anonLimit
76
+     * @param int $anonPeriod
77
+     * @param string $ip
78
+     * @throws RateLimitExceededException
79
+     */
80
+    public function registerAnonRequest($identifier,
81
+                                        $anonLimit,
82
+                                        $anonPeriod,
83
+                                        $ip) {
84
+        $ipSubnet = (new IpAddress($ip))->getSubnet();
85 85
 
86
-		$anonHashIdentifier = hash('sha512', 'anon::' . $identifier . $ipSubnet);
87
-		$this->register($identifier, $anonHashIdentifier, $anonPeriod, $anonLimit);
88
-	}
86
+        $anonHashIdentifier = hash('sha512', 'anon::' . $identifier . $ipSubnet);
87
+        $this->register($identifier, $anonHashIdentifier, $anonPeriod, $anonLimit);
88
+    }
89 89
 
90
-	/**
91
-	 * Registers attempt for an authenticated request
92
-	 *
93
-	 * @param string $identifier
94
-	 * @param int $userLimit
95
-	 * @param int $userPeriod
96
-	 * @param IUser $user
97
-	 * @throws RateLimitExceededException
98
-	 */
99
-	public function registerUserRequest($identifier,
100
-										$userLimit,
101
-										$userPeriod,
102
-										IUser $user) {
103
-		$userHashIdentifier = hash('sha512', 'user::' . $identifier . $user->getUID());
104
-		$this->register($identifier, $userHashIdentifier, $userPeriod, $userLimit);
105
-	}
90
+    /**
91
+     * Registers attempt for an authenticated request
92
+     *
93
+     * @param string $identifier
94
+     * @param int $userLimit
95
+     * @param int $userPeriod
96
+     * @param IUser $user
97
+     * @throws RateLimitExceededException
98
+     */
99
+    public function registerUserRequest($identifier,
100
+                                        $userLimit,
101
+                                        $userPeriod,
102
+                                        IUser $user) {
103
+        $userHashIdentifier = hash('sha512', 'user::' . $identifier . $user->getUID());
104
+        $this->register($identifier, $userHashIdentifier, $userPeriod, $userLimit);
105
+    }
106 106
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 							  $userIdentifier,
61 61
 							  $period,
62 62
 							  $limit) {
63
-		$existingAttempts = $this->backend->getAttempts($methodIdentifier, $userIdentifier, (int)$period);
64
-		if ($existingAttempts >= (int)$limit) {
63
+		$existingAttempts = $this->backend->getAttempts($methodIdentifier, $userIdentifier, (int) $period);
64
+		if ($existingAttempts >= (int) $limit) {
65 65
 			throw new RateLimitExceededException();
66 66
 		}
67 67
 
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 										$ip) {
84 84
 		$ipSubnet = (new IpAddress($ip))->getSubnet();
85 85
 
86
-		$anonHashIdentifier = hash('sha512', 'anon::' . $identifier . $ipSubnet);
86
+		$anonHashIdentifier = hash('sha512', 'anon::'.$identifier.$ipSubnet);
87 87
 		$this->register($identifier, $anonHashIdentifier, $anonPeriod, $anonLimit);
88 88
 	}
89 89
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 										$userLimit,
101 101
 										$userPeriod,
102 102
 										IUser $user) {
103
-		$userHashIdentifier = hash('sha512', 'user::' . $identifier . $user->getUID());
103
+		$userHashIdentifier = hash('sha512', 'user::'.$identifier.$user->getUID());
104 104
 		$this->register($identifier, $userHashIdentifier, $userPeriod, $userLimit);
105 105
 	}
106 106
 }
Please login to merge, or discard this patch.
lib/private/Security/RateLimiting/Exception/RateLimitExceededException.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 use OCP\AppFramework\Http;
26 26
 
27 27
 class RateLimitExceededException extends SecurityException {
28
-	public function __construct() {
29
-		parent::__construct('Rate limit exceeded', Http::STATUS_TOO_MANY_REQUESTS);
30
-	}
28
+    public function __construct() {
29
+        parent::__construct('Rate limit exceeded', Http::STATUS_TOO_MANY_REQUESTS);
30
+    }
31 31
 }
Please login to merge, or discard this patch.
lib/private/Security/Normalizer/IpAddress.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -28,79 +28,79 @@
 block discarded – undo
28 28
  * @package OC\Security\Normalizer
29 29
  */
30 30
 class IpAddress {
31
-	/** @var string */
32
-	private $ip;
31
+    /** @var string */
32
+    private $ip;
33 33
 
34
-	/**
35
-	 * @param string $ip IP to normalized
36
-	 */
37
-	public function __construct($ip) {
38
-		$this->ip = $ip;
39
-	}
34
+    /**
35
+     * @param string $ip IP to normalized
36
+     */
37
+    public function __construct($ip) {
38
+        $this->ip = $ip;
39
+    }
40 40
 
41
-	/**
42
-	 * Return the given subnet for an IPv4 address and mask bits
43
-	 *
44
-	 * @param string $ip
45
-	 * @param int $maskBits
46
-	 * @return string
47
-	 */
48
-	private function getIPv4Subnet($ip,
49
-								   $maskBits = 32) {
50
-		$binary = \inet_pton($ip);
51
-		for ($i = 32; $i > $maskBits; $i -= 8) {
52
-			$j = \intdiv($i, 8) - 1;
53
-			$k = (int) \min(8, $i - $maskBits);
54
-			$mask = (0xff - ((pow(2, $k)) - 1));
55
-			$int = \unpack('C', $binary[$j]);
56
-			$binary[$j] = \pack('C', $int[1] & $mask);
57
-		}
58
-		return \inet_ntop($binary).'/'.$maskBits;
59
-	}
41
+    /**
42
+     * Return the given subnet for an IPv4 address and mask bits
43
+     *
44
+     * @param string $ip
45
+     * @param int $maskBits
46
+     * @return string
47
+     */
48
+    private function getIPv4Subnet($ip,
49
+                                    $maskBits = 32) {
50
+        $binary = \inet_pton($ip);
51
+        for ($i = 32; $i > $maskBits; $i -= 8) {
52
+            $j = \intdiv($i, 8) - 1;
53
+            $k = (int) \min(8, $i - $maskBits);
54
+            $mask = (0xff - ((pow(2, $k)) - 1));
55
+            $int = \unpack('C', $binary[$j]);
56
+            $binary[$j] = \pack('C', $int[1] & $mask);
57
+        }
58
+        return \inet_ntop($binary).'/'.$maskBits;
59
+    }
60 60
 
61
-	/**
62
-	 * Return the given subnet for an IPv6 address and mask bits
63
-	 *
64
-	 * @param string $ip
65
-	 * @param int $maskBits
66
-	 * @return string
67
-	 */
68
-	private function getIPv6Subnet($ip, $maskBits = 48) {
69
-		$binary = \inet_pton($ip);
70
-		for ($i = 128; $i > $maskBits; $i -= 8) {
71
-			$j = \intdiv($i, 8) - 1;
72
-			$k = (int) \min(8, $i - $maskBits);
73
-			$mask = (0xff - ((pow(2, $k)) - 1));
74
-			$int = \unpack('C', $binary[$j]);
75
-			$binary[$j] = \pack('C', $int[1] & $mask);
76
-		}
77
-		return \inet_ntop($binary).'/'.$maskBits;
78
-	}
61
+    /**
62
+     * Return the given subnet for an IPv6 address and mask bits
63
+     *
64
+     * @param string $ip
65
+     * @param int $maskBits
66
+     * @return string
67
+     */
68
+    private function getIPv6Subnet($ip, $maskBits = 48) {
69
+        $binary = \inet_pton($ip);
70
+        for ($i = 128; $i > $maskBits; $i -= 8) {
71
+            $j = \intdiv($i, 8) - 1;
72
+            $k = (int) \min(8, $i - $maskBits);
73
+            $mask = (0xff - ((pow(2, $k)) - 1));
74
+            $int = \unpack('C', $binary[$j]);
75
+            $binary[$j] = \pack('C', $int[1] & $mask);
76
+        }
77
+        return \inet_ntop($binary).'/'.$maskBits;
78
+    }
79 79
 
80
-	/**
81
-	 * Gets either the /32 (IPv4) or the /128 (IPv6) subnet of an IP address
82
-	 *
83
-	 * @return string
84
-	 */
85
-	public function getSubnet() {
86
-		if (\preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $this->ip)) {
87
-			return $this->getIPv4Subnet(
88
-				$this->ip,
89
-				32
90
-			);
91
-		}
92
-		return $this->getIPv6Subnet(
93
-			$this->ip,
94
-			128
95
-		);
96
-	}
80
+    /**
81
+     * Gets either the /32 (IPv4) or the /128 (IPv6) subnet of an IP address
82
+     *
83
+     * @return string
84
+     */
85
+    public function getSubnet() {
86
+        if (\preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $this->ip)) {
87
+            return $this->getIPv4Subnet(
88
+                $this->ip,
89
+                32
90
+            );
91
+        }
92
+        return $this->getIPv6Subnet(
93
+            $this->ip,
94
+            128
95
+        );
96
+    }
97 97
 
98
-	/**
99
-	 * Returns the specified IP address
100
-	 *
101
-	 * @return string
102
-	 */
103
-	public function __toString() {
104
-		return $this->ip;
105
-	}
98
+    /**
99
+     * Returns the specified IP address
100
+     *
101
+     * @return string
102
+     */
103
+    public function __toString() {
104
+        return $this->ip;
105
+    }
106 106
 }
Please login to merge, or discard this patch.
lib/private/Security/Bruteforce/Throttler.php 2 patches
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -43,207 +43,207 @@
 block discarded – undo
43 43
  * @package OC\Security\Bruteforce
44 44
  */
45 45
 class Throttler {
46
-	const LOGIN_ACTION = 'login';
47
-
48
-	/** @var IDBConnection */
49
-	private $db;
50
-	/** @var ITimeFactory */
51
-	private $timeFactory;
52
-	/** @var ILogger */
53
-	private $logger;
54
-	/** @var IConfig */
55
-	private $config;
56
-
57
-	/**
58
-	 * @param IDBConnection $db
59
-	 * @param ITimeFactory $timeFactory
60
-	 * @param ILogger $logger
61
-	 * @param IConfig $config
62
-	 */
63
-	public function __construct(IDBConnection $db,
64
-								ITimeFactory $timeFactory,
65
-								ILogger $logger,
66
-								IConfig $config) {
67
-		$this->db = $db;
68
-		$this->timeFactory = $timeFactory;
69
-		$this->logger = $logger;
70
-		$this->config = $config;
71
-	}
72
-
73
-	/**
74
-	 * Convert a number of seconds into the appropriate DateInterval
75
-	 *
76
-	 * @param int $expire
77
-	 * @return \DateInterval
78
-	 */
79
-	private function getCutoff($expire) {
80
-		$d1 = new \DateTime();
81
-		$d2 = clone $d1;
82
-		$d2->sub(new \DateInterval('PT' . $expire . 'S'));
83
-		return $d2->diff($d1);
84
-	}
85
-
86
-	/**
87
-	 * Register a failed attempt to bruteforce a security control
88
-	 *
89
-	 * @param string $action
90
-	 * @param string $ip
91
-	 * @param array $metadata Optional metadata logged to the database
92
-	 */
93
-	public function registerAttempt($action,
94
-									$ip,
95
-									array $metadata = []) {
96
-		// No need to log if the bruteforce protection is disabled
97
-		if($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
98
-			return;
99
-		}
100
-
101
-		$ipAddress = new IpAddress($ip);
102
-		$values = [
103
-			'action' => $action,
104
-			'occurred' => $this->timeFactory->getTime(),
105
-			'ip' => (string)$ipAddress,
106
-			'subnet' => $ipAddress->getSubnet(),
107
-			'metadata' => json_encode($metadata),
108
-		];
109
-
110
-		$this->logger->notice(
111
-			sprintf(
112
-				'Bruteforce attempt from "%s" detected for action "%s".',
113
-				$ip,
114
-				$action
115
-			),
116
-			[
117
-				'app' => 'core',
118
-			]
119
-		);
120
-
121
-		$qb = $this->db->getQueryBuilder();
122
-		$qb->insert('bruteforce_attempts');
123
-		foreach($values as $column => $value) {
124
-			$qb->setValue($column, $qb->createNamedParameter($value));
125
-		}
126
-		$qb->execute();
127
-	}
128
-
129
-	/**
130
-	 * Check if the IP is whitelisted
131
-	 *
132
-	 * @param string $ip
133
-	 * @return bool
134
-	 */
135
-	private function isIPWhitelisted($ip) {
136
-		$keys = $this->config->getAppKeys('bruteForce');
137
-		$keys = array_filter($keys, function($key) {
138
-			$regex = '/^whitelist_/S';
139
-			return preg_match($regex, $key) === 1;
140
-		});
141
-
142
-		if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
143
-			$type = 4;
144
-		} else if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
145
-			$type = 6;
146
-		} else {
147
-			return false;
148
-		}
149
-
150
-		$ip = inet_pton($ip);
151
-
152
-		foreach ($keys as $key) {
153
-			$cidr = $this->config->getAppValue('bruteForce', $key, null);
154
-
155
-			$cx = explode('/', $cidr);
156
-			$addr = $cx[0];
157
-			$mask = (int)$cx[1];
158
-
159
-			// Do not compare ipv4 to ipv6
160
-			if (($type === 4 && !filter_var($addr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) ||
161
-				($type === 6 && !filter_var($addr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))) {
162
-				continue;
163
-			}
164
-
165
-			$addr = inet_pton($addr);
166
-
167
-			$valid = true;
168
-			for($i = 0; $i < $mask; $i++) {
169
-				$part = ord($addr[(int)($i/8)]);
170
-				$orig = ord($ip[(int)($i/8)]);
171
-
172
-				$part = $part & (15 << (1 - ($i % 2)));
173
-				$orig = $orig & (15 << (1 - ($i % 2)));
174
-
175
-				if ($part !== $orig) {
176
-					$valid = false;
177
-					break;
178
-				}
179
-			}
180
-
181
-			if ($valid === true) {
182
-				return true;
183
-			}
184
-		}
185
-
186
-		return false;
187
-
188
-	}
189
-
190
-	/**
191
-	 * Get the throttling delay (in milliseconds)
192
-	 *
193
-	 * @param string $ip
194
-	 * @param string $action optionally filter by action
195
-	 * @return int
196
-	 */
197
-	public function getDelay($ip, $action = '') {
198
-		$ipAddress = new IpAddress($ip);
199
-		if ($this->isIPWhitelisted((string)$ipAddress)) {
200
-			return 0;
201
-		}
202
-
203
-		$cutoffTime = (new \DateTime())
204
-			->sub($this->getCutoff(43200))
205
-			->getTimestamp();
206
-
207
-		$qb = $this->db->getQueryBuilder();
208
-		$qb->select('*')
209
-			->from('bruteforce_attempts')
210
-			->where($qb->expr()->gt('occurred', $qb->createNamedParameter($cutoffTime)))
211
-			->andWhere($qb->expr()->eq('subnet', $qb->createNamedParameter($ipAddress->getSubnet())));
212
-
213
-		if ($action !== '') {
214
-			$qb->andWhere($qb->expr()->eq('action', $qb->createNamedParameter($action)));
215
-		}
216
-
217
-		$attempts = count($qb->execute()->fetchAll());
218
-
219
-		if ($attempts === 0) {
220
-			return 0;
221
-		}
222
-
223
-		$maxDelay = 30;
224
-		$firstDelay = 0.1;
225
-		if ($attempts > (8 * PHP_INT_SIZE - 1))  {
226
-			// Don't ever overflow. Just assume the maxDelay time:s
227
-			$firstDelay = $maxDelay;
228
-		} else {
229
-			$firstDelay *= pow(2, $attempts);
230
-			if ($firstDelay > $maxDelay) {
231
-				$firstDelay = $maxDelay;
232
-			}
233
-		}
234
-		return (int) \ceil($firstDelay * 1000);
235
-	}
236
-
237
-	/**
238
-	 * Will sleep for the defined amount of time
239
-	 *
240
-	 * @param string $ip
241
-	 * @param string $action optionally filter by action
242
-	 * @return int the time spent sleeping
243
-	 */
244
-	public function sleepDelay($ip, $action = '') {
245
-		$delay = $this->getDelay($ip, $action);
246
-		usleep($delay * 1000);
247
-		return $delay;
248
-	}
46
+    const LOGIN_ACTION = 'login';
47
+
48
+    /** @var IDBConnection */
49
+    private $db;
50
+    /** @var ITimeFactory */
51
+    private $timeFactory;
52
+    /** @var ILogger */
53
+    private $logger;
54
+    /** @var IConfig */
55
+    private $config;
56
+
57
+    /**
58
+     * @param IDBConnection $db
59
+     * @param ITimeFactory $timeFactory
60
+     * @param ILogger $logger
61
+     * @param IConfig $config
62
+     */
63
+    public function __construct(IDBConnection $db,
64
+                                ITimeFactory $timeFactory,
65
+                                ILogger $logger,
66
+                                IConfig $config) {
67
+        $this->db = $db;
68
+        $this->timeFactory = $timeFactory;
69
+        $this->logger = $logger;
70
+        $this->config = $config;
71
+    }
72
+
73
+    /**
74
+     * Convert a number of seconds into the appropriate DateInterval
75
+     *
76
+     * @param int $expire
77
+     * @return \DateInterval
78
+     */
79
+    private function getCutoff($expire) {
80
+        $d1 = new \DateTime();
81
+        $d2 = clone $d1;
82
+        $d2->sub(new \DateInterval('PT' . $expire . 'S'));
83
+        return $d2->diff($d1);
84
+    }
85
+
86
+    /**
87
+     * Register a failed attempt to bruteforce a security control
88
+     *
89
+     * @param string $action
90
+     * @param string $ip
91
+     * @param array $metadata Optional metadata logged to the database
92
+     */
93
+    public function registerAttempt($action,
94
+                                    $ip,
95
+                                    array $metadata = []) {
96
+        // No need to log if the bruteforce protection is disabled
97
+        if($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
98
+            return;
99
+        }
100
+
101
+        $ipAddress = new IpAddress($ip);
102
+        $values = [
103
+            'action' => $action,
104
+            'occurred' => $this->timeFactory->getTime(),
105
+            'ip' => (string)$ipAddress,
106
+            'subnet' => $ipAddress->getSubnet(),
107
+            'metadata' => json_encode($metadata),
108
+        ];
109
+
110
+        $this->logger->notice(
111
+            sprintf(
112
+                'Bruteforce attempt from "%s" detected for action "%s".',
113
+                $ip,
114
+                $action
115
+            ),
116
+            [
117
+                'app' => 'core',
118
+            ]
119
+        );
120
+
121
+        $qb = $this->db->getQueryBuilder();
122
+        $qb->insert('bruteforce_attempts');
123
+        foreach($values as $column => $value) {
124
+            $qb->setValue($column, $qb->createNamedParameter($value));
125
+        }
126
+        $qb->execute();
127
+    }
128
+
129
+    /**
130
+     * Check if the IP is whitelisted
131
+     *
132
+     * @param string $ip
133
+     * @return bool
134
+     */
135
+    private function isIPWhitelisted($ip) {
136
+        $keys = $this->config->getAppKeys('bruteForce');
137
+        $keys = array_filter($keys, function($key) {
138
+            $regex = '/^whitelist_/S';
139
+            return preg_match($regex, $key) === 1;
140
+        });
141
+
142
+        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
143
+            $type = 4;
144
+        } else if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
145
+            $type = 6;
146
+        } else {
147
+            return false;
148
+        }
149
+
150
+        $ip = inet_pton($ip);
151
+
152
+        foreach ($keys as $key) {
153
+            $cidr = $this->config->getAppValue('bruteForce', $key, null);
154
+
155
+            $cx = explode('/', $cidr);
156
+            $addr = $cx[0];
157
+            $mask = (int)$cx[1];
158
+
159
+            // Do not compare ipv4 to ipv6
160
+            if (($type === 4 && !filter_var($addr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) ||
161
+                ($type === 6 && !filter_var($addr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))) {
162
+                continue;
163
+            }
164
+
165
+            $addr = inet_pton($addr);
166
+
167
+            $valid = true;
168
+            for($i = 0; $i < $mask; $i++) {
169
+                $part = ord($addr[(int)($i/8)]);
170
+                $orig = ord($ip[(int)($i/8)]);
171
+
172
+                $part = $part & (15 << (1 - ($i % 2)));
173
+                $orig = $orig & (15 << (1 - ($i % 2)));
174
+
175
+                if ($part !== $orig) {
176
+                    $valid = false;
177
+                    break;
178
+                }
179
+            }
180
+
181
+            if ($valid === true) {
182
+                return true;
183
+            }
184
+        }
185
+
186
+        return false;
187
+
188
+    }
189
+
190
+    /**
191
+     * Get the throttling delay (in milliseconds)
192
+     *
193
+     * @param string $ip
194
+     * @param string $action optionally filter by action
195
+     * @return int
196
+     */
197
+    public function getDelay($ip, $action = '') {
198
+        $ipAddress = new IpAddress($ip);
199
+        if ($this->isIPWhitelisted((string)$ipAddress)) {
200
+            return 0;
201
+        }
202
+
203
+        $cutoffTime = (new \DateTime())
204
+            ->sub($this->getCutoff(43200))
205
+            ->getTimestamp();
206
+
207
+        $qb = $this->db->getQueryBuilder();
208
+        $qb->select('*')
209
+            ->from('bruteforce_attempts')
210
+            ->where($qb->expr()->gt('occurred', $qb->createNamedParameter($cutoffTime)))
211
+            ->andWhere($qb->expr()->eq('subnet', $qb->createNamedParameter($ipAddress->getSubnet())));
212
+
213
+        if ($action !== '') {
214
+            $qb->andWhere($qb->expr()->eq('action', $qb->createNamedParameter($action)));
215
+        }
216
+
217
+        $attempts = count($qb->execute()->fetchAll());
218
+
219
+        if ($attempts === 0) {
220
+            return 0;
221
+        }
222
+
223
+        $maxDelay = 30;
224
+        $firstDelay = 0.1;
225
+        if ($attempts > (8 * PHP_INT_SIZE - 1))  {
226
+            // Don't ever overflow. Just assume the maxDelay time:s
227
+            $firstDelay = $maxDelay;
228
+        } else {
229
+            $firstDelay *= pow(2, $attempts);
230
+            if ($firstDelay > $maxDelay) {
231
+                $firstDelay = $maxDelay;
232
+            }
233
+        }
234
+        return (int) \ceil($firstDelay * 1000);
235
+    }
236
+
237
+    /**
238
+     * Will sleep for the defined amount of time
239
+     *
240
+     * @param string $ip
241
+     * @param string $action optionally filter by action
242
+     * @return int the time spent sleeping
243
+     */
244
+    public function sleepDelay($ip, $action = '') {
245
+        $delay = $this->getDelay($ip, $action);
246
+        usleep($delay * 1000);
247
+        return $delay;
248
+    }
249 249
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	private function getCutoff($expire) {
80 80
 		$d1 = new \DateTime();
81 81
 		$d2 = clone $d1;
82
-		$d2->sub(new \DateInterval('PT' . $expire . 'S'));
82
+		$d2->sub(new \DateInterval('PT'.$expire.'S'));
83 83
 		return $d2->diff($d1);
84 84
 	}
85 85
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 									$ip,
95 95
 									array $metadata = []) {
96 96
 		// No need to log if the bruteforce protection is disabled
97
-		if($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
97
+		if ($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
98 98
 			return;
99 99
 		}
100 100
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 		$values = [
103 103
 			'action' => $action,
104 104
 			'occurred' => $this->timeFactory->getTime(),
105
-			'ip' => (string)$ipAddress,
105
+			'ip' => (string) $ipAddress,
106 106
 			'subnet' => $ipAddress->getSubnet(),
107 107
 			'metadata' => json_encode($metadata),
108 108
 		];
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 
121 121
 		$qb = $this->db->getQueryBuilder();
122 122
 		$qb->insert('bruteforce_attempts');
123
-		foreach($values as $column => $value) {
123
+		foreach ($values as $column => $value) {
124 124
 			$qb->setValue($column, $qb->createNamedParameter($value));
125 125
 		}
126 126
 		$qb->execute();
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 
155 155
 			$cx = explode('/', $cidr);
156 156
 			$addr = $cx[0];
157
-			$mask = (int)$cx[1];
157
+			$mask = (int) $cx[1];
158 158
 
159 159
 			// Do not compare ipv4 to ipv6
160 160
 			if (($type === 4 && !filter_var($addr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) ||
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
 			$addr = inet_pton($addr);
166 166
 
167 167
 			$valid = true;
168
-			for($i = 0; $i < $mask; $i++) {
169
-				$part = ord($addr[(int)($i/8)]);
170
-				$orig = ord($ip[(int)($i/8)]);
168
+			for ($i = 0; $i < $mask; $i++) {
169
+				$part = ord($addr[(int) ($i / 8)]);
170
+				$orig = ord($ip[(int) ($i / 8)]);
171 171
 
172 172
 				$part = $part & (15 << (1 - ($i % 2)));
173 173
 				$orig = $orig & (15 << (1 - ($i % 2)));
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	 */
197 197
 	public function getDelay($ip, $action = '') {
198 198
 		$ipAddress = new IpAddress($ip);
199
-		if ($this->isIPWhitelisted((string)$ipAddress)) {
199
+		if ($this->isIPWhitelisted((string) $ipAddress)) {
200 200
 			return 0;
201 201
 		}
202 202
 
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 
223 223
 		$maxDelay = 30;
224 224
 		$firstDelay = 0.1;
225
-		if ($attempts > (8 * PHP_INT_SIZE - 1))  {
225
+		if ($attempts > (8 * PHP_INT_SIZE - 1)) {
226 226
 			// Don't ever overflow. Just assume the maxDelay time:s
227 227
 			$firstDelay = $maxDelay;
228 228
 		} else {
Please login to merge, or discard this patch.
lib/private/AppFramework/DependencyInjection/DIContainer.php 1 patch
Indentation   +349 added lines, -349 removed lines patch added patch discarded remove patch
@@ -61,353 +61,353 @@
 block discarded – undo
61 61
 
62 62
 class DIContainer extends SimpleContainer implements IAppContainer {
63 63
 
64
-	/**
65
-	 * @var array
66
-	 */
67
-	private $middleWares = array();
68
-
69
-	/** @var ServerContainer */
70
-	private $server;
71
-
72
-	/**
73
-	 * Put your class dependencies in here
74
-	 * @param string $appName the name of the app
75
-	 * @param array $urlParams
76
-	 * @param ServerContainer $server
77
-	 */
78
-	public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
79
-		parent::__construct();
80
-		$this['AppName'] = $appName;
81
-		$this['urlParams'] = $urlParams;
82
-
83
-		/** @var \OC\ServerContainer $server */
84
-		if ($server === null) {
85
-			$server = \OC::$server;
86
-		}
87
-		$this->server = $server;
88
-		$this->server->registerAppContainer($appName, $this);
89
-
90
-		// aliases
91
-		$this->registerAlias('appName', 'AppName');
92
-		$this->registerAlias('webRoot', 'WebRoot');
93
-		$this->registerAlias('userId', 'UserId');
94
-
95
-		/**
96
-		 * Core services
97
-		 */
98
-		$this->registerService(IOutput::class, function($c){
99
-			return new Output($this->getServer()->getWebRoot());
100
-		});
101
-
102
-		$this->registerService(Folder::class, function() {
103
-			return $this->getServer()->getUserFolder();
104
-		});
105
-
106
-		$this->registerService(IAppData::class, function (SimpleContainer $c) {
107
-			return $this->getServer()->getAppDataDir($c->query('AppName'));
108
-		});
109
-
110
-		$this->registerService(IL10N::class, function($c) {
111
-			return $this->getServer()->getL10N($c->query('AppName'));
112
-		});
113
-
114
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
115
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
116
-
117
-		$this->registerService(IRequest::class, function() {
118
-			return $this->getServer()->query(IRequest::class);
119
-		});
120
-		$this->registerAlias('Request', IRequest::class);
121
-
122
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
123
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
124
-
125
-		$this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);
126
-
127
-		$this->registerService(IServerContainer::class, function ($c) {
128
-			return $this->getServer();
129
-		});
130
-		$this->registerAlias('ServerContainer', IServerContainer::class);
131
-
132
-		$this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
133
-			return $c->query('OCA\WorkflowEngine\Manager');
134
-		});
135
-
136
-		$this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
137
-			return $c;
138
-		});
139
-
140
-		// commonly used attributes
141
-		$this->registerService('UserId', function ($c) {
142
-			return $c->query('OCP\\IUserSession')->getSession()->get('user_id');
143
-		});
144
-
145
-		$this->registerService('WebRoot', function ($c) {
146
-			return $c->query('ServerContainer')->getWebRoot();
147
-		});
148
-
149
-		$this->registerService('fromMailAddress', function() {
150
-			return Util::getDefaultEmailAddress('no-reply');
151
-		});
152
-
153
-		$this->registerService('OC_Defaults', function ($c) {
154
-			return $c->getServer()->getThemingDefaults();
155
-		});
156
-
157
-		$this->registerService('OCP\Encryption\IManager', function ($c) {
158
-			return $this->getServer()->getEncryptionManager();
159
-		});
160
-
161
-		$this->registerService(IValidator::class, function($c) {
162
-			return $c->query(Validator::class);
163
-		});
164
-
165
-		$this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
166
-			return new \OC\Security\IdentityProof\Manager(
167
-				$this->getServer()->getAppDataDir('identityproof'),
168
-				$this->getServer()->getCrypto()
169
-			);
170
-		});
171
-
172
-		/**
173
-		 * App Framework APIs
174
-		 */
175
-		$this->registerService('API', function($c){
176
-			$c->query('OCP\\ILogger')->debug(
177
-				'Accessing the API class is deprecated! Use the appropriate ' .
178
-				'services instead!'
179
-			);
180
-			return new API($c['AppName']);
181
-		});
182
-
183
-		$this->registerService('Protocol', function($c){
184
-			/** @var \OC\Server $server */
185
-			$server = $c->query('ServerContainer');
186
-			$protocol = $server->getRequest()->getHttpProtocol();
187
-			return new Http($_SERVER, $protocol);
188
-		});
189
-
190
-		$this->registerService('Dispatcher', function($c) {
191
-			return new Dispatcher(
192
-				$c['Protocol'],
193
-				$c['MiddlewareDispatcher'],
194
-				$c['ControllerMethodReflector'],
195
-				$c['Request']
196
-			);
197
-		});
198
-
199
-		/**
200
-		 * App Framework default arguments
201
-		 */
202
-		$this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH');
203
-		$this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept');
204
-		$this->registerParameter('corsMaxAge', 1728000);
205
-
206
-		/**
207
-		 * Middleware
208
-		 */
209
-		$app = $this;
210
-		$this->registerService('SecurityMiddleware', function($c) use ($app){
211
-			/** @var \OC\Server $server */
212
-			$server = $app->getServer();
213
-
214
-			return new SecurityMiddleware(
215
-				$c['Request'],
216
-				$c['ControllerMethodReflector'],
217
-				$server->getNavigationManager(),
218
-				$server->getURLGenerator(),
219
-				$server->getLogger(),
220
-				$server->getSession(),
221
-				$c['AppName'],
222
-				$server->getUserSession(),
223
-				$app->isAdminUser(),
224
-				$server->getContentSecurityPolicyManager(),
225
-				$server->getCsrfTokenManager(),
226
-				$server->getContentSecurityPolicyNonceManager(),
227
-				$server->getBruteForceThrottler(),
228
-				$c->query(OC\Security\RateLimiting\Limiter::class)
229
-			);
230
-
231
-		});
232
-
233
-		$this->registerService('CORSMiddleware', function($c) {
234
-			return new CORSMiddleware(
235
-				$c['Request'],
236
-				$c['ControllerMethodReflector'],
237
-				$c->query(IUserSession::class),
238
-				$c->getServer()->getBruteForceThrottler()
239
-			);
240
-		});
241
-
242
-		$this->registerService('SessionMiddleware', function($c) use ($app) {
243
-			return new SessionMiddleware(
244
-				$c['Request'],
245
-				$c['ControllerMethodReflector'],
246
-				$app->getServer()->getSession()
247
-			);
248
-		});
249
-
250
-		$this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) {
251
-			$twoFactorManager = $c->getServer()->getTwoFactorAuthManager();
252
-			$userSession = $app->getServer()->getUserSession();
253
-			$session = $app->getServer()->getSession();
254
-			$urlGenerator = $app->getServer()->getURLGenerator();
255
-			$reflector = $c['ControllerMethodReflector'];
256
-			$request = $app->getServer()->getRequest();
257
-			return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request);
258
-		});
259
-
260
-		$this->registerService('OCSMiddleware', function (SimpleContainer $c) {
261
-			return new OCSMiddleware(
262
-				$c['Request']
263
-			);
264
-		});
265
-
266
-		$middleWares = &$this->middleWares;
267
-		$this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) {
268
-			$dispatcher = new MiddlewareDispatcher();
269
-			$dispatcher->registerMiddleware($c['CORSMiddleware']);
270
-			$dispatcher->registerMiddleware($c['OCSMiddleware']);
271
-			$dispatcher->registerMiddleware($c['SecurityMiddleware']);
272
-			$dispatcher->registerMiddleWare($c['TwoFactorMiddleware']);
273
-
274
-			foreach($middleWares as $middleWare) {
275
-				$dispatcher->registerMiddleware($c[$middleWare]);
276
-			}
277
-
278
-			$dispatcher->registerMiddleware($c['SessionMiddleware']);
279
-			return $dispatcher;
280
-		});
281
-
282
-	}
283
-
284
-
285
-	/**
286
-	 * @deprecated implements only deprecated methods
287
-	 * @return IApi
288
-	 */
289
-	function getCoreApi()
290
-	{
291
-		return $this->query('API');
292
-	}
293
-
294
-	/**
295
-	 * @return \OCP\IServerContainer
296
-	 */
297
-	function getServer()
298
-	{
299
-		return $this->server;
300
-	}
301
-
302
-	/**
303
-	 * @param string $middleWare
304
-	 * @return boolean|null
305
-	 */
306
-	function registerMiddleWare($middleWare) {
307
-		array_push($this->middleWares, $middleWare);
308
-	}
309
-
310
-	/**
311
-	 * used to return the appname of the set application
312
-	 * @return string the name of your application
313
-	 */
314
-	function getAppName() {
315
-		return $this->query('AppName');
316
-	}
317
-
318
-	/**
319
-	 * @deprecated use IUserSession->isLoggedIn()
320
-	 * @return boolean
321
-	 */
322
-	function isLoggedIn() {
323
-		return \OC::$server->getUserSession()->isLoggedIn();
324
-	}
325
-
326
-	/**
327
-	 * @deprecated use IGroupManager->isAdmin($userId)
328
-	 * @return boolean
329
-	 */
330
-	function isAdminUser() {
331
-		$uid = $this->getUserId();
332
-		return \OC_User::isAdminUser($uid);
333
-	}
334
-
335
-	private function getUserId() {
336
-		return $this->getServer()->getSession()->get('user_id');
337
-	}
338
-
339
-	/**
340
-	 * @deprecated use the ILogger instead
341
-	 * @param string $message
342
-	 * @param string $level
343
-	 * @return mixed
344
-	 */
345
-	function log($message, $level) {
346
-		switch($level){
347
-			case 'debug':
348
-				$level = \OCP\Util::DEBUG;
349
-				break;
350
-			case 'info':
351
-				$level = \OCP\Util::INFO;
352
-				break;
353
-			case 'warn':
354
-				$level = \OCP\Util::WARN;
355
-				break;
356
-			case 'fatal':
357
-				$level = \OCP\Util::FATAL;
358
-				break;
359
-			default:
360
-				$level = \OCP\Util::ERROR;
361
-				break;
362
-		}
363
-		\OCP\Util::writeLog($this->getAppName(), $message, $level);
364
-	}
365
-
366
-	/**
367
-	 * Register a capability
368
-	 *
369
-	 * @param string $serviceName e.g. 'OCA\Files\Capabilities'
370
-	 */
371
-	public function registerCapability($serviceName) {
372
-		$this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) {
373
-			return $this->query($serviceName);
374
-		});
375
-	}
376
-
377
-	/**
378
-	 * @param string $name
379
-	 * @return mixed
380
-	 * @throws QueryException if the query could not be resolved
381
-	 */
382
-	public function query($name) {
383
-		try {
384
-			return $this->queryNoFallback($name);
385
-		} catch (QueryException $e) {
386
-			return $this->getServer()->query($name);
387
-		}
388
-	}
389
-
390
-	/**
391
-	 * @param string $name
392
-	 * @return mixed
393
-	 * @throws QueryException if the query could not be resolved
394
-	 */
395
-	public function queryNoFallback($name) {
396
-		$name = $this->sanitizeName($name);
397
-
398
-		if ($this->offsetExists($name)) {
399
-			return parent::query($name);
400
-		} else {
401
-			if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
402
-				return parent::query($name);
403
-			} else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
404
-				return parent::query($name);
405
-			} else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) {
406
-				return parent::query($name);
407
-			}
408
-		}
409
-
410
-		throw new QueryException('Could not resolve ' . $name . '!' .
411
-			' Class can not be instantiated');
412
-	}
64
+    /**
65
+     * @var array
66
+     */
67
+    private $middleWares = array();
68
+
69
+    /** @var ServerContainer */
70
+    private $server;
71
+
72
+    /**
73
+     * Put your class dependencies in here
74
+     * @param string $appName the name of the app
75
+     * @param array $urlParams
76
+     * @param ServerContainer $server
77
+     */
78
+    public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
79
+        parent::__construct();
80
+        $this['AppName'] = $appName;
81
+        $this['urlParams'] = $urlParams;
82
+
83
+        /** @var \OC\ServerContainer $server */
84
+        if ($server === null) {
85
+            $server = \OC::$server;
86
+        }
87
+        $this->server = $server;
88
+        $this->server->registerAppContainer($appName, $this);
89
+
90
+        // aliases
91
+        $this->registerAlias('appName', 'AppName');
92
+        $this->registerAlias('webRoot', 'WebRoot');
93
+        $this->registerAlias('userId', 'UserId');
94
+
95
+        /**
96
+         * Core services
97
+         */
98
+        $this->registerService(IOutput::class, function($c){
99
+            return new Output($this->getServer()->getWebRoot());
100
+        });
101
+
102
+        $this->registerService(Folder::class, function() {
103
+            return $this->getServer()->getUserFolder();
104
+        });
105
+
106
+        $this->registerService(IAppData::class, function (SimpleContainer $c) {
107
+            return $this->getServer()->getAppDataDir($c->query('AppName'));
108
+        });
109
+
110
+        $this->registerService(IL10N::class, function($c) {
111
+            return $this->getServer()->getL10N($c->query('AppName'));
112
+        });
113
+
114
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
115
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
116
+
117
+        $this->registerService(IRequest::class, function() {
118
+            return $this->getServer()->query(IRequest::class);
119
+        });
120
+        $this->registerAlias('Request', IRequest::class);
121
+
122
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
123
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
124
+
125
+        $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);
126
+
127
+        $this->registerService(IServerContainer::class, function ($c) {
128
+            return $this->getServer();
129
+        });
130
+        $this->registerAlias('ServerContainer', IServerContainer::class);
131
+
132
+        $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
133
+            return $c->query('OCA\WorkflowEngine\Manager');
134
+        });
135
+
136
+        $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
137
+            return $c;
138
+        });
139
+
140
+        // commonly used attributes
141
+        $this->registerService('UserId', function ($c) {
142
+            return $c->query('OCP\\IUserSession')->getSession()->get('user_id');
143
+        });
144
+
145
+        $this->registerService('WebRoot', function ($c) {
146
+            return $c->query('ServerContainer')->getWebRoot();
147
+        });
148
+
149
+        $this->registerService('fromMailAddress', function() {
150
+            return Util::getDefaultEmailAddress('no-reply');
151
+        });
152
+
153
+        $this->registerService('OC_Defaults', function ($c) {
154
+            return $c->getServer()->getThemingDefaults();
155
+        });
156
+
157
+        $this->registerService('OCP\Encryption\IManager', function ($c) {
158
+            return $this->getServer()->getEncryptionManager();
159
+        });
160
+
161
+        $this->registerService(IValidator::class, function($c) {
162
+            return $c->query(Validator::class);
163
+        });
164
+
165
+        $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
166
+            return new \OC\Security\IdentityProof\Manager(
167
+                $this->getServer()->getAppDataDir('identityproof'),
168
+                $this->getServer()->getCrypto()
169
+            );
170
+        });
171
+
172
+        /**
173
+         * App Framework APIs
174
+         */
175
+        $this->registerService('API', function($c){
176
+            $c->query('OCP\\ILogger')->debug(
177
+                'Accessing the API class is deprecated! Use the appropriate ' .
178
+                'services instead!'
179
+            );
180
+            return new API($c['AppName']);
181
+        });
182
+
183
+        $this->registerService('Protocol', function($c){
184
+            /** @var \OC\Server $server */
185
+            $server = $c->query('ServerContainer');
186
+            $protocol = $server->getRequest()->getHttpProtocol();
187
+            return new Http($_SERVER, $protocol);
188
+        });
189
+
190
+        $this->registerService('Dispatcher', function($c) {
191
+            return new Dispatcher(
192
+                $c['Protocol'],
193
+                $c['MiddlewareDispatcher'],
194
+                $c['ControllerMethodReflector'],
195
+                $c['Request']
196
+            );
197
+        });
198
+
199
+        /**
200
+         * App Framework default arguments
201
+         */
202
+        $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH');
203
+        $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept');
204
+        $this->registerParameter('corsMaxAge', 1728000);
205
+
206
+        /**
207
+         * Middleware
208
+         */
209
+        $app = $this;
210
+        $this->registerService('SecurityMiddleware', function($c) use ($app){
211
+            /** @var \OC\Server $server */
212
+            $server = $app->getServer();
213
+
214
+            return new SecurityMiddleware(
215
+                $c['Request'],
216
+                $c['ControllerMethodReflector'],
217
+                $server->getNavigationManager(),
218
+                $server->getURLGenerator(),
219
+                $server->getLogger(),
220
+                $server->getSession(),
221
+                $c['AppName'],
222
+                $server->getUserSession(),
223
+                $app->isAdminUser(),
224
+                $server->getContentSecurityPolicyManager(),
225
+                $server->getCsrfTokenManager(),
226
+                $server->getContentSecurityPolicyNonceManager(),
227
+                $server->getBruteForceThrottler(),
228
+                $c->query(OC\Security\RateLimiting\Limiter::class)
229
+            );
230
+
231
+        });
232
+
233
+        $this->registerService('CORSMiddleware', function($c) {
234
+            return new CORSMiddleware(
235
+                $c['Request'],
236
+                $c['ControllerMethodReflector'],
237
+                $c->query(IUserSession::class),
238
+                $c->getServer()->getBruteForceThrottler()
239
+            );
240
+        });
241
+
242
+        $this->registerService('SessionMiddleware', function($c) use ($app) {
243
+            return new SessionMiddleware(
244
+                $c['Request'],
245
+                $c['ControllerMethodReflector'],
246
+                $app->getServer()->getSession()
247
+            );
248
+        });
249
+
250
+        $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) {
251
+            $twoFactorManager = $c->getServer()->getTwoFactorAuthManager();
252
+            $userSession = $app->getServer()->getUserSession();
253
+            $session = $app->getServer()->getSession();
254
+            $urlGenerator = $app->getServer()->getURLGenerator();
255
+            $reflector = $c['ControllerMethodReflector'];
256
+            $request = $app->getServer()->getRequest();
257
+            return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request);
258
+        });
259
+
260
+        $this->registerService('OCSMiddleware', function (SimpleContainer $c) {
261
+            return new OCSMiddleware(
262
+                $c['Request']
263
+            );
264
+        });
265
+
266
+        $middleWares = &$this->middleWares;
267
+        $this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) {
268
+            $dispatcher = new MiddlewareDispatcher();
269
+            $dispatcher->registerMiddleware($c['CORSMiddleware']);
270
+            $dispatcher->registerMiddleware($c['OCSMiddleware']);
271
+            $dispatcher->registerMiddleware($c['SecurityMiddleware']);
272
+            $dispatcher->registerMiddleWare($c['TwoFactorMiddleware']);
273
+
274
+            foreach($middleWares as $middleWare) {
275
+                $dispatcher->registerMiddleware($c[$middleWare]);
276
+            }
277
+
278
+            $dispatcher->registerMiddleware($c['SessionMiddleware']);
279
+            return $dispatcher;
280
+        });
281
+
282
+    }
283
+
284
+
285
+    /**
286
+     * @deprecated implements only deprecated methods
287
+     * @return IApi
288
+     */
289
+    function getCoreApi()
290
+    {
291
+        return $this->query('API');
292
+    }
293
+
294
+    /**
295
+     * @return \OCP\IServerContainer
296
+     */
297
+    function getServer()
298
+    {
299
+        return $this->server;
300
+    }
301
+
302
+    /**
303
+     * @param string $middleWare
304
+     * @return boolean|null
305
+     */
306
+    function registerMiddleWare($middleWare) {
307
+        array_push($this->middleWares, $middleWare);
308
+    }
309
+
310
+    /**
311
+     * used to return the appname of the set application
312
+     * @return string the name of your application
313
+     */
314
+    function getAppName() {
315
+        return $this->query('AppName');
316
+    }
317
+
318
+    /**
319
+     * @deprecated use IUserSession->isLoggedIn()
320
+     * @return boolean
321
+     */
322
+    function isLoggedIn() {
323
+        return \OC::$server->getUserSession()->isLoggedIn();
324
+    }
325
+
326
+    /**
327
+     * @deprecated use IGroupManager->isAdmin($userId)
328
+     * @return boolean
329
+     */
330
+    function isAdminUser() {
331
+        $uid = $this->getUserId();
332
+        return \OC_User::isAdminUser($uid);
333
+    }
334
+
335
+    private function getUserId() {
336
+        return $this->getServer()->getSession()->get('user_id');
337
+    }
338
+
339
+    /**
340
+     * @deprecated use the ILogger instead
341
+     * @param string $message
342
+     * @param string $level
343
+     * @return mixed
344
+     */
345
+    function log($message, $level) {
346
+        switch($level){
347
+            case 'debug':
348
+                $level = \OCP\Util::DEBUG;
349
+                break;
350
+            case 'info':
351
+                $level = \OCP\Util::INFO;
352
+                break;
353
+            case 'warn':
354
+                $level = \OCP\Util::WARN;
355
+                break;
356
+            case 'fatal':
357
+                $level = \OCP\Util::FATAL;
358
+                break;
359
+            default:
360
+                $level = \OCP\Util::ERROR;
361
+                break;
362
+        }
363
+        \OCP\Util::writeLog($this->getAppName(), $message, $level);
364
+    }
365
+
366
+    /**
367
+     * Register a capability
368
+     *
369
+     * @param string $serviceName e.g. 'OCA\Files\Capabilities'
370
+     */
371
+    public function registerCapability($serviceName) {
372
+        $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) {
373
+            return $this->query($serviceName);
374
+        });
375
+    }
376
+
377
+    /**
378
+     * @param string $name
379
+     * @return mixed
380
+     * @throws QueryException if the query could not be resolved
381
+     */
382
+    public function query($name) {
383
+        try {
384
+            return $this->queryNoFallback($name);
385
+        } catch (QueryException $e) {
386
+            return $this->getServer()->query($name);
387
+        }
388
+    }
389
+
390
+    /**
391
+     * @param string $name
392
+     * @return mixed
393
+     * @throws QueryException if the query could not be resolved
394
+     */
395
+    public function queryNoFallback($name) {
396
+        $name = $this->sanitizeName($name);
397
+
398
+        if ($this->offsetExists($name)) {
399
+            return parent::query($name);
400
+        } else {
401
+            if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
402
+                return parent::query($name);
403
+            } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
404
+                return parent::query($name);
405
+            } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) {
406
+                return parent::query($name);
407
+            }
408
+        }
409
+
410
+        throw new QueryException('Could not resolve ' . $name . '!' .
411
+            ' Class can not be instantiated');
412
+    }
413 413
 }
Please login to merge, or discard this patch.
lib/private/Server.php 2 patches
Indentation   +1609 added lines, -1609 removed lines patch added patch discarded remove patch
@@ -117,1618 +117,1618 @@
 block discarded – undo
117 117
  * TODO: hookup all manager classes
118 118
  */
119 119
 class Server extends ServerContainer implements IServerContainer {
120
-	/** @var string */
121
-	private $webRoot;
122
-
123
-	/**
124
-	 * @param string $webRoot
125
-	 * @param \OC\Config $config
126
-	 */
127
-	public function __construct($webRoot, \OC\Config $config) {
128
-		parent::__construct();
129
-		$this->webRoot = $webRoot;
130
-
131
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
132
-		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
133
-
134
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
135
-			return new PreviewManager(
136
-				$c->getConfig(),
137
-				$c->getRootFolder(),
138
-				$c->getAppDataDir('preview'),
139
-				$c->getEventDispatcher(),
140
-				$c->getSession()->get('user_id')
141
-			);
142
-		});
143
-		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
144
-
145
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
146
-			return new \OC\Preview\Watcher(
147
-				$c->getAppDataDir('preview')
148
-			);
149
-		});
150
-
151
-		$this->registerService('EncryptionManager', function (Server $c) {
152
-			$view = new View();
153
-			$util = new Encryption\Util(
154
-				$view,
155
-				$c->getUserManager(),
156
-				$c->getGroupManager(),
157
-				$c->getConfig()
158
-			);
159
-			return new Encryption\Manager(
160
-				$c->getConfig(),
161
-				$c->getLogger(),
162
-				$c->getL10N('core'),
163
-				new View(),
164
-				$util,
165
-				new ArrayCache()
166
-			);
167
-		});
168
-
169
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
170
-			$util = new Encryption\Util(
171
-				new View(),
172
-				$c->getUserManager(),
173
-				$c->getGroupManager(),
174
-				$c->getConfig()
175
-			);
176
-			return new Encryption\File($util);
177
-		});
178
-
179
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
180
-			$view = new View();
181
-			$util = new Encryption\Util(
182
-				$view,
183
-				$c->getUserManager(),
184
-				$c->getGroupManager(),
185
-				$c->getConfig()
186
-			);
187
-
188
-			return new Encryption\Keys\Storage($view, $util);
189
-		});
190
-		$this->registerService('TagMapper', function (Server $c) {
191
-			return new TagMapper($c->getDatabaseConnection());
192
-		});
193
-
194
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
195
-			$tagMapper = $c->query('TagMapper');
196
-			return new TagManager($tagMapper, $c->getUserSession());
197
-		});
198
-		$this->registerAlias('TagManager', \OCP\ITagManager::class);
199
-
200
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
201
-			$config = $c->getConfig();
202
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
203
-			/** @var \OC\SystemTag\ManagerFactory $factory */
204
-			$factory = new $factoryClass($this);
205
-			return $factory;
206
-		});
207
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
208
-			return $c->query('SystemTagManagerFactory')->getManager();
209
-		});
210
-		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
211
-
212
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
213
-			return $c->query('SystemTagManagerFactory')->getObjectMapper();
214
-		});
215
-		$this->registerService('RootFolder', function (Server $c) {
216
-			$manager = \OC\Files\Filesystem::getMountManager(null);
217
-			$view = new View();
218
-			$root = new Root(
219
-				$manager,
220
-				$view,
221
-				null,
222
-				$c->getUserMountCache(),
223
-				$this->getLogger(),
224
-				$this->getUserManager()
225
-			);
226
-			$connector = new HookConnector($root, $view);
227
-			$connector->viewToNode();
228
-
229
-			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
230
-			$previewConnector->connectWatcher();
231
-
232
-			return $root;
233
-		});
234
-		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
235
-
236
-		$this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) {
237
-			return new LazyRoot(function() use ($c) {
238
-				return $c->query('RootFolder');
239
-			});
240
-		});
241
-		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
242
-
243
-		$this->registerService(\OCP\IUserManager::class, function (Server $c) {
244
-			$config = $c->getConfig();
245
-			return new \OC\User\Manager($config);
246
-		});
247
-		$this->registerAlias('UserManager', \OCP\IUserManager::class);
248
-
249
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
250
-			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
251
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
252
-				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
253
-			});
254
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
255
-				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
256
-			});
257
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
258
-				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
259
-			});
260
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
261
-				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
262
-			});
263
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
264
-				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
265
-			});
266
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
267
-				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
268
-				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
269
-				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
270
-			});
271
-			return $groupManager;
272
-		});
273
-		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
274
-
275
-		$this->registerService(Store::class, function(Server $c) {
276
-			$session = $c->getSession();
277
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
278
-				$tokenProvider = $c->query('OC\Authentication\Token\IProvider');
279
-			} else {
280
-				$tokenProvider = null;
281
-			}
282
-			$logger = $c->getLogger();
283
-			return new Store($session, $logger, $tokenProvider);
284
-		});
285
-		$this->registerAlias(IStore::class, Store::class);
286
-		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
287
-			$dbConnection = $c->getDatabaseConnection();
288
-			return new Authentication\Token\DefaultTokenMapper($dbConnection);
289
-		});
290
-		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
291
-			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
292
-			$crypto = $c->getCrypto();
293
-			$config = $c->getConfig();
294
-			$logger = $c->getLogger();
295
-			$timeFactory = new TimeFactory();
296
-			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
297
-		});
298
-		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
299
-
300
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
301
-			$manager = $c->getUserManager();
302
-			$session = new \OC\Session\Memory('');
303
-			$timeFactory = new TimeFactory();
304
-			// Token providers might require a working database. This code
305
-			// might however be called when ownCloud is not yet setup.
306
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
307
-				$defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
308
-			} else {
309
-				$defaultTokenProvider = null;
310
-			}
311
-
312
-			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
313
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
314
-				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
315
-			});
316
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
317
-				/** @var $user \OC\User\User */
318
-				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
319
-			});
320
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
321
-				/** @var $user \OC\User\User */
322
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
323
-			});
324
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
325
-				/** @var $user \OC\User\User */
326
-				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
327
-			});
328
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
329
-				/** @var $user \OC\User\User */
330
-				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
331
-			});
332
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
333
-				/** @var $user \OC\User\User */
334
-				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
335
-			});
336
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
337
-				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
338
-			});
339
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
340
-				/** @var $user \OC\User\User */
341
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
342
-			});
343
-			$userSession->listen('\OC\User', 'logout', function () {
344
-				\OC_Hook::emit('OC_User', 'logout', array());
345
-			});
346
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
347
-				/** @var $user \OC\User\User */
348
-				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));
349
-			});
350
-			return $userSession;
351
-		});
352
-		$this->registerAlias('UserSession', \OCP\IUserSession::class);
353
-
354
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
355
-			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
356
-		});
357
-
358
-		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
359
-		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
360
-
361
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
362
-			return new \OC\AllConfig(
363
-				$c->getSystemConfig()
364
-			);
365
-		});
366
-		$this->registerAlias('AllConfig', \OC\AllConfig::class);
367
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
368
-
369
-		$this->registerService('SystemConfig', function ($c) use ($config) {
370
-			return new \OC\SystemConfig($config);
371
-		});
372
-
373
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
374
-			return new \OC\AppConfig($c->getDatabaseConnection());
375
-		});
376
-		$this->registerAlias('AppConfig', \OC\AppConfig::class);
377
-		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
378
-
379
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
380
-			return new \OC\L10N\Factory(
381
-				$c->getConfig(),
382
-				$c->getRequest(),
383
-				$c->getUserSession(),
384
-				\OC::$SERVERROOT
385
-			);
386
-		});
387
-		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
388
-
389
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
390
-			$config = $c->getConfig();
391
-			$cacheFactory = $c->getMemCacheFactory();
392
-			return new \OC\URLGenerator(
393
-				$config,
394
-				$cacheFactory
395
-			);
396
-		});
397
-		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
398
-
399
-		$this->registerService('AppHelper', function ($c) {
400
-			return new \OC\AppHelper();
401
-		});
402
-		$this->registerService('AppFetcher', function ($c) {
403
-			return new AppFetcher(
404
-				$this->getAppDataDir('appstore'),
405
-				$this->getHTTPClientService(),
406
-				$this->query(TimeFactory::class),
407
-				$this->getConfig()
408
-			);
409
-		});
410
-		$this->registerService('CategoryFetcher', function ($c) {
411
-			return new CategoryFetcher(
412
-				$this->getAppDataDir('appstore'),
413
-				$this->getHTTPClientService(),
414
-				$this->query(TimeFactory::class),
415
-				$this->getConfig()
416
-			);
417
-		});
418
-
419
-		$this->registerService(\OCP\ICache::class, function ($c) {
420
-			return new Cache\File();
421
-		});
422
-		$this->registerAlias('UserCache', \OCP\ICache::class);
423
-
424
-		$this->registerService(Factory::class, function (Server $c) {
425
-			$config = $c->getConfig();
426
-
427
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
428
-				$v = \OC_App::getAppVersions();
429
-				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
430
-				$version = implode(',', $v);
431
-				$instanceId = \OC_Util::getInstanceId();
432
-				$path = \OC::$SERVERROOT;
433
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
434
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
435
-					$config->getSystemValue('memcache.local', null),
436
-					$config->getSystemValue('memcache.distributed', null),
437
-					$config->getSystemValue('memcache.locking', null)
438
-				);
439
-			}
440
-
441
-			return new \OC\Memcache\Factory('', $c->getLogger(),
442
-				'\\OC\\Memcache\\ArrayCache',
443
-				'\\OC\\Memcache\\ArrayCache',
444
-				'\\OC\\Memcache\\ArrayCache'
445
-			);
446
-		});
447
-		$this->registerAlias('MemCacheFactory', Factory::class);
448
-		$this->registerAlias(ICacheFactory::class, Factory::class);
449
-
450
-		$this->registerService('RedisFactory', function (Server $c) {
451
-			$systemConfig = $c->getSystemConfig();
452
-			return new RedisFactory($systemConfig);
453
-		});
454
-
455
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
456
-			return new \OC\Activity\Manager(
457
-				$c->getRequest(),
458
-				$c->getUserSession(),
459
-				$c->getConfig(),
460
-				$c->query(IValidator::class)
461
-			);
462
-		});
463
-		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
464
-
465
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
466
-			return new \OC\Activity\EventMerger(
467
-				$c->getL10N('lib')
468
-			);
469
-		});
470
-		$this->registerAlias(IValidator::class, Validator::class);
471
-
472
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
473
-			return new AvatarManager(
474
-				$c->getUserManager(),
475
-				$c->getAppDataDir('avatar'),
476
-				$c->getL10N('lib'),
477
-				$c->getLogger(),
478
-				$c->getConfig()
479
-			);
480
-		});
481
-		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
482
-
483
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
484
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
485
-			$logger = Log::getLogClass($logType);
486
-			call_user_func(array($logger, 'init'));
487
-
488
-			return new Log($logger);
489
-		});
490
-		$this->registerAlias('Logger', \OCP\ILogger::class);
491
-
492
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
493
-			$config = $c->getConfig();
494
-			return new \OC\BackgroundJob\JobList(
495
-				$c->getDatabaseConnection(),
496
-				$config,
497
-				new TimeFactory()
498
-			);
499
-		});
500
-		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
501
-
502
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
503
-			$cacheFactory = $c->getMemCacheFactory();
504
-			$logger = $c->getLogger();
505
-			if ($cacheFactory->isAvailable()) {
506
-				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
507
-			} else {
508
-				$router = new \OC\Route\Router($logger);
509
-			}
510
-			return $router;
511
-		});
512
-		$this->registerAlias('Router', \OCP\Route\IRouter::class);
513
-
514
-		$this->registerService(\OCP\ISearch::class, function ($c) {
515
-			return new Search();
516
-		});
517
-		$this->registerAlias('Search', \OCP\ISearch::class);
518
-
519
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) {
520
-			return new \OC\Security\RateLimiting\Limiter(
521
-				$this->getUserSession(),
522
-				$this->getRequest(),
523
-				new \OC\AppFramework\Utility\TimeFactory(),
524
-				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
525
-			);
526
-		});
527
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
528
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
529
-				$this->getMemCacheFactory(),
530
-				new \OC\AppFramework\Utility\TimeFactory()
531
-			);
532
-		});
533
-
534
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
535
-			return new SecureRandom();
536
-		});
537
-		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
538
-
539
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
540
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
541
-		});
542
-		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
543
-
544
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
545
-			return new Hasher($c->getConfig());
546
-		});
547
-		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
548
-
549
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
550
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
551
-		});
552
-		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
553
-
554
-		$this->registerService(IDBConnection::class, function (Server $c) {
555
-			$systemConfig = $c->getSystemConfig();
556
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
557
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
558
-			if (!$factory->isValidType($type)) {
559
-				throw new \OC\DatabaseException('Invalid database type');
560
-			}
561
-			$connectionParams = $factory->createConnectionParams();
562
-			$connection = $factory->getConnection($type, $connectionParams);
563
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
564
-			return $connection;
565
-		});
566
-		$this->registerAlias('DatabaseConnection', IDBConnection::class);
567
-
568
-		$this->registerService('HTTPHelper', function (Server $c) {
569
-			$config = $c->getConfig();
570
-			return new HTTPHelper(
571
-				$config,
572
-				$c->getHTTPClientService()
573
-			);
574
-		});
575
-
576
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
577
-			$user = \OC_User::getUser();
578
-			$uid = $user ? $user : null;
579
-			return new ClientService(
580
-				$c->getConfig(),
581
-				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
582
-			);
583
-		});
584
-		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
585
-
586
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
587
-			if ($c->getSystemConfig()->getValue('debug', false)) {
588
-				return new EventLogger();
589
-			} else {
590
-				return new NullEventLogger();
591
-			}
592
-		});
593
-		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
594
-
595
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
596
-			if ($c->getSystemConfig()->getValue('debug', false)) {
597
-				return new QueryLogger();
598
-			} else {
599
-				return new NullQueryLogger();
600
-			}
601
-		});
602
-		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
603
-
604
-		$this->registerService(TempManager::class, function (Server $c) {
605
-			return new TempManager(
606
-				$c->getLogger(),
607
-				$c->getConfig()
608
-			);
609
-		});
610
-		$this->registerAlias('TempManager', TempManager::class);
611
-		$this->registerAlias(ITempManager::class, TempManager::class);
612
-
613
-		$this->registerService(AppManager::class, function (Server $c) {
614
-			return new \OC\App\AppManager(
615
-				$c->getUserSession(),
616
-				$c->getAppConfig(),
617
-				$c->getGroupManager(),
618
-				$c->getMemCacheFactory(),
619
-				$c->getEventDispatcher()
620
-			);
621
-		});
622
-		$this->registerAlias('AppManager', AppManager::class);
623
-		$this->registerAlias(IAppManager::class, AppManager::class);
624
-
625
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
626
-			return new DateTimeZone(
627
-				$c->getConfig(),
628
-				$c->getSession()
629
-			);
630
-		});
631
-		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
632
-
633
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
634
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
635
-
636
-			return new DateTimeFormatter(
637
-				$c->getDateTimeZone()->getTimeZone(),
638
-				$c->getL10N('lib', $language)
639
-			);
640
-		});
641
-		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
642
-
643
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
644
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
645
-			$listener = new UserMountCacheListener($mountCache);
646
-			$listener->listen($c->getUserManager());
647
-			return $mountCache;
648
-		});
649
-		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
650
-
651
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
652
-			$loader = \OC\Files\Filesystem::getLoader();
653
-			$mountCache = $c->query('UserMountCache');
654
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
655
-
656
-			// builtin providers
657
-
658
-			$config = $c->getConfig();
659
-			$manager->registerProvider(new CacheMountProvider($config));
660
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
661
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
662
-
663
-			return $manager;
664
-		});
665
-		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
666
-
667
-		$this->registerService('IniWrapper', function ($c) {
668
-			return new IniGetWrapper();
669
-		});
670
-		$this->registerService('AsyncCommandBus', function (Server $c) {
671
-			$jobList = $c->getJobList();
672
-			return new AsyncBus($jobList);
673
-		});
674
-		$this->registerService('TrustedDomainHelper', function ($c) {
675
-			return new TrustedDomainHelper($this->getConfig());
676
-		});
677
-		$this->registerService('Throttler', function(Server $c) {
678
-			return new Throttler(
679
-				$c->getDatabaseConnection(),
680
-				new TimeFactory(),
681
-				$c->getLogger(),
682
-				$c->getConfig()
683
-			);
684
-		});
685
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
686
-			// IConfig and IAppManager requires a working database. This code
687
-			// might however be called when ownCloud is not yet setup.
688
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
689
-				$config = $c->getConfig();
690
-				$appManager = $c->getAppManager();
691
-			} else {
692
-				$config = null;
693
-				$appManager = null;
694
-			}
695
-
696
-			return new Checker(
697
-					new EnvironmentHelper(),
698
-					new FileAccessHelper(),
699
-					new AppLocator(),
700
-					$config,
701
-					$c->getMemCacheFactory(),
702
-					$appManager,
703
-					$c->getTempManager()
704
-			);
705
-		});
706
-		$this->registerService(\OCP\IRequest::class, function ($c) {
707
-			if (isset($this['urlParams'])) {
708
-				$urlParams = $this['urlParams'];
709
-			} else {
710
-				$urlParams = [];
711
-			}
712
-
713
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
714
-				&& in_array('fakeinput', stream_get_wrappers())
715
-			) {
716
-				$stream = 'fakeinput://data';
717
-			} else {
718
-				$stream = 'php://input';
719
-			}
720
-
721
-			return new Request(
722
-				[
723
-					'get' => $_GET,
724
-					'post' => $_POST,
725
-					'files' => $_FILES,
726
-					'server' => $_SERVER,
727
-					'env' => $_ENV,
728
-					'cookies' => $_COOKIE,
729
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
730
-						? $_SERVER['REQUEST_METHOD']
731
-						: null,
732
-					'urlParams' => $urlParams,
733
-				],
734
-				$this->getSecureRandom(),
735
-				$this->getConfig(),
736
-				$this->getCsrfTokenManager(),
737
-				$stream
738
-			);
739
-		});
740
-		$this->registerAlias('Request', \OCP\IRequest::class);
741
-
742
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
743
-			return new Mailer(
744
-				$c->getConfig(),
745
-				$c->getLogger(),
746
-				$c->query(Defaults::class),
747
-				$c->getURLGenerator(),
748
-				$c->getL10N('lib')
749
-			);
750
-		});
751
-		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
752
-
753
-		$this->registerService('LDAPProvider', function(Server $c) {
754
-			$config = $c->getConfig();
755
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
756
-			if(is_null($factoryClass)) {
757
-				throw new \Exception('ldapProviderFactory not set');
758
-			}
759
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
760
-			$factory = new $factoryClass($this);
761
-			return $factory->getLDAPProvider();
762
-		});
763
-		$this->registerService('LockingProvider', function (Server $c) {
764
-			$ini = $c->getIniWrapper();
765
-			$config = $c->getConfig();
766
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
767
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
768
-				/** @var \OC\Memcache\Factory $memcacheFactory */
769
-				$memcacheFactory = $c->getMemCacheFactory();
770
-				$memcache = $memcacheFactory->createLocking('lock');
771
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
772
-					return new MemcacheLockingProvider($memcache, $ttl);
773
-				}
774
-				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
775
-			}
776
-			return new NoopLockingProvider();
777
-		});
778
-
779
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
780
-			return new \OC\Files\Mount\Manager();
781
-		});
782
-		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
783
-
784
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
785
-			return new \OC\Files\Type\Detection(
786
-				$c->getURLGenerator(),
787
-				\OC::$configDir,
788
-				\OC::$SERVERROOT . '/resources/config/'
789
-			);
790
-		});
791
-		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
792
-
793
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
794
-			return new \OC\Files\Type\Loader(
795
-				$c->getDatabaseConnection()
796
-			);
797
-		});
798
-		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
799
-
800
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
801
-			return new Manager(
802
-				$c->query(IValidator::class)
803
-			);
804
-		});
805
-		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
806
-
807
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
808
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
809
-			$manager->registerCapability(function () use ($c) {
810
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
811
-			});
812
-			return $manager;
813
-		});
814
-		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
815
-
816
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
817
-			$config = $c->getConfig();
818
-			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
819
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
820
-			$factory = new $factoryClass($this);
821
-			return $factory->getManager();
822
-		});
823
-		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
824
-
825
-		$this->registerService('ThemingDefaults', function(Server $c) {
826
-			/*
120
+    /** @var string */
121
+    private $webRoot;
122
+
123
+    /**
124
+     * @param string $webRoot
125
+     * @param \OC\Config $config
126
+     */
127
+    public function __construct($webRoot, \OC\Config $config) {
128
+        parent::__construct();
129
+        $this->webRoot = $webRoot;
130
+
131
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
132
+        $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
133
+
134
+        $this->registerService(\OCP\IPreview::class, function (Server $c) {
135
+            return new PreviewManager(
136
+                $c->getConfig(),
137
+                $c->getRootFolder(),
138
+                $c->getAppDataDir('preview'),
139
+                $c->getEventDispatcher(),
140
+                $c->getSession()->get('user_id')
141
+            );
142
+        });
143
+        $this->registerAlias('PreviewManager', \OCP\IPreview::class);
144
+
145
+        $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
146
+            return new \OC\Preview\Watcher(
147
+                $c->getAppDataDir('preview')
148
+            );
149
+        });
150
+
151
+        $this->registerService('EncryptionManager', function (Server $c) {
152
+            $view = new View();
153
+            $util = new Encryption\Util(
154
+                $view,
155
+                $c->getUserManager(),
156
+                $c->getGroupManager(),
157
+                $c->getConfig()
158
+            );
159
+            return new Encryption\Manager(
160
+                $c->getConfig(),
161
+                $c->getLogger(),
162
+                $c->getL10N('core'),
163
+                new View(),
164
+                $util,
165
+                new ArrayCache()
166
+            );
167
+        });
168
+
169
+        $this->registerService('EncryptionFileHelper', function (Server $c) {
170
+            $util = new Encryption\Util(
171
+                new View(),
172
+                $c->getUserManager(),
173
+                $c->getGroupManager(),
174
+                $c->getConfig()
175
+            );
176
+            return new Encryption\File($util);
177
+        });
178
+
179
+        $this->registerService('EncryptionKeyStorage', function (Server $c) {
180
+            $view = new View();
181
+            $util = new Encryption\Util(
182
+                $view,
183
+                $c->getUserManager(),
184
+                $c->getGroupManager(),
185
+                $c->getConfig()
186
+            );
187
+
188
+            return new Encryption\Keys\Storage($view, $util);
189
+        });
190
+        $this->registerService('TagMapper', function (Server $c) {
191
+            return new TagMapper($c->getDatabaseConnection());
192
+        });
193
+
194
+        $this->registerService(\OCP\ITagManager::class, function (Server $c) {
195
+            $tagMapper = $c->query('TagMapper');
196
+            return new TagManager($tagMapper, $c->getUserSession());
197
+        });
198
+        $this->registerAlias('TagManager', \OCP\ITagManager::class);
199
+
200
+        $this->registerService('SystemTagManagerFactory', function (Server $c) {
201
+            $config = $c->getConfig();
202
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
203
+            /** @var \OC\SystemTag\ManagerFactory $factory */
204
+            $factory = new $factoryClass($this);
205
+            return $factory;
206
+        });
207
+        $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
208
+            return $c->query('SystemTagManagerFactory')->getManager();
209
+        });
210
+        $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
211
+
212
+        $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
213
+            return $c->query('SystemTagManagerFactory')->getObjectMapper();
214
+        });
215
+        $this->registerService('RootFolder', function (Server $c) {
216
+            $manager = \OC\Files\Filesystem::getMountManager(null);
217
+            $view = new View();
218
+            $root = new Root(
219
+                $manager,
220
+                $view,
221
+                null,
222
+                $c->getUserMountCache(),
223
+                $this->getLogger(),
224
+                $this->getUserManager()
225
+            );
226
+            $connector = new HookConnector($root, $view);
227
+            $connector->viewToNode();
228
+
229
+            $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
230
+            $previewConnector->connectWatcher();
231
+
232
+            return $root;
233
+        });
234
+        $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
235
+
236
+        $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) {
237
+            return new LazyRoot(function() use ($c) {
238
+                return $c->query('RootFolder');
239
+            });
240
+        });
241
+        $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
242
+
243
+        $this->registerService(\OCP\IUserManager::class, function (Server $c) {
244
+            $config = $c->getConfig();
245
+            return new \OC\User\Manager($config);
246
+        });
247
+        $this->registerAlias('UserManager', \OCP\IUserManager::class);
248
+
249
+        $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
250
+            $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
251
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
252
+                \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
253
+            });
254
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
255
+                \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
256
+            });
257
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
258
+                \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
259
+            });
260
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
261
+                \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
262
+            });
263
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
264
+                \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
265
+            });
266
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
267
+                \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
268
+                //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
269
+                \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
270
+            });
271
+            return $groupManager;
272
+        });
273
+        $this->registerAlias('GroupManager', \OCP\IGroupManager::class);
274
+
275
+        $this->registerService(Store::class, function(Server $c) {
276
+            $session = $c->getSession();
277
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
278
+                $tokenProvider = $c->query('OC\Authentication\Token\IProvider');
279
+            } else {
280
+                $tokenProvider = null;
281
+            }
282
+            $logger = $c->getLogger();
283
+            return new Store($session, $logger, $tokenProvider);
284
+        });
285
+        $this->registerAlias(IStore::class, Store::class);
286
+        $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
287
+            $dbConnection = $c->getDatabaseConnection();
288
+            return new Authentication\Token\DefaultTokenMapper($dbConnection);
289
+        });
290
+        $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
291
+            $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
292
+            $crypto = $c->getCrypto();
293
+            $config = $c->getConfig();
294
+            $logger = $c->getLogger();
295
+            $timeFactory = new TimeFactory();
296
+            return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
297
+        });
298
+        $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
299
+
300
+        $this->registerService(\OCP\IUserSession::class, function (Server $c) {
301
+            $manager = $c->getUserManager();
302
+            $session = new \OC\Session\Memory('');
303
+            $timeFactory = new TimeFactory();
304
+            // Token providers might require a working database. This code
305
+            // might however be called when ownCloud is not yet setup.
306
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
307
+                $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
308
+            } else {
309
+                $defaultTokenProvider = null;
310
+            }
311
+
312
+            $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
313
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
314
+                \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
315
+            });
316
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
317
+                /** @var $user \OC\User\User */
318
+                \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
319
+            });
320
+            $userSession->listen('\OC\User', 'preDelete', function ($user) {
321
+                /** @var $user \OC\User\User */
322
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
323
+            });
324
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
325
+                /** @var $user \OC\User\User */
326
+                \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
327
+            });
328
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
329
+                /** @var $user \OC\User\User */
330
+                \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
331
+            });
332
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
333
+                /** @var $user \OC\User\User */
334
+                \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
335
+            });
336
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
337
+                \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
338
+            });
339
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
340
+                /** @var $user \OC\User\User */
341
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
342
+            });
343
+            $userSession->listen('\OC\User', 'logout', function () {
344
+                \OC_Hook::emit('OC_User', 'logout', array());
345
+            });
346
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
347
+                /** @var $user \OC\User\User */
348
+                \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));
349
+            });
350
+            return $userSession;
351
+        });
352
+        $this->registerAlias('UserSession', \OCP\IUserSession::class);
353
+
354
+        $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
355
+            return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
356
+        });
357
+
358
+        $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
359
+        $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
360
+
361
+        $this->registerService(\OC\AllConfig::class, function (Server $c) {
362
+            return new \OC\AllConfig(
363
+                $c->getSystemConfig()
364
+            );
365
+        });
366
+        $this->registerAlias('AllConfig', \OC\AllConfig::class);
367
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
368
+
369
+        $this->registerService('SystemConfig', function ($c) use ($config) {
370
+            return new \OC\SystemConfig($config);
371
+        });
372
+
373
+        $this->registerService(\OC\AppConfig::class, function (Server $c) {
374
+            return new \OC\AppConfig($c->getDatabaseConnection());
375
+        });
376
+        $this->registerAlias('AppConfig', \OC\AppConfig::class);
377
+        $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
378
+
379
+        $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
380
+            return new \OC\L10N\Factory(
381
+                $c->getConfig(),
382
+                $c->getRequest(),
383
+                $c->getUserSession(),
384
+                \OC::$SERVERROOT
385
+            );
386
+        });
387
+        $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
388
+
389
+        $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
390
+            $config = $c->getConfig();
391
+            $cacheFactory = $c->getMemCacheFactory();
392
+            return new \OC\URLGenerator(
393
+                $config,
394
+                $cacheFactory
395
+            );
396
+        });
397
+        $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
398
+
399
+        $this->registerService('AppHelper', function ($c) {
400
+            return new \OC\AppHelper();
401
+        });
402
+        $this->registerService('AppFetcher', function ($c) {
403
+            return new AppFetcher(
404
+                $this->getAppDataDir('appstore'),
405
+                $this->getHTTPClientService(),
406
+                $this->query(TimeFactory::class),
407
+                $this->getConfig()
408
+            );
409
+        });
410
+        $this->registerService('CategoryFetcher', function ($c) {
411
+            return new CategoryFetcher(
412
+                $this->getAppDataDir('appstore'),
413
+                $this->getHTTPClientService(),
414
+                $this->query(TimeFactory::class),
415
+                $this->getConfig()
416
+            );
417
+        });
418
+
419
+        $this->registerService(\OCP\ICache::class, function ($c) {
420
+            return new Cache\File();
421
+        });
422
+        $this->registerAlias('UserCache', \OCP\ICache::class);
423
+
424
+        $this->registerService(Factory::class, function (Server $c) {
425
+            $config = $c->getConfig();
426
+
427
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
428
+                $v = \OC_App::getAppVersions();
429
+                $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
430
+                $version = implode(',', $v);
431
+                $instanceId = \OC_Util::getInstanceId();
432
+                $path = \OC::$SERVERROOT;
433
+                $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
434
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
435
+                    $config->getSystemValue('memcache.local', null),
436
+                    $config->getSystemValue('memcache.distributed', null),
437
+                    $config->getSystemValue('memcache.locking', null)
438
+                );
439
+            }
440
+
441
+            return new \OC\Memcache\Factory('', $c->getLogger(),
442
+                '\\OC\\Memcache\\ArrayCache',
443
+                '\\OC\\Memcache\\ArrayCache',
444
+                '\\OC\\Memcache\\ArrayCache'
445
+            );
446
+        });
447
+        $this->registerAlias('MemCacheFactory', Factory::class);
448
+        $this->registerAlias(ICacheFactory::class, Factory::class);
449
+
450
+        $this->registerService('RedisFactory', function (Server $c) {
451
+            $systemConfig = $c->getSystemConfig();
452
+            return new RedisFactory($systemConfig);
453
+        });
454
+
455
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
456
+            return new \OC\Activity\Manager(
457
+                $c->getRequest(),
458
+                $c->getUserSession(),
459
+                $c->getConfig(),
460
+                $c->query(IValidator::class)
461
+            );
462
+        });
463
+        $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
464
+
465
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
466
+            return new \OC\Activity\EventMerger(
467
+                $c->getL10N('lib')
468
+            );
469
+        });
470
+        $this->registerAlias(IValidator::class, Validator::class);
471
+
472
+        $this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
473
+            return new AvatarManager(
474
+                $c->getUserManager(),
475
+                $c->getAppDataDir('avatar'),
476
+                $c->getL10N('lib'),
477
+                $c->getLogger(),
478
+                $c->getConfig()
479
+            );
480
+        });
481
+        $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
482
+
483
+        $this->registerService(\OCP\ILogger::class, function (Server $c) {
484
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
485
+            $logger = Log::getLogClass($logType);
486
+            call_user_func(array($logger, 'init'));
487
+
488
+            return new Log($logger);
489
+        });
490
+        $this->registerAlias('Logger', \OCP\ILogger::class);
491
+
492
+        $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
493
+            $config = $c->getConfig();
494
+            return new \OC\BackgroundJob\JobList(
495
+                $c->getDatabaseConnection(),
496
+                $config,
497
+                new TimeFactory()
498
+            );
499
+        });
500
+        $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
501
+
502
+        $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
503
+            $cacheFactory = $c->getMemCacheFactory();
504
+            $logger = $c->getLogger();
505
+            if ($cacheFactory->isAvailable()) {
506
+                $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
507
+            } else {
508
+                $router = new \OC\Route\Router($logger);
509
+            }
510
+            return $router;
511
+        });
512
+        $this->registerAlias('Router', \OCP\Route\IRouter::class);
513
+
514
+        $this->registerService(\OCP\ISearch::class, function ($c) {
515
+            return new Search();
516
+        });
517
+        $this->registerAlias('Search', \OCP\ISearch::class);
518
+
519
+        $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) {
520
+            return new \OC\Security\RateLimiting\Limiter(
521
+                $this->getUserSession(),
522
+                $this->getRequest(),
523
+                new \OC\AppFramework\Utility\TimeFactory(),
524
+                $c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
525
+            );
526
+        });
527
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
528
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
529
+                $this->getMemCacheFactory(),
530
+                new \OC\AppFramework\Utility\TimeFactory()
531
+            );
532
+        });
533
+
534
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
535
+            return new SecureRandom();
536
+        });
537
+        $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
538
+
539
+        $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
540
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
541
+        });
542
+        $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
543
+
544
+        $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
545
+            return new Hasher($c->getConfig());
546
+        });
547
+        $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
548
+
549
+        $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
550
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
551
+        });
552
+        $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
553
+
554
+        $this->registerService(IDBConnection::class, function (Server $c) {
555
+            $systemConfig = $c->getSystemConfig();
556
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
557
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
558
+            if (!$factory->isValidType($type)) {
559
+                throw new \OC\DatabaseException('Invalid database type');
560
+            }
561
+            $connectionParams = $factory->createConnectionParams();
562
+            $connection = $factory->getConnection($type, $connectionParams);
563
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
564
+            return $connection;
565
+        });
566
+        $this->registerAlias('DatabaseConnection', IDBConnection::class);
567
+
568
+        $this->registerService('HTTPHelper', function (Server $c) {
569
+            $config = $c->getConfig();
570
+            return new HTTPHelper(
571
+                $config,
572
+                $c->getHTTPClientService()
573
+            );
574
+        });
575
+
576
+        $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
577
+            $user = \OC_User::getUser();
578
+            $uid = $user ? $user : null;
579
+            return new ClientService(
580
+                $c->getConfig(),
581
+                new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
582
+            );
583
+        });
584
+        $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
585
+
586
+        $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
587
+            if ($c->getSystemConfig()->getValue('debug', false)) {
588
+                return new EventLogger();
589
+            } else {
590
+                return new NullEventLogger();
591
+            }
592
+        });
593
+        $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
594
+
595
+        $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
596
+            if ($c->getSystemConfig()->getValue('debug', false)) {
597
+                return new QueryLogger();
598
+            } else {
599
+                return new NullQueryLogger();
600
+            }
601
+        });
602
+        $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
603
+
604
+        $this->registerService(TempManager::class, function (Server $c) {
605
+            return new TempManager(
606
+                $c->getLogger(),
607
+                $c->getConfig()
608
+            );
609
+        });
610
+        $this->registerAlias('TempManager', TempManager::class);
611
+        $this->registerAlias(ITempManager::class, TempManager::class);
612
+
613
+        $this->registerService(AppManager::class, function (Server $c) {
614
+            return new \OC\App\AppManager(
615
+                $c->getUserSession(),
616
+                $c->getAppConfig(),
617
+                $c->getGroupManager(),
618
+                $c->getMemCacheFactory(),
619
+                $c->getEventDispatcher()
620
+            );
621
+        });
622
+        $this->registerAlias('AppManager', AppManager::class);
623
+        $this->registerAlias(IAppManager::class, AppManager::class);
624
+
625
+        $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
626
+            return new DateTimeZone(
627
+                $c->getConfig(),
628
+                $c->getSession()
629
+            );
630
+        });
631
+        $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
632
+
633
+        $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
634
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
635
+
636
+            return new DateTimeFormatter(
637
+                $c->getDateTimeZone()->getTimeZone(),
638
+                $c->getL10N('lib', $language)
639
+            );
640
+        });
641
+        $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
642
+
643
+        $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
644
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
645
+            $listener = new UserMountCacheListener($mountCache);
646
+            $listener->listen($c->getUserManager());
647
+            return $mountCache;
648
+        });
649
+        $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
650
+
651
+        $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
652
+            $loader = \OC\Files\Filesystem::getLoader();
653
+            $mountCache = $c->query('UserMountCache');
654
+            $manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
655
+
656
+            // builtin providers
657
+
658
+            $config = $c->getConfig();
659
+            $manager->registerProvider(new CacheMountProvider($config));
660
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
661
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
662
+
663
+            return $manager;
664
+        });
665
+        $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
666
+
667
+        $this->registerService('IniWrapper', function ($c) {
668
+            return new IniGetWrapper();
669
+        });
670
+        $this->registerService('AsyncCommandBus', function (Server $c) {
671
+            $jobList = $c->getJobList();
672
+            return new AsyncBus($jobList);
673
+        });
674
+        $this->registerService('TrustedDomainHelper', function ($c) {
675
+            return new TrustedDomainHelper($this->getConfig());
676
+        });
677
+        $this->registerService('Throttler', function(Server $c) {
678
+            return new Throttler(
679
+                $c->getDatabaseConnection(),
680
+                new TimeFactory(),
681
+                $c->getLogger(),
682
+                $c->getConfig()
683
+            );
684
+        });
685
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
686
+            // IConfig and IAppManager requires a working database. This code
687
+            // might however be called when ownCloud is not yet setup.
688
+            if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
689
+                $config = $c->getConfig();
690
+                $appManager = $c->getAppManager();
691
+            } else {
692
+                $config = null;
693
+                $appManager = null;
694
+            }
695
+
696
+            return new Checker(
697
+                    new EnvironmentHelper(),
698
+                    new FileAccessHelper(),
699
+                    new AppLocator(),
700
+                    $config,
701
+                    $c->getMemCacheFactory(),
702
+                    $appManager,
703
+                    $c->getTempManager()
704
+            );
705
+        });
706
+        $this->registerService(\OCP\IRequest::class, function ($c) {
707
+            if (isset($this['urlParams'])) {
708
+                $urlParams = $this['urlParams'];
709
+            } else {
710
+                $urlParams = [];
711
+            }
712
+
713
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
714
+                && in_array('fakeinput', stream_get_wrappers())
715
+            ) {
716
+                $stream = 'fakeinput://data';
717
+            } else {
718
+                $stream = 'php://input';
719
+            }
720
+
721
+            return new Request(
722
+                [
723
+                    'get' => $_GET,
724
+                    'post' => $_POST,
725
+                    'files' => $_FILES,
726
+                    'server' => $_SERVER,
727
+                    'env' => $_ENV,
728
+                    'cookies' => $_COOKIE,
729
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
730
+                        ? $_SERVER['REQUEST_METHOD']
731
+                        : null,
732
+                    'urlParams' => $urlParams,
733
+                ],
734
+                $this->getSecureRandom(),
735
+                $this->getConfig(),
736
+                $this->getCsrfTokenManager(),
737
+                $stream
738
+            );
739
+        });
740
+        $this->registerAlias('Request', \OCP\IRequest::class);
741
+
742
+        $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
743
+            return new Mailer(
744
+                $c->getConfig(),
745
+                $c->getLogger(),
746
+                $c->query(Defaults::class),
747
+                $c->getURLGenerator(),
748
+                $c->getL10N('lib')
749
+            );
750
+        });
751
+        $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
752
+
753
+        $this->registerService('LDAPProvider', function(Server $c) {
754
+            $config = $c->getConfig();
755
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
756
+            if(is_null($factoryClass)) {
757
+                throw new \Exception('ldapProviderFactory not set');
758
+            }
759
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
760
+            $factory = new $factoryClass($this);
761
+            return $factory->getLDAPProvider();
762
+        });
763
+        $this->registerService('LockingProvider', function (Server $c) {
764
+            $ini = $c->getIniWrapper();
765
+            $config = $c->getConfig();
766
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
767
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
768
+                /** @var \OC\Memcache\Factory $memcacheFactory */
769
+                $memcacheFactory = $c->getMemCacheFactory();
770
+                $memcache = $memcacheFactory->createLocking('lock');
771
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
772
+                    return new MemcacheLockingProvider($memcache, $ttl);
773
+                }
774
+                return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
775
+            }
776
+            return new NoopLockingProvider();
777
+        });
778
+
779
+        $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
780
+            return new \OC\Files\Mount\Manager();
781
+        });
782
+        $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
783
+
784
+        $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
785
+            return new \OC\Files\Type\Detection(
786
+                $c->getURLGenerator(),
787
+                \OC::$configDir,
788
+                \OC::$SERVERROOT . '/resources/config/'
789
+            );
790
+        });
791
+        $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
792
+
793
+        $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
794
+            return new \OC\Files\Type\Loader(
795
+                $c->getDatabaseConnection()
796
+            );
797
+        });
798
+        $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
799
+
800
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
801
+            return new Manager(
802
+                $c->query(IValidator::class)
803
+            );
804
+        });
805
+        $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
806
+
807
+        $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
808
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
809
+            $manager->registerCapability(function () use ($c) {
810
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
811
+            });
812
+            return $manager;
813
+        });
814
+        $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
815
+
816
+        $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
817
+            $config = $c->getConfig();
818
+            $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
819
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
820
+            $factory = new $factoryClass($this);
821
+            return $factory->getManager();
822
+        });
823
+        $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
824
+
825
+        $this->registerService('ThemingDefaults', function(Server $c) {
826
+            /*
827 827
 			 * Dark magic for autoloader.
828 828
 			 * If we do a class_exists it will try to load the class which will
829 829
 			 * make composer cache the result. Resulting in errors when enabling
830 830
 			 * the theming app.
831 831
 			 */
832
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
833
-			if (isset($prefixes['OCA\\Theming\\'])) {
834
-				$classExists = true;
835
-			} else {
836
-				$classExists = false;
837
-			}
838
-
839
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
840
-				return new ThemingDefaults(
841
-					$c->getConfig(),
842
-					$c->getL10N('theming'),
843
-					$c->getURLGenerator(),
844
-					new \OC_Defaults(),
845
-					$c->getAppDataDir('theming'),
846
-					$c->getMemCacheFactory()
847
-				);
848
-			}
849
-			return new \OC_Defaults();
850
-		});
851
-		$this->registerService(EventDispatcher::class, function () {
852
-			return new EventDispatcher();
853
-		});
854
-		$this->registerAlias('EventDispatcher', EventDispatcher::class);
855
-		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
856
-
857
-		$this->registerService('CryptoWrapper', function (Server $c) {
858
-			// FIXME: Instantiiated here due to cyclic dependency
859
-			$request = new Request(
860
-				[
861
-					'get' => $_GET,
862
-					'post' => $_POST,
863
-					'files' => $_FILES,
864
-					'server' => $_SERVER,
865
-					'env' => $_ENV,
866
-					'cookies' => $_COOKIE,
867
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
868
-						? $_SERVER['REQUEST_METHOD']
869
-						: null,
870
-				],
871
-				$c->getSecureRandom(),
872
-				$c->getConfig()
873
-			);
874
-
875
-			return new CryptoWrapper(
876
-				$c->getConfig(),
877
-				$c->getCrypto(),
878
-				$c->getSecureRandom(),
879
-				$request
880
-			);
881
-		});
882
-		$this->registerService('CsrfTokenManager', function (Server $c) {
883
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
884
-
885
-			return new CsrfTokenManager(
886
-				$tokenGenerator,
887
-				$c->query(SessionStorage::class)
888
-			);
889
-		});
890
-		$this->registerService(SessionStorage::class, function (Server $c) {
891
-			return new SessionStorage($c->getSession());
892
-		});
893
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
894
-			return new ContentSecurityPolicyManager();
895
-		});
896
-		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
897
-
898
-		$this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
899
-			return new ContentSecurityPolicyNonceManager(
900
-				$c->getCsrfTokenManager(),
901
-				$c->getRequest()
902
-			);
903
-		});
904
-
905
-		$this->registerService(\OCP\Share\IManager::class, function(Server $c) {
906
-			$config = $c->getConfig();
907
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
908
-			/** @var \OCP\Share\IProviderFactory $factory */
909
-			$factory = new $factoryClass($this);
910
-
911
-			$manager = new \OC\Share20\Manager(
912
-				$c->getLogger(),
913
-				$c->getConfig(),
914
-				$c->getSecureRandom(),
915
-				$c->getHasher(),
916
-				$c->getMountManager(),
917
-				$c->getGroupManager(),
918
-				$c->getL10N('core'),
919
-				$factory,
920
-				$c->getUserManager(),
921
-				$c->getLazyRootFolder(),
922
-				$c->getEventDispatcher()
923
-			);
924
-
925
-			return $manager;
926
-		});
927
-		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
928
-
929
-		$this->registerService('SettingsManager', function(Server $c) {
930
-			$manager = new \OC\Settings\Manager(
931
-				$c->getLogger(),
932
-				$c->getDatabaseConnection(),
933
-				$c->getL10N('lib'),
934
-				$c->getConfig(),
935
-				$c->getEncryptionManager(),
936
-				$c->getUserManager(),
937
-				$c->getLockingProvider(),
938
-				$c->getRequest(),
939
-				new \OC\Settings\Mapper($c->getDatabaseConnection()),
940
-				$c->getURLGenerator()
941
-			);
942
-			return $manager;
943
-		});
944
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
945
-			return new \OC\Files\AppData\Factory(
946
-				$c->getRootFolder(),
947
-				$c->getSystemConfig()
948
-			);
949
-		});
950
-
951
-		$this->registerService('LockdownManager', function (Server $c) {
952
-			return new LockdownManager(function() use ($c) {
953
-				return $c->getSession();
954
-			});
955
-		});
956
-
957
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
958
-			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
959
-		});
960
-
961
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
962
-			return new CloudIdManager();
963
-		});
964
-
965
-		/* To trick DI since we don't extend the DIContainer here */
966
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
967
-			return new CleanPreviewsBackgroundJob(
968
-				$c->getRootFolder(),
969
-				$c->getLogger(),
970
-				$c->getJobList(),
971
-				new TimeFactory()
972
-			);
973
-		});
974
-
975
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
976
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
977
-
978
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
979
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
980
-
981
-		$this->registerService(Defaults::class, function (Server $c) {
982
-			return new Defaults(
983
-				$c->getThemingDefaults()
984
-			);
985
-		});
986
-		$this->registerAlias('Defaults', \OCP\Defaults::class);
987
-
988
-		$this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
989
-			return $c->query(\OCP\IUserSession::class)->getSession();
990
-		});
991
-	}
992
-
993
-	/**
994
-	 * @return \OCP\Contacts\IManager
995
-	 */
996
-	public function getContactsManager() {
997
-		return $this->query('ContactsManager');
998
-	}
999
-
1000
-	/**
1001
-	 * @return \OC\Encryption\Manager
1002
-	 */
1003
-	public function getEncryptionManager() {
1004
-		return $this->query('EncryptionManager');
1005
-	}
1006
-
1007
-	/**
1008
-	 * @return \OC\Encryption\File
1009
-	 */
1010
-	public function getEncryptionFilesHelper() {
1011
-		return $this->query('EncryptionFileHelper');
1012
-	}
1013
-
1014
-	/**
1015
-	 * @return \OCP\Encryption\Keys\IStorage
1016
-	 */
1017
-	public function getEncryptionKeyStorage() {
1018
-		return $this->query('EncryptionKeyStorage');
1019
-	}
1020
-
1021
-	/**
1022
-	 * The current request object holding all information about the request
1023
-	 * currently being processed is returned from this method.
1024
-	 * In case the current execution was not initiated by a web request null is returned
1025
-	 *
1026
-	 * @return \OCP\IRequest
1027
-	 */
1028
-	public function getRequest() {
1029
-		return $this->query('Request');
1030
-	}
1031
-
1032
-	/**
1033
-	 * Returns the preview manager which can create preview images for a given file
1034
-	 *
1035
-	 * @return \OCP\IPreview
1036
-	 */
1037
-	public function getPreviewManager() {
1038
-		return $this->query('PreviewManager');
1039
-	}
1040
-
1041
-	/**
1042
-	 * Returns the tag manager which can get and set tags for different object types
1043
-	 *
1044
-	 * @see \OCP\ITagManager::load()
1045
-	 * @return \OCP\ITagManager
1046
-	 */
1047
-	public function getTagManager() {
1048
-		return $this->query('TagManager');
1049
-	}
1050
-
1051
-	/**
1052
-	 * Returns the system-tag manager
1053
-	 *
1054
-	 * @return \OCP\SystemTag\ISystemTagManager
1055
-	 *
1056
-	 * @since 9.0.0
1057
-	 */
1058
-	public function getSystemTagManager() {
1059
-		return $this->query('SystemTagManager');
1060
-	}
1061
-
1062
-	/**
1063
-	 * Returns the system-tag object mapper
1064
-	 *
1065
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1066
-	 *
1067
-	 * @since 9.0.0
1068
-	 */
1069
-	public function getSystemTagObjectMapper() {
1070
-		return $this->query('SystemTagObjectMapper');
1071
-	}
1072
-
1073
-	/**
1074
-	 * Returns the avatar manager, used for avatar functionality
1075
-	 *
1076
-	 * @return \OCP\IAvatarManager
1077
-	 */
1078
-	public function getAvatarManager() {
1079
-		return $this->query('AvatarManager');
1080
-	}
1081
-
1082
-	/**
1083
-	 * Returns the root folder of ownCloud's data directory
1084
-	 *
1085
-	 * @return \OCP\Files\IRootFolder
1086
-	 */
1087
-	public function getRootFolder() {
1088
-		return $this->query('LazyRootFolder');
1089
-	}
1090
-
1091
-	/**
1092
-	 * Returns the root folder of ownCloud's data directory
1093
-	 * This is the lazy variant so this gets only initialized once it
1094
-	 * is actually used.
1095
-	 *
1096
-	 * @return \OCP\Files\IRootFolder
1097
-	 */
1098
-	public function getLazyRootFolder() {
1099
-		return $this->query('LazyRootFolder');
1100
-	}
1101
-
1102
-	/**
1103
-	 * Returns a view to ownCloud's files folder
1104
-	 *
1105
-	 * @param string $userId user ID
1106
-	 * @return \OCP\Files\Folder|null
1107
-	 */
1108
-	public function getUserFolder($userId = null) {
1109
-		if ($userId === null) {
1110
-			$user = $this->getUserSession()->getUser();
1111
-			if (!$user) {
1112
-				return null;
1113
-			}
1114
-			$userId = $user->getUID();
1115
-		}
1116
-		$root = $this->getRootFolder();
1117
-		return $root->getUserFolder($userId);
1118
-	}
1119
-
1120
-	/**
1121
-	 * Returns an app-specific view in ownClouds data directory
1122
-	 *
1123
-	 * @return \OCP\Files\Folder
1124
-	 * @deprecated since 9.2.0 use IAppData
1125
-	 */
1126
-	public function getAppFolder() {
1127
-		$dir = '/' . \OC_App::getCurrentApp();
1128
-		$root = $this->getRootFolder();
1129
-		if (!$root->nodeExists($dir)) {
1130
-			$folder = $root->newFolder($dir);
1131
-		} else {
1132
-			$folder = $root->get($dir);
1133
-		}
1134
-		return $folder;
1135
-	}
1136
-
1137
-	/**
1138
-	 * @return \OC\User\Manager
1139
-	 */
1140
-	public function getUserManager() {
1141
-		return $this->query('UserManager');
1142
-	}
1143
-
1144
-	/**
1145
-	 * @return \OC\Group\Manager
1146
-	 */
1147
-	public function getGroupManager() {
1148
-		return $this->query('GroupManager');
1149
-	}
1150
-
1151
-	/**
1152
-	 * @return \OC\User\Session
1153
-	 */
1154
-	public function getUserSession() {
1155
-		return $this->query('UserSession');
1156
-	}
1157
-
1158
-	/**
1159
-	 * @return \OCP\ISession
1160
-	 */
1161
-	public function getSession() {
1162
-		return $this->query('UserSession')->getSession();
1163
-	}
1164
-
1165
-	/**
1166
-	 * @param \OCP\ISession $session
1167
-	 */
1168
-	public function setSession(\OCP\ISession $session) {
1169
-		$this->query(SessionStorage::class)->setSession($session);
1170
-		$this->query('UserSession')->setSession($session);
1171
-		$this->query(Store::class)->setSession($session);
1172
-	}
1173
-
1174
-	/**
1175
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1176
-	 */
1177
-	public function getTwoFactorAuthManager() {
1178
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1179
-	}
1180
-
1181
-	/**
1182
-	 * @return \OC\NavigationManager
1183
-	 */
1184
-	public function getNavigationManager() {
1185
-		return $this->query('NavigationManager');
1186
-	}
1187
-
1188
-	/**
1189
-	 * @return \OCP\IConfig
1190
-	 */
1191
-	public function getConfig() {
1192
-		return $this->query('AllConfig');
1193
-	}
1194
-
1195
-	/**
1196
-	 * @internal For internal use only
1197
-	 * @return \OC\SystemConfig
1198
-	 */
1199
-	public function getSystemConfig() {
1200
-		return $this->query('SystemConfig');
1201
-	}
1202
-
1203
-	/**
1204
-	 * Returns the app config manager
1205
-	 *
1206
-	 * @return \OCP\IAppConfig
1207
-	 */
1208
-	public function getAppConfig() {
1209
-		return $this->query('AppConfig');
1210
-	}
1211
-
1212
-	/**
1213
-	 * @return \OCP\L10N\IFactory
1214
-	 */
1215
-	public function getL10NFactory() {
1216
-		return $this->query('L10NFactory');
1217
-	}
1218
-
1219
-	/**
1220
-	 * get an L10N instance
1221
-	 *
1222
-	 * @param string $app appid
1223
-	 * @param string $lang
1224
-	 * @return IL10N
1225
-	 */
1226
-	public function getL10N($app, $lang = null) {
1227
-		return $this->getL10NFactory()->get($app, $lang);
1228
-	}
1229
-
1230
-	/**
1231
-	 * @return \OCP\IURLGenerator
1232
-	 */
1233
-	public function getURLGenerator() {
1234
-		return $this->query('URLGenerator');
1235
-	}
1236
-
1237
-	/**
1238
-	 * @return \OCP\IHelper
1239
-	 */
1240
-	public function getHelper() {
1241
-		return $this->query('AppHelper');
1242
-	}
1243
-
1244
-	/**
1245
-	 * @return AppFetcher
1246
-	 */
1247
-	public function getAppFetcher() {
1248
-		return $this->query('AppFetcher');
1249
-	}
1250
-
1251
-	/**
1252
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1253
-	 * getMemCacheFactory() instead.
1254
-	 *
1255
-	 * @return \OCP\ICache
1256
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1257
-	 */
1258
-	public function getCache() {
1259
-		return $this->query('UserCache');
1260
-	}
1261
-
1262
-	/**
1263
-	 * Returns an \OCP\CacheFactory instance
1264
-	 *
1265
-	 * @return \OCP\ICacheFactory
1266
-	 */
1267
-	public function getMemCacheFactory() {
1268
-		return $this->query('MemCacheFactory');
1269
-	}
1270
-
1271
-	/**
1272
-	 * Returns an \OC\RedisFactory instance
1273
-	 *
1274
-	 * @return \OC\RedisFactory
1275
-	 */
1276
-	public function getGetRedisFactory() {
1277
-		return $this->query('RedisFactory');
1278
-	}
1279
-
1280
-
1281
-	/**
1282
-	 * Returns the current session
1283
-	 *
1284
-	 * @return \OCP\IDBConnection
1285
-	 */
1286
-	public function getDatabaseConnection() {
1287
-		return $this->query('DatabaseConnection');
1288
-	}
1289
-
1290
-	/**
1291
-	 * Returns the activity manager
1292
-	 *
1293
-	 * @return \OCP\Activity\IManager
1294
-	 */
1295
-	public function getActivityManager() {
1296
-		return $this->query('ActivityManager');
1297
-	}
1298
-
1299
-	/**
1300
-	 * Returns an job list for controlling background jobs
1301
-	 *
1302
-	 * @return \OCP\BackgroundJob\IJobList
1303
-	 */
1304
-	public function getJobList() {
1305
-		return $this->query('JobList');
1306
-	}
1307
-
1308
-	/**
1309
-	 * Returns a logger instance
1310
-	 *
1311
-	 * @return \OCP\ILogger
1312
-	 */
1313
-	public function getLogger() {
1314
-		return $this->query('Logger');
1315
-	}
1316
-
1317
-	/**
1318
-	 * Returns a router for generating and matching urls
1319
-	 *
1320
-	 * @return \OCP\Route\IRouter
1321
-	 */
1322
-	public function getRouter() {
1323
-		return $this->query('Router');
1324
-	}
1325
-
1326
-	/**
1327
-	 * Returns a search instance
1328
-	 *
1329
-	 * @return \OCP\ISearch
1330
-	 */
1331
-	public function getSearch() {
1332
-		return $this->query('Search');
1333
-	}
1334
-
1335
-	/**
1336
-	 * Returns a SecureRandom instance
1337
-	 *
1338
-	 * @return \OCP\Security\ISecureRandom
1339
-	 */
1340
-	public function getSecureRandom() {
1341
-		return $this->query('SecureRandom');
1342
-	}
1343
-
1344
-	/**
1345
-	 * Returns a Crypto instance
1346
-	 *
1347
-	 * @return \OCP\Security\ICrypto
1348
-	 */
1349
-	public function getCrypto() {
1350
-		return $this->query('Crypto');
1351
-	}
1352
-
1353
-	/**
1354
-	 * Returns a Hasher instance
1355
-	 *
1356
-	 * @return \OCP\Security\IHasher
1357
-	 */
1358
-	public function getHasher() {
1359
-		return $this->query('Hasher');
1360
-	}
1361
-
1362
-	/**
1363
-	 * Returns a CredentialsManager instance
1364
-	 *
1365
-	 * @return \OCP\Security\ICredentialsManager
1366
-	 */
1367
-	public function getCredentialsManager() {
1368
-		return $this->query('CredentialsManager');
1369
-	}
1370
-
1371
-	/**
1372
-	 * Returns an instance of the HTTP helper class
1373
-	 *
1374
-	 * @deprecated Use getHTTPClientService()
1375
-	 * @return \OC\HTTPHelper
1376
-	 */
1377
-	public function getHTTPHelper() {
1378
-		return $this->query('HTTPHelper');
1379
-	}
1380
-
1381
-	/**
1382
-	 * Get the certificate manager for the user
1383
-	 *
1384
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1385
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1386
-	 */
1387
-	public function getCertificateManager($userId = '') {
1388
-		if ($userId === '') {
1389
-			$userSession = $this->getUserSession();
1390
-			$user = $userSession->getUser();
1391
-			if (is_null($user)) {
1392
-				return null;
1393
-			}
1394
-			$userId = $user->getUID();
1395
-		}
1396
-		return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
1397
-	}
1398
-
1399
-	/**
1400
-	 * Returns an instance of the HTTP client service
1401
-	 *
1402
-	 * @return \OCP\Http\Client\IClientService
1403
-	 */
1404
-	public function getHTTPClientService() {
1405
-		return $this->query('HttpClientService');
1406
-	}
1407
-
1408
-	/**
1409
-	 * Create a new event source
1410
-	 *
1411
-	 * @return \OCP\IEventSource
1412
-	 */
1413
-	public function createEventSource() {
1414
-		return new \OC_EventSource();
1415
-	}
1416
-
1417
-	/**
1418
-	 * Get the active event logger
1419
-	 *
1420
-	 * The returned logger only logs data when debug mode is enabled
1421
-	 *
1422
-	 * @return \OCP\Diagnostics\IEventLogger
1423
-	 */
1424
-	public function getEventLogger() {
1425
-		return $this->query('EventLogger');
1426
-	}
1427
-
1428
-	/**
1429
-	 * Get the active query logger
1430
-	 *
1431
-	 * The returned logger only logs data when debug mode is enabled
1432
-	 *
1433
-	 * @return \OCP\Diagnostics\IQueryLogger
1434
-	 */
1435
-	public function getQueryLogger() {
1436
-		return $this->query('QueryLogger');
1437
-	}
1438
-
1439
-	/**
1440
-	 * Get the manager for temporary files and folders
1441
-	 *
1442
-	 * @return \OCP\ITempManager
1443
-	 */
1444
-	public function getTempManager() {
1445
-		return $this->query('TempManager');
1446
-	}
1447
-
1448
-	/**
1449
-	 * Get the app manager
1450
-	 *
1451
-	 * @return \OCP\App\IAppManager
1452
-	 */
1453
-	public function getAppManager() {
1454
-		return $this->query('AppManager');
1455
-	}
1456
-
1457
-	/**
1458
-	 * Creates a new mailer
1459
-	 *
1460
-	 * @return \OCP\Mail\IMailer
1461
-	 */
1462
-	public function getMailer() {
1463
-		return $this->query('Mailer');
1464
-	}
1465
-
1466
-	/**
1467
-	 * Get the webroot
1468
-	 *
1469
-	 * @return string
1470
-	 */
1471
-	public function getWebRoot() {
1472
-		return $this->webRoot;
1473
-	}
1474
-
1475
-	/**
1476
-	 * @return \OC\OCSClient
1477
-	 */
1478
-	public function getOcsClient() {
1479
-		return $this->query('OcsClient');
1480
-	}
1481
-
1482
-	/**
1483
-	 * @return \OCP\IDateTimeZone
1484
-	 */
1485
-	public function getDateTimeZone() {
1486
-		return $this->query('DateTimeZone');
1487
-	}
1488
-
1489
-	/**
1490
-	 * @return \OCP\IDateTimeFormatter
1491
-	 */
1492
-	public function getDateTimeFormatter() {
1493
-		return $this->query('DateTimeFormatter');
1494
-	}
1495
-
1496
-	/**
1497
-	 * @return \OCP\Files\Config\IMountProviderCollection
1498
-	 */
1499
-	public function getMountProviderCollection() {
1500
-		return $this->query('MountConfigManager');
1501
-	}
1502
-
1503
-	/**
1504
-	 * Get the IniWrapper
1505
-	 *
1506
-	 * @return IniGetWrapper
1507
-	 */
1508
-	public function getIniWrapper() {
1509
-		return $this->query('IniWrapper');
1510
-	}
1511
-
1512
-	/**
1513
-	 * @return \OCP\Command\IBus
1514
-	 */
1515
-	public function getCommandBus() {
1516
-		return $this->query('AsyncCommandBus');
1517
-	}
1518
-
1519
-	/**
1520
-	 * Get the trusted domain helper
1521
-	 *
1522
-	 * @return TrustedDomainHelper
1523
-	 */
1524
-	public function getTrustedDomainHelper() {
1525
-		return $this->query('TrustedDomainHelper');
1526
-	}
1527
-
1528
-	/**
1529
-	 * Get the locking provider
1530
-	 *
1531
-	 * @return \OCP\Lock\ILockingProvider
1532
-	 * @since 8.1.0
1533
-	 */
1534
-	public function getLockingProvider() {
1535
-		return $this->query('LockingProvider');
1536
-	}
1537
-
1538
-	/**
1539
-	 * @return \OCP\Files\Mount\IMountManager
1540
-	 **/
1541
-	function getMountManager() {
1542
-		return $this->query('MountManager');
1543
-	}
1544
-
1545
-	/** @return \OCP\Files\Config\IUserMountCache */
1546
-	function getUserMountCache() {
1547
-		return $this->query('UserMountCache');
1548
-	}
1549
-
1550
-	/**
1551
-	 * Get the MimeTypeDetector
1552
-	 *
1553
-	 * @return \OCP\Files\IMimeTypeDetector
1554
-	 */
1555
-	public function getMimeTypeDetector() {
1556
-		return $this->query('MimeTypeDetector');
1557
-	}
1558
-
1559
-	/**
1560
-	 * Get the MimeTypeLoader
1561
-	 *
1562
-	 * @return \OCP\Files\IMimeTypeLoader
1563
-	 */
1564
-	public function getMimeTypeLoader() {
1565
-		return $this->query('MimeTypeLoader');
1566
-	}
1567
-
1568
-	/**
1569
-	 * Get the manager of all the capabilities
1570
-	 *
1571
-	 * @return \OC\CapabilitiesManager
1572
-	 */
1573
-	public function getCapabilitiesManager() {
1574
-		return $this->query('CapabilitiesManager');
1575
-	}
1576
-
1577
-	/**
1578
-	 * Get the EventDispatcher
1579
-	 *
1580
-	 * @return EventDispatcherInterface
1581
-	 * @since 8.2.0
1582
-	 */
1583
-	public function getEventDispatcher() {
1584
-		return $this->query('EventDispatcher');
1585
-	}
1586
-
1587
-	/**
1588
-	 * Get the Notification Manager
1589
-	 *
1590
-	 * @return \OCP\Notification\IManager
1591
-	 * @since 8.2.0
1592
-	 */
1593
-	public function getNotificationManager() {
1594
-		return $this->query('NotificationManager');
1595
-	}
1596
-
1597
-	/**
1598
-	 * @return \OCP\Comments\ICommentsManager
1599
-	 */
1600
-	public function getCommentsManager() {
1601
-		return $this->query('CommentsManager');
1602
-	}
1603
-
1604
-	/**
1605
-	 * @return \OCA\Theming\ThemingDefaults
1606
-	 */
1607
-	public function getThemingDefaults() {
1608
-		return $this->query('ThemingDefaults');
1609
-	}
1610
-
1611
-	/**
1612
-	 * @return \OC\IntegrityCheck\Checker
1613
-	 */
1614
-	public function getIntegrityCodeChecker() {
1615
-		return $this->query('IntegrityCodeChecker');
1616
-	}
1617
-
1618
-	/**
1619
-	 * @return \OC\Session\CryptoWrapper
1620
-	 */
1621
-	public function getSessionCryptoWrapper() {
1622
-		return $this->query('CryptoWrapper');
1623
-	}
1624
-
1625
-	/**
1626
-	 * @return CsrfTokenManager
1627
-	 */
1628
-	public function getCsrfTokenManager() {
1629
-		return $this->query('CsrfTokenManager');
1630
-	}
1631
-
1632
-	/**
1633
-	 * @return Throttler
1634
-	 */
1635
-	public function getBruteForceThrottler() {
1636
-		return $this->query('Throttler');
1637
-	}
1638
-
1639
-	/**
1640
-	 * @return IContentSecurityPolicyManager
1641
-	 */
1642
-	public function getContentSecurityPolicyManager() {
1643
-		return $this->query('ContentSecurityPolicyManager');
1644
-	}
1645
-
1646
-	/**
1647
-	 * @return ContentSecurityPolicyNonceManager
1648
-	 */
1649
-	public function getContentSecurityPolicyNonceManager() {
1650
-		return $this->query('ContentSecurityPolicyNonceManager');
1651
-	}
1652
-
1653
-	/**
1654
-	 * Not a public API as of 8.2, wait for 9.0
1655
-	 *
1656
-	 * @return \OCA\Files_External\Service\BackendService
1657
-	 */
1658
-	public function getStoragesBackendService() {
1659
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1660
-	}
1661
-
1662
-	/**
1663
-	 * Not a public API as of 8.2, wait for 9.0
1664
-	 *
1665
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1666
-	 */
1667
-	public function getGlobalStoragesService() {
1668
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1669
-	}
1670
-
1671
-	/**
1672
-	 * Not a public API as of 8.2, wait for 9.0
1673
-	 *
1674
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1675
-	 */
1676
-	public function getUserGlobalStoragesService() {
1677
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1678
-	}
1679
-
1680
-	/**
1681
-	 * Not a public API as of 8.2, wait for 9.0
1682
-	 *
1683
-	 * @return \OCA\Files_External\Service\UserStoragesService
1684
-	 */
1685
-	public function getUserStoragesService() {
1686
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1687
-	}
1688
-
1689
-	/**
1690
-	 * @return \OCP\Share\IManager
1691
-	 */
1692
-	public function getShareManager() {
1693
-		return $this->query('ShareManager');
1694
-	}
1695
-
1696
-	/**
1697
-	 * Returns the LDAP Provider
1698
-	 *
1699
-	 * @return \OCP\LDAP\ILDAPProvider
1700
-	 */
1701
-	public function getLDAPProvider() {
1702
-		return $this->query('LDAPProvider');
1703
-	}
1704
-
1705
-	/**
1706
-	 * @return \OCP\Settings\IManager
1707
-	 */
1708
-	public function getSettingsManager() {
1709
-		return $this->query('SettingsManager');
1710
-	}
1711
-
1712
-	/**
1713
-	 * @return \OCP\Files\IAppData
1714
-	 */
1715
-	public function getAppDataDir($app) {
1716
-		/** @var \OC\Files\AppData\Factory $factory */
1717
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
1718
-		return $factory->get($app);
1719
-	}
1720
-
1721
-	/**
1722
-	 * @return \OCP\Lockdown\ILockdownManager
1723
-	 */
1724
-	public function getLockdownManager() {
1725
-		return $this->query('LockdownManager');
1726
-	}
1727
-
1728
-	/**
1729
-	 * @return \OCP\Federation\ICloudIdManager
1730
-	 */
1731
-	public function getCloudIdManager() {
1732
-		return $this->query(ICloudIdManager::class);
1733
-	}
832
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
833
+            if (isset($prefixes['OCA\\Theming\\'])) {
834
+                $classExists = true;
835
+            } else {
836
+                $classExists = false;
837
+            }
838
+
839
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
840
+                return new ThemingDefaults(
841
+                    $c->getConfig(),
842
+                    $c->getL10N('theming'),
843
+                    $c->getURLGenerator(),
844
+                    new \OC_Defaults(),
845
+                    $c->getAppDataDir('theming'),
846
+                    $c->getMemCacheFactory()
847
+                );
848
+            }
849
+            return new \OC_Defaults();
850
+        });
851
+        $this->registerService(EventDispatcher::class, function () {
852
+            return new EventDispatcher();
853
+        });
854
+        $this->registerAlias('EventDispatcher', EventDispatcher::class);
855
+        $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
856
+
857
+        $this->registerService('CryptoWrapper', function (Server $c) {
858
+            // FIXME: Instantiiated here due to cyclic dependency
859
+            $request = new Request(
860
+                [
861
+                    'get' => $_GET,
862
+                    'post' => $_POST,
863
+                    'files' => $_FILES,
864
+                    'server' => $_SERVER,
865
+                    'env' => $_ENV,
866
+                    'cookies' => $_COOKIE,
867
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
868
+                        ? $_SERVER['REQUEST_METHOD']
869
+                        : null,
870
+                ],
871
+                $c->getSecureRandom(),
872
+                $c->getConfig()
873
+            );
874
+
875
+            return new CryptoWrapper(
876
+                $c->getConfig(),
877
+                $c->getCrypto(),
878
+                $c->getSecureRandom(),
879
+                $request
880
+            );
881
+        });
882
+        $this->registerService('CsrfTokenManager', function (Server $c) {
883
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
884
+
885
+            return new CsrfTokenManager(
886
+                $tokenGenerator,
887
+                $c->query(SessionStorage::class)
888
+            );
889
+        });
890
+        $this->registerService(SessionStorage::class, function (Server $c) {
891
+            return new SessionStorage($c->getSession());
892
+        });
893
+        $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
894
+            return new ContentSecurityPolicyManager();
895
+        });
896
+        $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
897
+
898
+        $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
899
+            return new ContentSecurityPolicyNonceManager(
900
+                $c->getCsrfTokenManager(),
901
+                $c->getRequest()
902
+            );
903
+        });
904
+
905
+        $this->registerService(\OCP\Share\IManager::class, function(Server $c) {
906
+            $config = $c->getConfig();
907
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
908
+            /** @var \OCP\Share\IProviderFactory $factory */
909
+            $factory = new $factoryClass($this);
910
+
911
+            $manager = new \OC\Share20\Manager(
912
+                $c->getLogger(),
913
+                $c->getConfig(),
914
+                $c->getSecureRandom(),
915
+                $c->getHasher(),
916
+                $c->getMountManager(),
917
+                $c->getGroupManager(),
918
+                $c->getL10N('core'),
919
+                $factory,
920
+                $c->getUserManager(),
921
+                $c->getLazyRootFolder(),
922
+                $c->getEventDispatcher()
923
+            );
924
+
925
+            return $manager;
926
+        });
927
+        $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
928
+
929
+        $this->registerService('SettingsManager', function(Server $c) {
930
+            $manager = new \OC\Settings\Manager(
931
+                $c->getLogger(),
932
+                $c->getDatabaseConnection(),
933
+                $c->getL10N('lib'),
934
+                $c->getConfig(),
935
+                $c->getEncryptionManager(),
936
+                $c->getUserManager(),
937
+                $c->getLockingProvider(),
938
+                $c->getRequest(),
939
+                new \OC\Settings\Mapper($c->getDatabaseConnection()),
940
+                $c->getURLGenerator()
941
+            );
942
+            return $manager;
943
+        });
944
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
945
+            return new \OC\Files\AppData\Factory(
946
+                $c->getRootFolder(),
947
+                $c->getSystemConfig()
948
+            );
949
+        });
950
+
951
+        $this->registerService('LockdownManager', function (Server $c) {
952
+            return new LockdownManager(function() use ($c) {
953
+                return $c->getSession();
954
+            });
955
+        });
956
+
957
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
958
+            return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
959
+        });
960
+
961
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
962
+            return new CloudIdManager();
963
+        });
964
+
965
+        /* To trick DI since we don't extend the DIContainer here */
966
+        $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
967
+            return new CleanPreviewsBackgroundJob(
968
+                $c->getRootFolder(),
969
+                $c->getLogger(),
970
+                $c->getJobList(),
971
+                new TimeFactory()
972
+            );
973
+        });
974
+
975
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
976
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
977
+
978
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
979
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
980
+
981
+        $this->registerService(Defaults::class, function (Server $c) {
982
+            return new Defaults(
983
+                $c->getThemingDefaults()
984
+            );
985
+        });
986
+        $this->registerAlias('Defaults', \OCP\Defaults::class);
987
+
988
+        $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
989
+            return $c->query(\OCP\IUserSession::class)->getSession();
990
+        });
991
+    }
992
+
993
+    /**
994
+     * @return \OCP\Contacts\IManager
995
+     */
996
+    public function getContactsManager() {
997
+        return $this->query('ContactsManager');
998
+    }
999
+
1000
+    /**
1001
+     * @return \OC\Encryption\Manager
1002
+     */
1003
+    public function getEncryptionManager() {
1004
+        return $this->query('EncryptionManager');
1005
+    }
1006
+
1007
+    /**
1008
+     * @return \OC\Encryption\File
1009
+     */
1010
+    public function getEncryptionFilesHelper() {
1011
+        return $this->query('EncryptionFileHelper');
1012
+    }
1013
+
1014
+    /**
1015
+     * @return \OCP\Encryption\Keys\IStorage
1016
+     */
1017
+    public function getEncryptionKeyStorage() {
1018
+        return $this->query('EncryptionKeyStorage');
1019
+    }
1020
+
1021
+    /**
1022
+     * The current request object holding all information about the request
1023
+     * currently being processed is returned from this method.
1024
+     * In case the current execution was not initiated by a web request null is returned
1025
+     *
1026
+     * @return \OCP\IRequest
1027
+     */
1028
+    public function getRequest() {
1029
+        return $this->query('Request');
1030
+    }
1031
+
1032
+    /**
1033
+     * Returns the preview manager which can create preview images for a given file
1034
+     *
1035
+     * @return \OCP\IPreview
1036
+     */
1037
+    public function getPreviewManager() {
1038
+        return $this->query('PreviewManager');
1039
+    }
1040
+
1041
+    /**
1042
+     * Returns the tag manager which can get and set tags for different object types
1043
+     *
1044
+     * @see \OCP\ITagManager::load()
1045
+     * @return \OCP\ITagManager
1046
+     */
1047
+    public function getTagManager() {
1048
+        return $this->query('TagManager');
1049
+    }
1050
+
1051
+    /**
1052
+     * Returns the system-tag manager
1053
+     *
1054
+     * @return \OCP\SystemTag\ISystemTagManager
1055
+     *
1056
+     * @since 9.0.0
1057
+     */
1058
+    public function getSystemTagManager() {
1059
+        return $this->query('SystemTagManager');
1060
+    }
1061
+
1062
+    /**
1063
+     * Returns the system-tag object mapper
1064
+     *
1065
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
1066
+     *
1067
+     * @since 9.0.0
1068
+     */
1069
+    public function getSystemTagObjectMapper() {
1070
+        return $this->query('SystemTagObjectMapper');
1071
+    }
1072
+
1073
+    /**
1074
+     * Returns the avatar manager, used for avatar functionality
1075
+     *
1076
+     * @return \OCP\IAvatarManager
1077
+     */
1078
+    public function getAvatarManager() {
1079
+        return $this->query('AvatarManager');
1080
+    }
1081
+
1082
+    /**
1083
+     * Returns the root folder of ownCloud's data directory
1084
+     *
1085
+     * @return \OCP\Files\IRootFolder
1086
+     */
1087
+    public function getRootFolder() {
1088
+        return $this->query('LazyRootFolder');
1089
+    }
1090
+
1091
+    /**
1092
+     * Returns the root folder of ownCloud's data directory
1093
+     * This is the lazy variant so this gets only initialized once it
1094
+     * is actually used.
1095
+     *
1096
+     * @return \OCP\Files\IRootFolder
1097
+     */
1098
+    public function getLazyRootFolder() {
1099
+        return $this->query('LazyRootFolder');
1100
+    }
1101
+
1102
+    /**
1103
+     * Returns a view to ownCloud's files folder
1104
+     *
1105
+     * @param string $userId user ID
1106
+     * @return \OCP\Files\Folder|null
1107
+     */
1108
+    public function getUserFolder($userId = null) {
1109
+        if ($userId === null) {
1110
+            $user = $this->getUserSession()->getUser();
1111
+            if (!$user) {
1112
+                return null;
1113
+            }
1114
+            $userId = $user->getUID();
1115
+        }
1116
+        $root = $this->getRootFolder();
1117
+        return $root->getUserFolder($userId);
1118
+    }
1119
+
1120
+    /**
1121
+     * Returns an app-specific view in ownClouds data directory
1122
+     *
1123
+     * @return \OCP\Files\Folder
1124
+     * @deprecated since 9.2.0 use IAppData
1125
+     */
1126
+    public function getAppFolder() {
1127
+        $dir = '/' . \OC_App::getCurrentApp();
1128
+        $root = $this->getRootFolder();
1129
+        if (!$root->nodeExists($dir)) {
1130
+            $folder = $root->newFolder($dir);
1131
+        } else {
1132
+            $folder = $root->get($dir);
1133
+        }
1134
+        return $folder;
1135
+    }
1136
+
1137
+    /**
1138
+     * @return \OC\User\Manager
1139
+     */
1140
+    public function getUserManager() {
1141
+        return $this->query('UserManager');
1142
+    }
1143
+
1144
+    /**
1145
+     * @return \OC\Group\Manager
1146
+     */
1147
+    public function getGroupManager() {
1148
+        return $this->query('GroupManager');
1149
+    }
1150
+
1151
+    /**
1152
+     * @return \OC\User\Session
1153
+     */
1154
+    public function getUserSession() {
1155
+        return $this->query('UserSession');
1156
+    }
1157
+
1158
+    /**
1159
+     * @return \OCP\ISession
1160
+     */
1161
+    public function getSession() {
1162
+        return $this->query('UserSession')->getSession();
1163
+    }
1164
+
1165
+    /**
1166
+     * @param \OCP\ISession $session
1167
+     */
1168
+    public function setSession(\OCP\ISession $session) {
1169
+        $this->query(SessionStorage::class)->setSession($session);
1170
+        $this->query('UserSession')->setSession($session);
1171
+        $this->query(Store::class)->setSession($session);
1172
+    }
1173
+
1174
+    /**
1175
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1176
+     */
1177
+    public function getTwoFactorAuthManager() {
1178
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1179
+    }
1180
+
1181
+    /**
1182
+     * @return \OC\NavigationManager
1183
+     */
1184
+    public function getNavigationManager() {
1185
+        return $this->query('NavigationManager');
1186
+    }
1187
+
1188
+    /**
1189
+     * @return \OCP\IConfig
1190
+     */
1191
+    public function getConfig() {
1192
+        return $this->query('AllConfig');
1193
+    }
1194
+
1195
+    /**
1196
+     * @internal For internal use only
1197
+     * @return \OC\SystemConfig
1198
+     */
1199
+    public function getSystemConfig() {
1200
+        return $this->query('SystemConfig');
1201
+    }
1202
+
1203
+    /**
1204
+     * Returns the app config manager
1205
+     *
1206
+     * @return \OCP\IAppConfig
1207
+     */
1208
+    public function getAppConfig() {
1209
+        return $this->query('AppConfig');
1210
+    }
1211
+
1212
+    /**
1213
+     * @return \OCP\L10N\IFactory
1214
+     */
1215
+    public function getL10NFactory() {
1216
+        return $this->query('L10NFactory');
1217
+    }
1218
+
1219
+    /**
1220
+     * get an L10N instance
1221
+     *
1222
+     * @param string $app appid
1223
+     * @param string $lang
1224
+     * @return IL10N
1225
+     */
1226
+    public function getL10N($app, $lang = null) {
1227
+        return $this->getL10NFactory()->get($app, $lang);
1228
+    }
1229
+
1230
+    /**
1231
+     * @return \OCP\IURLGenerator
1232
+     */
1233
+    public function getURLGenerator() {
1234
+        return $this->query('URLGenerator');
1235
+    }
1236
+
1237
+    /**
1238
+     * @return \OCP\IHelper
1239
+     */
1240
+    public function getHelper() {
1241
+        return $this->query('AppHelper');
1242
+    }
1243
+
1244
+    /**
1245
+     * @return AppFetcher
1246
+     */
1247
+    public function getAppFetcher() {
1248
+        return $this->query('AppFetcher');
1249
+    }
1250
+
1251
+    /**
1252
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1253
+     * getMemCacheFactory() instead.
1254
+     *
1255
+     * @return \OCP\ICache
1256
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1257
+     */
1258
+    public function getCache() {
1259
+        return $this->query('UserCache');
1260
+    }
1261
+
1262
+    /**
1263
+     * Returns an \OCP\CacheFactory instance
1264
+     *
1265
+     * @return \OCP\ICacheFactory
1266
+     */
1267
+    public function getMemCacheFactory() {
1268
+        return $this->query('MemCacheFactory');
1269
+    }
1270
+
1271
+    /**
1272
+     * Returns an \OC\RedisFactory instance
1273
+     *
1274
+     * @return \OC\RedisFactory
1275
+     */
1276
+    public function getGetRedisFactory() {
1277
+        return $this->query('RedisFactory');
1278
+    }
1279
+
1280
+
1281
+    /**
1282
+     * Returns the current session
1283
+     *
1284
+     * @return \OCP\IDBConnection
1285
+     */
1286
+    public function getDatabaseConnection() {
1287
+        return $this->query('DatabaseConnection');
1288
+    }
1289
+
1290
+    /**
1291
+     * Returns the activity manager
1292
+     *
1293
+     * @return \OCP\Activity\IManager
1294
+     */
1295
+    public function getActivityManager() {
1296
+        return $this->query('ActivityManager');
1297
+    }
1298
+
1299
+    /**
1300
+     * Returns an job list for controlling background jobs
1301
+     *
1302
+     * @return \OCP\BackgroundJob\IJobList
1303
+     */
1304
+    public function getJobList() {
1305
+        return $this->query('JobList');
1306
+    }
1307
+
1308
+    /**
1309
+     * Returns a logger instance
1310
+     *
1311
+     * @return \OCP\ILogger
1312
+     */
1313
+    public function getLogger() {
1314
+        return $this->query('Logger');
1315
+    }
1316
+
1317
+    /**
1318
+     * Returns a router for generating and matching urls
1319
+     *
1320
+     * @return \OCP\Route\IRouter
1321
+     */
1322
+    public function getRouter() {
1323
+        return $this->query('Router');
1324
+    }
1325
+
1326
+    /**
1327
+     * Returns a search instance
1328
+     *
1329
+     * @return \OCP\ISearch
1330
+     */
1331
+    public function getSearch() {
1332
+        return $this->query('Search');
1333
+    }
1334
+
1335
+    /**
1336
+     * Returns a SecureRandom instance
1337
+     *
1338
+     * @return \OCP\Security\ISecureRandom
1339
+     */
1340
+    public function getSecureRandom() {
1341
+        return $this->query('SecureRandom');
1342
+    }
1343
+
1344
+    /**
1345
+     * Returns a Crypto instance
1346
+     *
1347
+     * @return \OCP\Security\ICrypto
1348
+     */
1349
+    public function getCrypto() {
1350
+        return $this->query('Crypto');
1351
+    }
1352
+
1353
+    /**
1354
+     * Returns a Hasher instance
1355
+     *
1356
+     * @return \OCP\Security\IHasher
1357
+     */
1358
+    public function getHasher() {
1359
+        return $this->query('Hasher');
1360
+    }
1361
+
1362
+    /**
1363
+     * Returns a CredentialsManager instance
1364
+     *
1365
+     * @return \OCP\Security\ICredentialsManager
1366
+     */
1367
+    public function getCredentialsManager() {
1368
+        return $this->query('CredentialsManager');
1369
+    }
1370
+
1371
+    /**
1372
+     * Returns an instance of the HTTP helper class
1373
+     *
1374
+     * @deprecated Use getHTTPClientService()
1375
+     * @return \OC\HTTPHelper
1376
+     */
1377
+    public function getHTTPHelper() {
1378
+        return $this->query('HTTPHelper');
1379
+    }
1380
+
1381
+    /**
1382
+     * Get the certificate manager for the user
1383
+     *
1384
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1385
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1386
+     */
1387
+    public function getCertificateManager($userId = '') {
1388
+        if ($userId === '') {
1389
+            $userSession = $this->getUserSession();
1390
+            $user = $userSession->getUser();
1391
+            if (is_null($user)) {
1392
+                return null;
1393
+            }
1394
+            $userId = $user->getUID();
1395
+        }
1396
+        return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
1397
+    }
1398
+
1399
+    /**
1400
+     * Returns an instance of the HTTP client service
1401
+     *
1402
+     * @return \OCP\Http\Client\IClientService
1403
+     */
1404
+    public function getHTTPClientService() {
1405
+        return $this->query('HttpClientService');
1406
+    }
1407
+
1408
+    /**
1409
+     * Create a new event source
1410
+     *
1411
+     * @return \OCP\IEventSource
1412
+     */
1413
+    public function createEventSource() {
1414
+        return new \OC_EventSource();
1415
+    }
1416
+
1417
+    /**
1418
+     * Get the active event logger
1419
+     *
1420
+     * The returned logger only logs data when debug mode is enabled
1421
+     *
1422
+     * @return \OCP\Diagnostics\IEventLogger
1423
+     */
1424
+    public function getEventLogger() {
1425
+        return $this->query('EventLogger');
1426
+    }
1427
+
1428
+    /**
1429
+     * Get the active query logger
1430
+     *
1431
+     * The returned logger only logs data when debug mode is enabled
1432
+     *
1433
+     * @return \OCP\Diagnostics\IQueryLogger
1434
+     */
1435
+    public function getQueryLogger() {
1436
+        return $this->query('QueryLogger');
1437
+    }
1438
+
1439
+    /**
1440
+     * Get the manager for temporary files and folders
1441
+     *
1442
+     * @return \OCP\ITempManager
1443
+     */
1444
+    public function getTempManager() {
1445
+        return $this->query('TempManager');
1446
+    }
1447
+
1448
+    /**
1449
+     * Get the app manager
1450
+     *
1451
+     * @return \OCP\App\IAppManager
1452
+     */
1453
+    public function getAppManager() {
1454
+        return $this->query('AppManager');
1455
+    }
1456
+
1457
+    /**
1458
+     * Creates a new mailer
1459
+     *
1460
+     * @return \OCP\Mail\IMailer
1461
+     */
1462
+    public function getMailer() {
1463
+        return $this->query('Mailer');
1464
+    }
1465
+
1466
+    /**
1467
+     * Get the webroot
1468
+     *
1469
+     * @return string
1470
+     */
1471
+    public function getWebRoot() {
1472
+        return $this->webRoot;
1473
+    }
1474
+
1475
+    /**
1476
+     * @return \OC\OCSClient
1477
+     */
1478
+    public function getOcsClient() {
1479
+        return $this->query('OcsClient');
1480
+    }
1481
+
1482
+    /**
1483
+     * @return \OCP\IDateTimeZone
1484
+     */
1485
+    public function getDateTimeZone() {
1486
+        return $this->query('DateTimeZone');
1487
+    }
1488
+
1489
+    /**
1490
+     * @return \OCP\IDateTimeFormatter
1491
+     */
1492
+    public function getDateTimeFormatter() {
1493
+        return $this->query('DateTimeFormatter');
1494
+    }
1495
+
1496
+    /**
1497
+     * @return \OCP\Files\Config\IMountProviderCollection
1498
+     */
1499
+    public function getMountProviderCollection() {
1500
+        return $this->query('MountConfigManager');
1501
+    }
1502
+
1503
+    /**
1504
+     * Get the IniWrapper
1505
+     *
1506
+     * @return IniGetWrapper
1507
+     */
1508
+    public function getIniWrapper() {
1509
+        return $this->query('IniWrapper');
1510
+    }
1511
+
1512
+    /**
1513
+     * @return \OCP\Command\IBus
1514
+     */
1515
+    public function getCommandBus() {
1516
+        return $this->query('AsyncCommandBus');
1517
+    }
1518
+
1519
+    /**
1520
+     * Get the trusted domain helper
1521
+     *
1522
+     * @return TrustedDomainHelper
1523
+     */
1524
+    public function getTrustedDomainHelper() {
1525
+        return $this->query('TrustedDomainHelper');
1526
+    }
1527
+
1528
+    /**
1529
+     * Get the locking provider
1530
+     *
1531
+     * @return \OCP\Lock\ILockingProvider
1532
+     * @since 8.1.0
1533
+     */
1534
+    public function getLockingProvider() {
1535
+        return $this->query('LockingProvider');
1536
+    }
1537
+
1538
+    /**
1539
+     * @return \OCP\Files\Mount\IMountManager
1540
+     **/
1541
+    function getMountManager() {
1542
+        return $this->query('MountManager');
1543
+    }
1544
+
1545
+    /** @return \OCP\Files\Config\IUserMountCache */
1546
+    function getUserMountCache() {
1547
+        return $this->query('UserMountCache');
1548
+    }
1549
+
1550
+    /**
1551
+     * Get the MimeTypeDetector
1552
+     *
1553
+     * @return \OCP\Files\IMimeTypeDetector
1554
+     */
1555
+    public function getMimeTypeDetector() {
1556
+        return $this->query('MimeTypeDetector');
1557
+    }
1558
+
1559
+    /**
1560
+     * Get the MimeTypeLoader
1561
+     *
1562
+     * @return \OCP\Files\IMimeTypeLoader
1563
+     */
1564
+    public function getMimeTypeLoader() {
1565
+        return $this->query('MimeTypeLoader');
1566
+    }
1567
+
1568
+    /**
1569
+     * Get the manager of all the capabilities
1570
+     *
1571
+     * @return \OC\CapabilitiesManager
1572
+     */
1573
+    public function getCapabilitiesManager() {
1574
+        return $this->query('CapabilitiesManager');
1575
+    }
1576
+
1577
+    /**
1578
+     * Get the EventDispatcher
1579
+     *
1580
+     * @return EventDispatcherInterface
1581
+     * @since 8.2.0
1582
+     */
1583
+    public function getEventDispatcher() {
1584
+        return $this->query('EventDispatcher');
1585
+    }
1586
+
1587
+    /**
1588
+     * Get the Notification Manager
1589
+     *
1590
+     * @return \OCP\Notification\IManager
1591
+     * @since 8.2.0
1592
+     */
1593
+    public function getNotificationManager() {
1594
+        return $this->query('NotificationManager');
1595
+    }
1596
+
1597
+    /**
1598
+     * @return \OCP\Comments\ICommentsManager
1599
+     */
1600
+    public function getCommentsManager() {
1601
+        return $this->query('CommentsManager');
1602
+    }
1603
+
1604
+    /**
1605
+     * @return \OCA\Theming\ThemingDefaults
1606
+     */
1607
+    public function getThemingDefaults() {
1608
+        return $this->query('ThemingDefaults');
1609
+    }
1610
+
1611
+    /**
1612
+     * @return \OC\IntegrityCheck\Checker
1613
+     */
1614
+    public function getIntegrityCodeChecker() {
1615
+        return $this->query('IntegrityCodeChecker');
1616
+    }
1617
+
1618
+    /**
1619
+     * @return \OC\Session\CryptoWrapper
1620
+     */
1621
+    public function getSessionCryptoWrapper() {
1622
+        return $this->query('CryptoWrapper');
1623
+    }
1624
+
1625
+    /**
1626
+     * @return CsrfTokenManager
1627
+     */
1628
+    public function getCsrfTokenManager() {
1629
+        return $this->query('CsrfTokenManager');
1630
+    }
1631
+
1632
+    /**
1633
+     * @return Throttler
1634
+     */
1635
+    public function getBruteForceThrottler() {
1636
+        return $this->query('Throttler');
1637
+    }
1638
+
1639
+    /**
1640
+     * @return IContentSecurityPolicyManager
1641
+     */
1642
+    public function getContentSecurityPolicyManager() {
1643
+        return $this->query('ContentSecurityPolicyManager');
1644
+    }
1645
+
1646
+    /**
1647
+     * @return ContentSecurityPolicyNonceManager
1648
+     */
1649
+    public function getContentSecurityPolicyNonceManager() {
1650
+        return $this->query('ContentSecurityPolicyNonceManager');
1651
+    }
1652
+
1653
+    /**
1654
+     * Not a public API as of 8.2, wait for 9.0
1655
+     *
1656
+     * @return \OCA\Files_External\Service\BackendService
1657
+     */
1658
+    public function getStoragesBackendService() {
1659
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1660
+    }
1661
+
1662
+    /**
1663
+     * Not a public API as of 8.2, wait for 9.0
1664
+     *
1665
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1666
+     */
1667
+    public function getGlobalStoragesService() {
1668
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1669
+    }
1670
+
1671
+    /**
1672
+     * Not a public API as of 8.2, wait for 9.0
1673
+     *
1674
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1675
+     */
1676
+    public function getUserGlobalStoragesService() {
1677
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1678
+    }
1679
+
1680
+    /**
1681
+     * Not a public API as of 8.2, wait for 9.0
1682
+     *
1683
+     * @return \OCA\Files_External\Service\UserStoragesService
1684
+     */
1685
+    public function getUserStoragesService() {
1686
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1687
+    }
1688
+
1689
+    /**
1690
+     * @return \OCP\Share\IManager
1691
+     */
1692
+    public function getShareManager() {
1693
+        return $this->query('ShareManager');
1694
+    }
1695
+
1696
+    /**
1697
+     * Returns the LDAP Provider
1698
+     *
1699
+     * @return \OCP\LDAP\ILDAPProvider
1700
+     */
1701
+    public function getLDAPProvider() {
1702
+        return $this->query('LDAPProvider');
1703
+    }
1704
+
1705
+    /**
1706
+     * @return \OCP\Settings\IManager
1707
+     */
1708
+    public function getSettingsManager() {
1709
+        return $this->query('SettingsManager');
1710
+    }
1711
+
1712
+    /**
1713
+     * @return \OCP\Files\IAppData
1714
+     */
1715
+    public function getAppDataDir($app) {
1716
+        /** @var \OC\Files\AppData\Factory $factory */
1717
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
1718
+        return $factory->get($app);
1719
+    }
1720
+
1721
+    /**
1722
+     * @return \OCP\Lockdown\ILockdownManager
1723
+     */
1724
+    public function getLockdownManager() {
1725
+        return $this->query('LockdownManager');
1726
+    }
1727
+
1728
+    /**
1729
+     * @return \OCP\Federation\ICloudIdManager
1730
+     */
1731
+    public function getCloudIdManager() {
1732
+        return $this->query(ICloudIdManager::class);
1733
+    }
1734 1734
 }
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
132 132
 		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
133 133
 
134
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
134
+		$this->registerService(\OCP\IPreview::class, function(Server $c) {
135 135
 			return new PreviewManager(
136 136
 				$c->getConfig(),
137 137
 				$c->getRootFolder(),
@@ -142,13 +142,13 @@  discard block
 block discarded – undo
142 142
 		});
143 143
 		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
144 144
 
145
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
145
+		$this->registerService(\OC\Preview\Watcher::class, function(Server $c) {
146 146
 			return new \OC\Preview\Watcher(
147 147
 				$c->getAppDataDir('preview')
148 148
 			);
149 149
 		});
150 150
 
151
-		$this->registerService('EncryptionManager', function (Server $c) {
151
+		$this->registerService('EncryptionManager', function(Server $c) {
152 152
 			$view = new View();
153 153
 			$util = new Encryption\Util(
154 154
 				$view,
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 			);
167 167
 		});
168 168
 
169
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
169
+		$this->registerService('EncryptionFileHelper', function(Server $c) {
170 170
 			$util = new Encryption\Util(
171 171
 				new View(),
172 172
 				$c->getUserManager(),
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 			return new Encryption\File($util);
177 177
 		});
178 178
 
179
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
179
+		$this->registerService('EncryptionKeyStorage', function(Server $c) {
180 180
 			$view = new View();
181 181
 			$util = new Encryption\Util(
182 182
 				$view,
@@ -187,32 +187,32 @@  discard block
 block discarded – undo
187 187
 
188 188
 			return new Encryption\Keys\Storage($view, $util);
189 189
 		});
190
-		$this->registerService('TagMapper', function (Server $c) {
190
+		$this->registerService('TagMapper', function(Server $c) {
191 191
 			return new TagMapper($c->getDatabaseConnection());
192 192
 		});
193 193
 
194
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
194
+		$this->registerService(\OCP\ITagManager::class, function(Server $c) {
195 195
 			$tagMapper = $c->query('TagMapper');
196 196
 			return new TagManager($tagMapper, $c->getUserSession());
197 197
 		});
198 198
 		$this->registerAlias('TagManager', \OCP\ITagManager::class);
199 199
 
200
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
200
+		$this->registerService('SystemTagManagerFactory', function(Server $c) {
201 201
 			$config = $c->getConfig();
202 202
 			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
203 203
 			/** @var \OC\SystemTag\ManagerFactory $factory */
204 204
 			$factory = new $factoryClass($this);
205 205
 			return $factory;
206 206
 		});
207
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
207
+		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) {
208 208
 			return $c->query('SystemTagManagerFactory')->getManager();
209 209
 		});
210 210
 		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
211 211
 
212
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
212
+		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) {
213 213
 			return $c->query('SystemTagManagerFactory')->getObjectMapper();
214 214
 		});
215
-		$this->registerService('RootFolder', function (Server $c) {
215
+		$this->registerService('RootFolder', function(Server $c) {
216 216
 			$manager = \OC\Files\Filesystem::getMountManager(null);
217 217
 			$view = new View();
218 218
 			$root = new Root(
@@ -240,30 +240,30 @@  discard block
 block discarded – undo
240 240
 		});
241 241
 		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
242 242
 
243
-		$this->registerService(\OCP\IUserManager::class, function (Server $c) {
243
+		$this->registerService(\OCP\IUserManager::class, function(Server $c) {
244 244
 			$config = $c->getConfig();
245 245
 			return new \OC\User\Manager($config);
246 246
 		});
247 247
 		$this->registerAlias('UserManager', \OCP\IUserManager::class);
248 248
 
249
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
249
+		$this->registerService(\OCP\IGroupManager::class, function(Server $c) {
250 250
 			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
251
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
251
+			$groupManager->listen('\OC\Group', 'preCreate', function($gid) {
252 252
 				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
253 253
 			});
254
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
254
+			$groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) {
255 255
 				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
256 256
 			});
257
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
257
+			$groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) {
258 258
 				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
259 259
 			});
260
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
260
+			$groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) {
261 261
 				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
262 262
 			});
263
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
263
+			$groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
264 264
 				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
265 265
 			});
266
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
266
+			$groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
267 267
 				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
268 268
 				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
269 269
 				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
@@ -283,11 +283,11 @@  discard block
 block discarded – undo
283 283
 			return new Store($session, $logger, $tokenProvider);
284 284
 		});
285 285
 		$this->registerAlias(IStore::class, Store::class);
286
-		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
286
+		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function(Server $c) {
287 287
 			$dbConnection = $c->getDatabaseConnection();
288 288
 			return new Authentication\Token\DefaultTokenMapper($dbConnection);
289 289
 		});
290
-		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
290
+		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function(Server $c) {
291 291
 			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
292 292
 			$crypto = $c->getCrypto();
293 293
 			$config = $c->getConfig();
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 		});
298 298
 		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
299 299
 
300
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
300
+		$this->registerService(\OCP\IUserSession::class, function(Server $c) {
301 301
 			$manager = $c->getUserManager();
302 302
 			$session = new \OC\Session\Memory('');
303 303
 			$timeFactory = new TimeFactory();
@@ -310,40 +310,40 @@  discard block
 block discarded – undo
310 310
 			}
311 311
 
312 312
 			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
313
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
313
+			$userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) {
314 314
 				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
315 315
 			});
316
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
316
+			$userSession->listen('\OC\User', 'postCreateUser', function($user, $password) {
317 317
 				/** @var $user \OC\User\User */
318 318
 				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
319 319
 			});
320
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
320
+			$userSession->listen('\OC\User', 'preDelete', function($user) {
321 321
 				/** @var $user \OC\User\User */
322 322
 				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
323 323
 			});
324
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
324
+			$userSession->listen('\OC\User', 'postDelete', function($user) {
325 325
 				/** @var $user \OC\User\User */
326 326
 				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
327 327
 			});
328
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
328
+			$userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) {
329 329
 				/** @var $user \OC\User\User */
330 330
 				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
331 331
 			});
332
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
332
+			$userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) {
333 333
 				/** @var $user \OC\User\User */
334 334
 				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
335 335
 			});
336
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
336
+			$userSession->listen('\OC\User', 'preLogin', function($uid, $password) {
337 337
 				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
338 338
 			});
339
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
339
+			$userSession->listen('\OC\User', 'postLogin', function($user, $password) {
340 340
 				/** @var $user \OC\User\User */
341 341
 				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
342 342
 			});
343
-			$userSession->listen('\OC\User', 'logout', function () {
343
+			$userSession->listen('\OC\User', 'logout', function() {
344 344
 				\OC_Hook::emit('OC_User', 'logout', array());
345 345
 			});
346
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
346
+			$userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value) {
347 347
 				/** @var $user \OC\User\User */
348 348
 				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));
349 349
 			});
@@ -351,14 +351,14 @@  discard block
 block discarded – undo
351 351
 		});
352 352
 		$this->registerAlias('UserSession', \OCP\IUserSession::class);
353 353
 
354
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
354
+		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) {
355 355
 			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
356 356
 		});
357 357
 
358 358
 		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
359 359
 		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
360 360
 
361
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
361
+		$this->registerService(\OC\AllConfig::class, function(Server $c) {
362 362
 			return new \OC\AllConfig(
363 363
 				$c->getSystemConfig()
364 364
 			);
@@ -366,17 +366,17 @@  discard block
 block discarded – undo
366 366
 		$this->registerAlias('AllConfig', \OC\AllConfig::class);
367 367
 		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
368 368
 
369
-		$this->registerService('SystemConfig', function ($c) use ($config) {
369
+		$this->registerService('SystemConfig', function($c) use ($config) {
370 370
 			return new \OC\SystemConfig($config);
371 371
 		});
372 372
 
373
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
373
+		$this->registerService(\OC\AppConfig::class, function(Server $c) {
374 374
 			return new \OC\AppConfig($c->getDatabaseConnection());
375 375
 		});
376 376
 		$this->registerAlias('AppConfig', \OC\AppConfig::class);
377 377
 		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
378 378
 
379
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
379
+		$this->registerService(\OCP\L10N\IFactory::class, function(Server $c) {
380 380
 			return new \OC\L10N\Factory(
381 381
 				$c->getConfig(),
382 382
 				$c->getRequest(),
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 		});
387 387
 		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
388 388
 
389
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
389
+		$this->registerService(\OCP\IURLGenerator::class, function(Server $c) {
390 390
 			$config = $c->getConfig();
391 391
 			$cacheFactory = $c->getMemCacheFactory();
392 392
 			return new \OC\URLGenerator(
@@ -396,10 +396,10 @@  discard block
 block discarded – undo
396 396
 		});
397 397
 		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
398 398
 
399
-		$this->registerService('AppHelper', function ($c) {
399
+		$this->registerService('AppHelper', function($c) {
400 400
 			return new \OC\AppHelper();
401 401
 		});
402
-		$this->registerService('AppFetcher', function ($c) {
402
+		$this->registerService('AppFetcher', function($c) {
403 403
 			return new AppFetcher(
404 404
 				$this->getAppDataDir('appstore'),
405 405
 				$this->getHTTPClientService(),
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 				$this->getConfig()
408 408
 			);
409 409
 		});
410
-		$this->registerService('CategoryFetcher', function ($c) {
410
+		$this->registerService('CategoryFetcher', function($c) {
411 411
 			return new CategoryFetcher(
412 412
 				$this->getAppDataDir('appstore'),
413 413
 				$this->getHTTPClientService(),
@@ -416,21 +416,21 @@  discard block
 block discarded – undo
416 416
 			);
417 417
 		});
418 418
 
419
-		$this->registerService(\OCP\ICache::class, function ($c) {
419
+		$this->registerService(\OCP\ICache::class, function($c) {
420 420
 			return new Cache\File();
421 421
 		});
422 422
 		$this->registerAlias('UserCache', \OCP\ICache::class);
423 423
 
424
-		$this->registerService(Factory::class, function (Server $c) {
424
+		$this->registerService(Factory::class, function(Server $c) {
425 425
 			$config = $c->getConfig();
426 426
 
427 427
 			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
428 428
 				$v = \OC_App::getAppVersions();
429
-				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
429
+				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT.'/version.php'));
430 430
 				$version = implode(',', $v);
431 431
 				$instanceId = \OC_Util::getInstanceId();
432 432
 				$path = \OC::$SERVERROOT;
433
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
433
+				$prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.\OC::$WEBROOT);
434 434
 				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
435 435
 					$config->getSystemValue('memcache.local', null),
436 436
 					$config->getSystemValue('memcache.distributed', null),
@@ -447,12 +447,12 @@  discard block
 block discarded – undo
447 447
 		$this->registerAlias('MemCacheFactory', Factory::class);
448 448
 		$this->registerAlias(ICacheFactory::class, Factory::class);
449 449
 
450
-		$this->registerService('RedisFactory', function (Server $c) {
450
+		$this->registerService('RedisFactory', function(Server $c) {
451 451
 			$systemConfig = $c->getSystemConfig();
452 452
 			return new RedisFactory($systemConfig);
453 453
 		});
454 454
 
455
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
455
+		$this->registerService(\OCP\Activity\IManager::class, function(Server $c) {
456 456
 			return new \OC\Activity\Manager(
457 457
 				$c->getRequest(),
458 458
 				$c->getUserSession(),
@@ -462,14 +462,14 @@  discard block
 block discarded – undo
462 462
 		});
463 463
 		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
464 464
 
465
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
465
+		$this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) {
466 466
 			return new \OC\Activity\EventMerger(
467 467
 				$c->getL10N('lib')
468 468
 			);
469 469
 		});
470 470
 		$this->registerAlias(IValidator::class, Validator::class);
471 471
 
472
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
472
+		$this->registerService(\OCP\IAvatarManager::class, function(Server $c) {
473 473
 			return new AvatarManager(
474 474
 				$c->getUserManager(),
475 475
 				$c->getAppDataDir('avatar'),
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 		});
481 481
 		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
482 482
 
483
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
483
+		$this->registerService(\OCP\ILogger::class, function(Server $c) {
484 484
 			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
485 485
 			$logger = Log::getLogClass($logType);
486 486
 			call_user_func(array($logger, 'init'));
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 		});
490 490
 		$this->registerAlias('Logger', \OCP\ILogger::class);
491 491
 
492
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
492
+		$this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) {
493 493
 			$config = $c->getConfig();
494 494
 			return new \OC\BackgroundJob\JobList(
495 495
 				$c->getDatabaseConnection(),
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 		});
500 500
 		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
501 501
 
502
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
502
+		$this->registerService(\OCP\Route\IRouter::class, function(Server $c) {
503 503
 			$cacheFactory = $c->getMemCacheFactory();
504 504
 			$logger = $c->getLogger();
505 505
 			if ($cacheFactory->isAvailable()) {
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 		});
512 512
 		$this->registerAlias('Router', \OCP\Route\IRouter::class);
513 513
 
514
-		$this->registerService(\OCP\ISearch::class, function ($c) {
514
+		$this->registerService(\OCP\ISearch::class, function($c) {
515 515
 			return new Search();
516 516
 		});
517 517
 		$this->registerAlias('Search', \OCP\ISearch::class);
@@ -531,27 +531,27 @@  discard block
 block discarded – undo
531 531
 			);
532 532
 		});
533 533
 
534
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
534
+		$this->registerService(\OCP\Security\ISecureRandom::class, function($c) {
535 535
 			return new SecureRandom();
536 536
 		});
537 537
 		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
538 538
 
539
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
539
+		$this->registerService(\OCP\Security\ICrypto::class, function(Server $c) {
540 540
 			return new Crypto($c->getConfig(), $c->getSecureRandom());
541 541
 		});
542 542
 		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
543 543
 
544
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
544
+		$this->registerService(\OCP\Security\IHasher::class, function(Server $c) {
545 545
 			return new Hasher($c->getConfig());
546 546
 		});
547 547
 		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
548 548
 
549
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
549
+		$this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) {
550 550
 			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
551 551
 		});
552 552
 		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
553 553
 
554
-		$this->registerService(IDBConnection::class, function (Server $c) {
554
+		$this->registerService(IDBConnection::class, function(Server $c) {
555 555
 			$systemConfig = $c->getSystemConfig();
556 556
 			$factory = new \OC\DB\ConnectionFactory($systemConfig);
557 557
 			$type = $systemConfig->getValue('dbtype', 'sqlite');
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 		});
566 566
 		$this->registerAlias('DatabaseConnection', IDBConnection::class);
567 567
 
568
-		$this->registerService('HTTPHelper', function (Server $c) {
568
+		$this->registerService('HTTPHelper', function(Server $c) {
569 569
 			$config = $c->getConfig();
570 570
 			return new HTTPHelper(
571 571
 				$config,
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
 			);
574 574
 		});
575 575
 
576
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
576
+		$this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) {
577 577
 			$user = \OC_User::getUser();
578 578
 			$uid = $user ? $user : null;
579 579
 			return new ClientService(
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
 		});
584 584
 		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
585 585
 
586
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
586
+		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) {
587 587
 			if ($c->getSystemConfig()->getValue('debug', false)) {
588 588
 				return new EventLogger();
589 589
 			} else {
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 		});
593 593
 		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
594 594
 
595
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
595
+		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) {
596 596
 			if ($c->getSystemConfig()->getValue('debug', false)) {
597 597
 				return new QueryLogger();
598 598
 			} else {
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
 		});
602 602
 		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
603 603
 
604
-		$this->registerService(TempManager::class, function (Server $c) {
604
+		$this->registerService(TempManager::class, function(Server $c) {
605 605
 			return new TempManager(
606 606
 				$c->getLogger(),
607 607
 				$c->getConfig()
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 		$this->registerAlias('TempManager', TempManager::class);
611 611
 		$this->registerAlias(ITempManager::class, TempManager::class);
612 612
 
613
-		$this->registerService(AppManager::class, function (Server $c) {
613
+		$this->registerService(AppManager::class, function(Server $c) {
614 614
 			return new \OC\App\AppManager(
615 615
 				$c->getUserSession(),
616 616
 				$c->getAppConfig(),
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
 		$this->registerAlias('AppManager', AppManager::class);
623 623
 		$this->registerAlias(IAppManager::class, AppManager::class);
624 624
 
625
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
625
+		$this->registerService(\OCP\IDateTimeZone::class, function(Server $c) {
626 626
 			return new DateTimeZone(
627 627
 				$c->getConfig(),
628 628
 				$c->getSession()
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 		});
631 631
 		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
632 632
 
633
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
633
+		$this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) {
634 634
 			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
635 635
 
636 636
 			return new DateTimeFormatter(
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 		});
641 641
 		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
642 642
 
643
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
643
+		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) {
644 644
 			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
645 645
 			$listener = new UserMountCacheListener($mountCache);
646 646
 			$listener->listen($c->getUserManager());
@@ -648,10 +648,10 @@  discard block
 block discarded – undo
648 648
 		});
649 649
 		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
650 650
 
651
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
651
+		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) {
652 652
 			$loader = \OC\Files\Filesystem::getLoader();
653 653
 			$mountCache = $c->query('UserMountCache');
654
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
654
+			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
655 655
 
656 656
 			// builtin providers
657 657
 
@@ -664,14 +664,14 @@  discard block
 block discarded – undo
664 664
 		});
665 665
 		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
666 666
 
667
-		$this->registerService('IniWrapper', function ($c) {
667
+		$this->registerService('IniWrapper', function($c) {
668 668
 			return new IniGetWrapper();
669 669
 		});
670
-		$this->registerService('AsyncCommandBus', function (Server $c) {
670
+		$this->registerService('AsyncCommandBus', function(Server $c) {
671 671
 			$jobList = $c->getJobList();
672 672
 			return new AsyncBus($jobList);
673 673
 		});
674
-		$this->registerService('TrustedDomainHelper', function ($c) {
674
+		$this->registerService('TrustedDomainHelper', function($c) {
675 675
 			return new TrustedDomainHelper($this->getConfig());
676 676
 		});
677 677
 		$this->registerService('Throttler', function(Server $c) {
@@ -682,10 +682,10 @@  discard block
 block discarded – undo
682 682
 				$c->getConfig()
683 683
 			);
684 684
 		});
685
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
685
+		$this->registerService('IntegrityCodeChecker', function(Server $c) {
686 686
 			// IConfig and IAppManager requires a working database. This code
687 687
 			// might however be called when ownCloud is not yet setup.
688
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
688
+			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
689 689
 				$config = $c->getConfig();
690 690
 				$appManager = $c->getAppManager();
691 691
 			} else {
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 					$c->getTempManager()
704 704
 			);
705 705
 		});
706
-		$this->registerService(\OCP\IRequest::class, function ($c) {
706
+		$this->registerService(\OCP\IRequest::class, function($c) {
707 707
 			if (isset($this['urlParams'])) {
708 708
 				$urlParams = $this['urlParams'];
709 709
 			} else {
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
 		});
740 740
 		$this->registerAlias('Request', \OCP\IRequest::class);
741 741
 
742
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
742
+		$this->registerService(\OCP\Mail\IMailer::class, function(Server $c) {
743 743
 			return new Mailer(
744 744
 				$c->getConfig(),
745 745
 				$c->getLogger(),
@@ -753,14 +753,14 @@  discard block
 block discarded – undo
753 753
 		$this->registerService('LDAPProvider', function(Server $c) {
754 754
 			$config = $c->getConfig();
755 755
 			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
756
-			if(is_null($factoryClass)) {
756
+			if (is_null($factoryClass)) {
757 757
 				throw new \Exception('ldapProviderFactory not set');
758 758
 			}
759 759
 			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
760 760
 			$factory = new $factoryClass($this);
761 761
 			return $factory->getLDAPProvider();
762 762
 		});
763
-		$this->registerService('LockingProvider', function (Server $c) {
763
+		$this->registerService('LockingProvider', function(Server $c) {
764 764
 			$ini = $c->getIniWrapper();
765 765
 			$config = $c->getConfig();
766 766
 			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
@@ -776,37 +776,37 @@  discard block
 block discarded – undo
776 776
 			return new NoopLockingProvider();
777 777
 		});
778 778
 
779
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
779
+		$this->registerService(\OCP\Files\Mount\IMountManager::class, function() {
780 780
 			return new \OC\Files\Mount\Manager();
781 781
 		});
782 782
 		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
783 783
 
784
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
784
+		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) {
785 785
 			return new \OC\Files\Type\Detection(
786 786
 				$c->getURLGenerator(),
787 787
 				\OC::$configDir,
788
-				\OC::$SERVERROOT . '/resources/config/'
788
+				\OC::$SERVERROOT.'/resources/config/'
789 789
 			);
790 790
 		});
791 791
 		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
792 792
 
793
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
793
+		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) {
794 794
 			return new \OC\Files\Type\Loader(
795 795
 				$c->getDatabaseConnection()
796 796
 			);
797 797
 		});
798 798
 		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
799 799
 
800
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
800
+		$this->registerService(\OCP\Notification\IManager::class, function(Server $c) {
801 801
 			return new Manager(
802 802
 				$c->query(IValidator::class)
803 803
 			);
804 804
 		});
805 805
 		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
806 806
 
807
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
807
+		$this->registerService(\OC\CapabilitiesManager::class, function(Server $c) {
808 808
 			$manager = new \OC\CapabilitiesManager($c->getLogger());
809
-			$manager->registerCapability(function () use ($c) {
809
+			$manager->registerCapability(function() use ($c) {
810 810
 				return new \OC\OCS\CoreCapabilities($c->getConfig());
811 811
 			});
812 812
 			return $manager;
@@ -848,13 +848,13 @@  discard block
 block discarded – undo
848 848
 			}
849 849
 			return new \OC_Defaults();
850 850
 		});
851
-		$this->registerService(EventDispatcher::class, function () {
851
+		$this->registerService(EventDispatcher::class, function() {
852 852
 			return new EventDispatcher();
853 853
 		});
854 854
 		$this->registerAlias('EventDispatcher', EventDispatcher::class);
855 855
 		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
856 856
 
857
-		$this->registerService('CryptoWrapper', function (Server $c) {
857
+		$this->registerService('CryptoWrapper', function(Server $c) {
858 858
 			// FIXME: Instantiiated here due to cyclic dependency
859 859
 			$request = new Request(
860 860
 				[
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
 				$request
880 880
 			);
881 881
 		});
882
-		$this->registerService('CsrfTokenManager', function (Server $c) {
882
+		$this->registerService('CsrfTokenManager', function(Server $c) {
883 883
 			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
884 884
 
885 885
 			return new CsrfTokenManager(
@@ -887,10 +887,10 @@  discard block
 block discarded – undo
887 887
 				$c->query(SessionStorage::class)
888 888
 			);
889 889
 		});
890
-		$this->registerService(SessionStorage::class, function (Server $c) {
890
+		$this->registerService(SessionStorage::class, function(Server $c) {
891 891
 			return new SessionStorage($c->getSession());
892 892
 		});
893
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
893
+		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) {
894 894
 			return new ContentSecurityPolicyManager();
895 895
 		});
896 896
 		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
@@ -941,29 +941,29 @@  discard block
 block discarded – undo
941 941
 			);
942 942
 			return $manager;
943 943
 		});
944
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
944
+		$this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) {
945 945
 			return new \OC\Files\AppData\Factory(
946 946
 				$c->getRootFolder(),
947 947
 				$c->getSystemConfig()
948 948
 			);
949 949
 		});
950 950
 
951
-		$this->registerService('LockdownManager', function (Server $c) {
951
+		$this->registerService('LockdownManager', function(Server $c) {
952 952
 			return new LockdownManager(function() use ($c) {
953 953
 				return $c->getSession();
954 954
 			});
955 955
 		});
956 956
 
957
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
957
+		$this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) {
958 958
 			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
959 959
 		});
960 960
 
961
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
961
+		$this->registerService(ICloudIdManager::class, function(Server $c) {
962 962
 			return new CloudIdManager();
963 963
 		});
964 964
 
965 965
 		/* To trick DI since we don't extend the DIContainer here */
966
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
966
+		$this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) {
967 967
 			return new CleanPreviewsBackgroundJob(
968 968
 				$c->getRootFolder(),
969 969
 				$c->getLogger(),
@@ -978,7 +978,7 @@  discard block
 block discarded – undo
978 978
 		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
979 979
 		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
980 980
 
981
-		$this->registerService(Defaults::class, function (Server $c) {
981
+		$this->registerService(Defaults::class, function(Server $c) {
982 982
 			return new Defaults(
983 983
 				$c->getThemingDefaults()
984 984
 			);
@@ -1124,7 +1124,7 @@  discard block
 block discarded – undo
1124 1124
 	 * @deprecated since 9.2.0 use IAppData
1125 1125
 	 */
1126 1126
 	public function getAppFolder() {
1127
-		$dir = '/' . \OC_App::getCurrentApp();
1127
+		$dir = '/'.\OC_App::getCurrentApp();
1128 1128
 		$root = $this->getRootFolder();
1129 1129
 		if (!$root->nodeExists($dir)) {
1130 1130
 			$folder = $root->newFolder($dir);
Please login to merge, or discard this patch.