Completed
Pull Request — master (#5888)
by Maxence
16:07
created
settings/Controller/CertificateController.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @NoAdminRequired
74 74
 	 * @NoSubadminRequired
75
-	 * @return array
75
+	 * @return DataResponse
76 76
 	 */
77 77
 	public function addPersonalRootCertificate() {
78 78
 		return $this->addCertificate($this->userCertificateManager);
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	/**
161 161
 	 * Add a new personal root certificate to the system's trust store
162 162
 	 *
163
-	 * @return array
163
+	 * @return DataResponse
164 164
 	 */
165 165
 	public function addSystemRootCertificate() {
166 166
 		return $this->addCertificate($this->systemCertificateManager);
Please login to merge, or discard this patch.
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -37,144 +37,144 @@
 block discarded – undo
37 37
  * @package OC\Settings\Controller
38 38
  */
39 39
 class CertificateController extends Controller {
40
-	/** @var ICertificateManager */
41
-	private $userCertificateManager;
42
-	/** @var ICertificateManager  */
43
-	private $systemCertificateManager;
44
-	/** @var IL10N */
45
-	private $l10n;
46
-	/** @var IAppManager */
47
-	private $appManager;
48
-
49
-	/**
50
-	 * @param string $appName
51
-	 * @param IRequest $request
52
-	 * @param ICertificateManager $userCertificateManager
53
-	 * @param ICertificateManager $systemCertificateManager
54
-	 * @param IL10N $l10n
55
-	 * @param IAppManager $appManager
56
-	 */
57
-	public function __construct($appName,
58
-								IRequest $request,
59
-								ICertificateManager $userCertificateManager,
60
-								ICertificateManager $systemCertificateManager,
61
-								IL10N $l10n,
62
-								IAppManager $appManager) {
63
-		parent::__construct($appName, $request);
64
-		$this->userCertificateManager = $userCertificateManager;
65
-		$this->systemCertificateManager = $systemCertificateManager;
66
-		$this->l10n = $l10n;
67
-		$this->appManager = $appManager;
68
-	}
69
-
70
-	/**
71
-	 * Add a new personal root certificate to the users' trust store
72
-	 *
73
-	 * @NoAdminRequired
74
-	 * @NoSubadminRequired
75
-	 * @return array
76
-	 */
77
-	public function addPersonalRootCertificate() {
78
-		return $this->addCertificate($this->userCertificateManager);
79
-	}
80
-
81
-	/**
82
-	 * Add a new root certificate to a trust store
83
-	 *
84
-	 * @param ICertificateManager $certificateManager
85
-	 * @return DataResponse
86
-	 */
87
-	private function addCertificate(ICertificateManager $certificateManager) {
88
-		$headers = [];
89
-
90
-		if ($this->isCertificateImportAllowed() === false) {
91
-			return new DataResponse(['message' => 'Individual certificate management disabled'], Http::STATUS_FORBIDDEN, $headers);
92
-		}
93
-
94
-		$file = $this->request->getUploadedFile('rootcert_import');
95
-		if (empty($file)) {
96
-			return new DataResponse(['message' => 'No file uploaded'], Http::STATUS_UNPROCESSABLE_ENTITY, $headers);
97
-		}
98
-
99
-		try {
100
-			$certificate = $certificateManager->addCertificate(file_get_contents($file['tmp_name']), $file['name']);
101
-			return new DataResponse(
102
-				[
103
-					'name' => $certificate->getName(),
104
-					'commonName' => $certificate->getCommonName(),
105
-					'organization' => $certificate->getOrganization(),
106
-					'validFrom' => $certificate->getIssueDate()->getTimestamp(),
107
-					'validTill' => $certificate->getExpireDate()->getTimestamp(),
108
-					'validFromString' => $this->l10n->l('date', $certificate->getIssueDate()),
109
-					'validTillString' => $this->l10n->l('date', $certificate->getExpireDate()),
110
-					'issuer' => $certificate->getIssuerName(),
111
-					'issuerOrganization' => $certificate->getIssuerOrganization(),
112
-				],
113
-				Http::STATUS_OK,
114
-				$headers
115
-			);
116
-		} catch (\Exception $e) {
117
-			return new DataResponse('An error occurred.', Http::STATUS_UNPROCESSABLE_ENTITY, $headers);
118
-		}
119
-	}
120
-
121
-	/**
122
-	 * Removes a personal root certificate from the users' trust store
123
-	 *
124
-	 * @NoAdminRequired
125
-	 * @NoSubadminRequired
126
-	 * @param string $certificateIdentifier
127
-	 * @return DataResponse
128
-	 */
129
-	public function removePersonalRootCertificate($certificateIdentifier) {
130
-
131
-		if ($this->isCertificateImportAllowed() === false) {
132
-			return new DataResponse('Individual certificate management disabled', Http::STATUS_FORBIDDEN);
133
-		}
134
-
135
-		$this->userCertificateManager->removeCertificate($certificateIdentifier);
136
-		return new DataResponse();
137
-	}
138
-
139
-	/**
140
-	 * check if certificate import is allowed
141
-	 *
142
-	 * @return bool
143
-	 */
144
-	protected function isCertificateImportAllowed() {
145
-		$externalStorageEnabled = $this->appManager->isEnabledForUser('files_external');
146
-		if ($externalStorageEnabled) {
147
-			/** @var \OCA\Files_External\Service\BackendService $backendService */
148
-			$backendService = \OC_Mount_Config::$app->getContainer()->query('\OCA\Files_External\Service\BackendService');
149
-			if ($backendService->isUserMountingAllowed()) {
150
-				return true;
151
-			}
152
-		}
153
-		return false;
154
-	}
155
-
156
-	/**
157
-	 * Add a new personal root certificate to the system's trust store
158
-	 *
159
-	 * @return array
160
-	 */
161
-	public function addSystemRootCertificate() {
162
-		return $this->addCertificate($this->systemCertificateManager);
163
-	}
164
-
165
-	/**
166
-	 * Removes a personal root certificate from the users' trust store
167
-	 *
168
-	 * @param string $certificateIdentifier
169
-	 * @return DataResponse
170
-	 */
171
-	public function removeSystemRootCertificate($certificateIdentifier) {
172
-
173
-		if ($this->isCertificateImportAllowed() === false) {
174
-			return new DataResponse('Individual certificate management disabled', Http::STATUS_FORBIDDEN);
175
-		}
176
-
177
-		$this->systemCertificateManager->removeCertificate($certificateIdentifier);
178
-		return new DataResponse();
179
-	}
40
+    /** @var ICertificateManager */
41
+    private $userCertificateManager;
42
+    /** @var ICertificateManager  */
43
+    private $systemCertificateManager;
44
+    /** @var IL10N */
45
+    private $l10n;
46
+    /** @var IAppManager */
47
+    private $appManager;
48
+
49
+    /**
50
+     * @param string $appName
51
+     * @param IRequest $request
52
+     * @param ICertificateManager $userCertificateManager
53
+     * @param ICertificateManager $systemCertificateManager
54
+     * @param IL10N $l10n
55
+     * @param IAppManager $appManager
56
+     */
57
+    public function __construct($appName,
58
+                                IRequest $request,
59
+                                ICertificateManager $userCertificateManager,
60
+                                ICertificateManager $systemCertificateManager,
61
+                                IL10N $l10n,
62
+                                IAppManager $appManager) {
63
+        parent::__construct($appName, $request);
64
+        $this->userCertificateManager = $userCertificateManager;
65
+        $this->systemCertificateManager = $systemCertificateManager;
66
+        $this->l10n = $l10n;
67
+        $this->appManager = $appManager;
68
+    }
69
+
70
+    /**
71
+     * Add a new personal root certificate to the users' trust store
72
+     *
73
+     * @NoAdminRequired
74
+     * @NoSubadminRequired
75
+     * @return array
76
+     */
77
+    public function addPersonalRootCertificate() {
78
+        return $this->addCertificate($this->userCertificateManager);
79
+    }
80
+
81
+    /**
82
+     * Add a new root certificate to a trust store
83
+     *
84
+     * @param ICertificateManager $certificateManager
85
+     * @return DataResponse
86
+     */
87
+    private function addCertificate(ICertificateManager $certificateManager) {
88
+        $headers = [];
89
+
90
+        if ($this->isCertificateImportAllowed() === false) {
91
+            return new DataResponse(['message' => 'Individual certificate management disabled'], Http::STATUS_FORBIDDEN, $headers);
92
+        }
93
+
94
+        $file = $this->request->getUploadedFile('rootcert_import');
95
+        if (empty($file)) {
96
+            return new DataResponse(['message' => 'No file uploaded'], Http::STATUS_UNPROCESSABLE_ENTITY, $headers);
97
+        }
98
+
99
+        try {
100
+            $certificate = $certificateManager->addCertificate(file_get_contents($file['tmp_name']), $file['name']);
101
+            return new DataResponse(
102
+                [
103
+                    'name' => $certificate->getName(),
104
+                    'commonName' => $certificate->getCommonName(),
105
+                    'organization' => $certificate->getOrganization(),
106
+                    'validFrom' => $certificate->getIssueDate()->getTimestamp(),
107
+                    'validTill' => $certificate->getExpireDate()->getTimestamp(),
108
+                    'validFromString' => $this->l10n->l('date', $certificate->getIssueDate()),
109
+                    'validTillString' => $this->l10n->l('date', $certificate->getExpireDate()),
110
+                    'issuer' => $certificate->getIssuerName(),
111
+                    'issuerOrganization' => $certificate->getIssuerOrganization(),
112
+                ],
113
+                Http::STATUS_OK,
114
+                $headers
115
+            );
116
+        } catch (\Exception $e) {
117
+            return new DataResponse('An error occurred.', Http::STATUS_UNPROCESSABLE_ENTITY, $headers);
118
+        }
119
+    }
120
+
121
+    /**
122
+     * Removes a personal root certificate from the users' trust store
123
+     *
124
+     * @NoAdminRequired
125
+     * @NoSubadminRequired
126
+     * @param string $certificateIdentifier
127
+     * @return DataResponse
128
+     */
129
+    public function removePersonalRootCertificate($certificateIdentifier) {
130
+
131
+        if ($this->isCertificateImportAllowed() === false) {
132
+            return new DataResponse('Individual certificate management disabled', Http::STATUS_FORBIDDEN);
133
+        }
134
+
135
+        $this->userCertificateManager->removeCertificate($certificateIdentifier);
136
+        return new DataResponse();
137
+    }
138
+
139
+    /**
140
+     * check if certificate import is allowed
141
+     *
142
+     * @return bool
143
+     */
144
+    protected function isCertificateImportAllowed() {
145
+        $externalStorageEnabled = $this->appManager->isEnabledForUser('files_external');
146
+        if ($externalStorageEnabled) {
147
+            /** @var \OCA\Files_External\Service\BackendService $backendService */
148
+            $backendService = \OC_Mount_Config::$app->getContainer()->query('\OCA\Files_External\Service\BackendService');
149
+            if ($backendService->isUserMountingAllowed()) {
150
+                return true;
151
+            }
152
+        }
153
+        return false;
154
+    }
155
+
156
+    /**
157
+     * Add a new personal root certificate to the system's trust store
158
+     *
159
+     * @return array
160
+     */
161
+    public function addSystemRootCertificate() {
162
+        return $this->addCertificate($this->systemCertificateManager);
163
+    }
164
+
165
+    /**
166
+     * Removes a personal root certificate from the users' trust store
167
+     *
168
+     * @param string $certificateIdentifier
169
+     * @return DataResponse
170
+     */
171
+    public function removeSystemRootCertificate($certificateIdentifier) {
172
+
173
+        if ($this->isCertificateImportAllowed() === false) {
174
+            return new DataResponse('Individual certificate management disabled', Http::STATUS_FORBIDDEN);
175
+        }
176
+
177
+        $this->systemCertificateManager->removeCertificate($certificateIdentifier);
178
+        return new DataResponse();
179
+    }
180 180
 }
Please login to merge, or discard this patch.
lib/private/Cache/File.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@
 block discarded – undo
95 95
 	 * @param string $key
96 96
 	 * @param mixed $value
97 97
 	 * @param int $ttl
98
-	 * @return bool|mixed
98
+	 * @return boolean
99 99
 	 * @throws \OC\ForbiddenException
100 100
 	 */
101 101
 	public function set($key, $value, $ttl = 0) {
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 			$rootView = new View();
52 52
 			$user = \OC::$server->getUserSession()->getUser();
53 53
 			Filesystem::initMountPoints($user->getUID());
54
-			if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) {
55
-				$rootView->mkdir('/' . $user->getUID() . '/cache');
54
+			if (!$rootView->file_exists('/'.$user->getUID().'/cache')) {
55
+				$rootView->mkdir('/'.$user->getUID().'/cache');
56 56
 			}
57
-			$this->storage = new View('/' . $user->getUID() . '/cache');
57
+			$this->storage = new View('/'.$user->getUID().'/cache');
58 58
 			return $this->storage;
59 59
 		} else {
60 60
 			\OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', \OCP\Util::ERROR);
@@ -104,12 +104,12 @@  discard block
 block discarded – undo
104 104
 		// unique id to avoid chunk collision, just in case
105 105
 		$uniqueId = \OC::$server->getSecureRandom()->generate(
106 106
 			16,
107
-			ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER
107
+			ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER
108 108
 		);
109 109
 
110 110
 		// use part file to prevent hasKey() to find the key
111 111
 		// while it is being written
112
-		$keyPart = $key . '.' . $uniqueId . '.part';
112
+		$keyPart = $key.'.'.$uniqueId.'.part';
113 113
 		if ($storage and $storage->file_put_contents($keyPart, $value)) {
114 114
 			if ($ttl === 0) {
115 115
 				$ttl = 86400; // 60*60*24
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 			if (is_resource($dh)) {
159 159
 				while (($file = readdir($dh)) !== false) {
160 160
 					if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) {
161
-						$storage->unlink('/' . $file);
161
+						$storage->unlink('/'.$file);
162 162
 					}
163 163
 				}
164 164
 			}
@@ -183,17 +183,17 @@  discard block
 block discarded – undo
183 183
 			while (($file = readdir($dh)) !== false) {
184 184
 				if ($file != '.' and $file != '..') {
185 185
 					try {
186
-						$mtime = $storage->filemtime('/' . $file);
186
+						$mtime = $storage->filemtime('/'.$file);
187 187
 						if ($mtime < $now) {
188
-							$storage->unlink('/' . $file);
188
+							$storage->unlink('/'.$file);
189 189
 						}
190 190
 					} catch (\OCP\Lock\LockedException $e) {
191 191
 						// ignore locked chunks
192
-						\OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core'));
192
+						\OC::$server->getLogger()->debug('Could not cleanup locked chunk "'.$file.'"', array('app' => 'core'));
193 193
 					} catch (\OCP\Files\ForbiddenException $e) {
194
-						\OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core'));
194
+						\OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "'.$file.'"', array('app' => 'core'));
195 195
 					} catch (\OCP\Files\LockNotAcquiredException $e) {
196
-						\OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core'));
196
+						\OC::$server->getLogger()->debug('Could not cleanup locked chunk "'.$file.'"', array('app' => 'core'));
197 197
 					}
198 198
 				}
199 199
 			}
Please login to merge, or discard this patch.
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -33,170 +33,170 @@
 block discarded – undo
33 33
 
34 34
 class File implements ICache {
35 35
 
36
-	/** @var View */
37
-	protected $storage;
36
+    /** @var View */
37
+    protected $storage;
38 38
 
39
-	/**
40
-	 * Returns the cache storage for the logged in user
41
-	 *
42
-	 * @return \OC\Files\View cache storage
43
-	 * @throws \OC\ForbiddenException
44
-	 * @throws \OC\User\NoUserException
45
-	 */
46
-	protected function getStorage() {
47
-		if (isset($this->storage)) {
48
-			return $this->storage;
49
-		}
50
-		if (\OC::$server->getUserSession()->isLoggedIn()) {
51
-			$rootView = new View();
52
-			$user = \OC::$server->getUserSession()->getUser();
53
-			Filesystem::initMountPoints($user->getUID());
54
-			if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) {
55
-				$rootView->mkdir('/' . $user->getUID() . '/cache');
56
-			}
57
-			$this->storage = new View('/' . $user->getUID() . '/cache');
58
-			return $this->storage;
59
-		} else {
60
-			\OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', \OCP\Util::ERROR);
61
-			throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in');
62
-		}
63
-	}
39
+    /**
40
+     * Returns the cache storage for the logged in user
41
+     *
42
+     * @return \OC\Files\View cache storage
43
+     * @throws \OC\ForbiddenException
44
+     * @throws \OC\User\NoUserException
45
+     */
46
+    protected function getStorage() {
47
+        if (isset($this->storage)) {
48
+            return $this->storage;
49
+        }
50
+        if (\OC::$server->getUserSession()->isLoggedIn()) {
51
+            $rootView = new View();
52
+            $user = \OC::$server->getUserSession()->getUser();
53
+            Filesystem::initMountPoints($user->getUID());
54
+            if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) {
55
+                $rootView->mkdir('/' . $user->getUID() . '/cache');
56
+            }
57
+            $this->storage = new View('/' . $user->getUID() . '/cache');
58
+            return $this->storage;
59
+        } else {
60
+            \OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', \OCP\Util::ERROR);
61
+            throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in');
62
+        }
63
+    }
64 64
 
65
-	/**
66
-	 * @param string $key
67
-	 * @return mixed|null
68
-	 * @throws \OC\ForbiddenException
69
-	 */
70
-	public function get($key) {
71
-		$result = null;
72
-		if ($this->hasKey($key)) {
73
-			$storage = $this->getStorage();
74
-			$result = $storage->file_get_contents($key);
75
-		}
76
-		return $result;
77
-	}
65
+    /**
66
+     * @param string $key
67
+     * @return mixed|null
68
+     * @throws \OC\ForbiddenException
69
+     */
70
+    public function get($key) {
71
+        $result = null;
72
+        if ($this->hasKey($key)) {
73
+            $storage = $this->getStorage();
74
+            $result = $storage->file_get_contents($key);
75
+        }
76
+        return $result;
77
+    }
78 78
 
79
-	/**
80
-	 * Returns the size of the stored/cached data
81
-	 *
82
-	 * @param string $key
83
-	 * @return int
84
-	 */
85
-	public function size($key) {
86
-		$result = 0;
87
-		if ($this->hasKey($key)) {
88
-			$storage = $this->getStorage();
89
-			$result = $storage->filesize($key);
90
-		}
91
-		return $result;
92
-	}
79
+    /**
80
+     * Returns the size of the stored/cached data
81
+     *
82
+     * @param string $key
83
+     * @return int
84
+     */
85
+    public function size($key) {
86
+        $result = 0;
87
+        if ($this->hasKey($key)) {
88
+            $storage = $this->getStorage();
89
+            $result = $storage->filesize($key);
90
+        }
91
+        return $result;
92
+    }
93 93
 
94
-	/**
95
-	 * @param string $key
96
-	 * @param mixed $value
97
-	 * @param int $ttl
98
-	 * @return bool|mixed
99
-	 * @throws \OC\ForbiddenException
100
-	 */
101
-	public function set($key, $value, $ttl = 0) {
102
-		$storage = $this->getStorage();
103
-		$result = false;
104
-		// unique id to avoid chunk collision, just in case
105
-		$uniqueId = \OC::$server->getSecureRandom()->generate(
106
-			16,
107
-			ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER
108
-		);
94
+    /**
95
+     * @param string $key
96
+     * @param mixed $value
97
+     * @param int $ttl
98
+     * @return bool|mixed
99
+     * @throws \OC\ForbiddenException
100
+     */
101
+    public function set($key, $value, $ttl = 0) {
102
+        $storage = $this->getStorage();
103
+        $result = false;
104
+        // unique id to avoid chunk collision, just in case
105
+        $uniqueId = \OC::$server->getSecureRandom()->generate(
106
+            16,
107
+            ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER
108
+        );
109 109
 
110
-		// use part file to prevent hasKey() to find the key
111
-		// while it is being written
112
-		$keyPart = $key . '.' . $uniqueId . '.part';
113
-		if ($storage and $storage->file_put_contents($keyPart, $value)) {
114
-			if ($ttl === 0) {
115
-				$ttl = 86400; // 60*60*24
116
-			}
117
-			$result = $storage->touch($keyPart, time() + $ttl);
118
-			$result &= $storage->rename($keyPart, $key);
119
-		}
120
-		return $result;
121
-	}
110
+        // use part file to prevent hasKey() to find the key
111
+        // while it is being written
112
+        $keyPart = $key . '.' . $uniqueId . '.part';
113
+        if ($storage and $storage->file_put_contents($keyPart, $value)) {
114
+            if ($ttl === 0) {
115
+                $ttl = 86400; // 60*60*24
116
+            }
117
+            $result = $storage->touch($keyPart, time() + $ttl);
118
+            $result &= $storage->rename($keyPart, $key);
119
+        }
120
+        return $result;
121
+    }
122 122
 
123
-	/**
124
-	 * @param string $key
125
-	 * @return bool
126
-	 * @throws \OC\ForbiddenException
127
-	 */
128
-	public function hasKey($key) {
129
-		$storage = $this->getStorage();
130
-		if ($storage && $storage->is_file($key) && $storage->isReadable($key)) {
131
-			return true;
132
-		}
133
-		return false;
134
-	}
123
+    /**
124
+     * @param string $key
125
+     * @return bool
126
+     * @throws \OC\ForbiddenException
127
+     */
128
+    public function hasKey($key) {
129
+        $storage = $this->getStorage();
130
+        if ($storage && $storage->is_file($key) && $storage->isReadable($key)) {
131
+            return true;
132
+        }
133
+        return false;
134
+    }
135 135
 
136
-	/**
137
-	 * @param string $key
138
-	 * @return bool|mixed
139
-	 * @throws \OC\ForbiddenException
140
-	 */
141
-	public function remove($key) {
142
-		$storage = $this->getStorage();
143
-		if (!$storage) {
144
-			return false;
145
-		}
146
-		return $storage->unlink($key);
147
-	}
136
+    /**
137
+     * @param string $key
138
+     * @return bool|mixed
139
+     * @throws \OC\ForbiddenException
140
+     */
141
+    public function remove($key) {
142
+        $storage = $this->getStorage();
143
+        if (!$storage) {
144
+            return false;
145
+        }
146
+        return $storage->unlink($key);
147
+    }
148 148
 
149
-	/**
150
-	 * @param string $prefix
151
-	 * @return bool
152
-	 * @throws \OC\ForbiddenException
153
-	 */
154
-	public function clear($prefix = '') {
155
-		$storage = $this->getStorage();
156
-		if ($storage and $storage->is_dir('/')) {
157
-			$dh = $storage->opendir('/');
158
-			if (is_resource($dh)) {
159
-				while (($file = readdir($dh)) !== false) {
160
-					if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) {
161
-						$storage->unlink('/' . $file);
162
-					}
163
-				}
164
-			}
165
-		}
166
-		return true;
167
-	}
149
+    /**
150
+     * @param string $prefix
151
+     * @return bool
152
+     * @throws \OC\ForbiddenException
153
+     */
154
+    public function clear($prefix = '') {
155
+        $storage = $this->getStorage();
156
+        if ($storage and $storage->is_dir('/')) {
157
+            $dh = $storage->opendir('/');
158
+            if (is_resource($dh)) {
159
+                while (($file = readdir($dh)) !== false) {
160
+                    if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) {
161
+                        $storage->unlink('/' . $file);
162
+                    }
163
+                }
164
+            }
165
+        }
166
+        return true;
167
+    }
168 168
 
169
-	/**
170
-	 * Runs GC
171
-	 * @throws \OC\ForbiddenException
172
-	 */
173
-	public function gc() {
174
-		$storage = $this->getStorage();
175
-		if ($storage and $storage->is_dir('/')) {
176
-			// extra hour safety, in case of stray part chunks that take longer to write,
177
-			// because touch() is only called after the chunk was finished
178
-			$now = time() - 3600;
179
-			$dh = $storage->opendir('/');
180
-			if (!is_resource($dh)) {
181
-				return null;
182
-			}
183
-			while (($file = readdir($dh)) !== false) {
184
-				if ($file != '.' and $file != '..') {
185
-					try {
186
-						$mtime = $storage->filemtime('/' . $file);
187
-						if ($mtime < $now) {
188
-							$storage->unlink('/' . $file);
189
-						}
190
-					} catch (\OCP\Lock\LockedException $e) {
191
-						// ignore locked chunks
192
-						\OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core'));
193
-					} catch (\OCP\Files\ForbiddenException $e) {
194
-						\OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core'));
195
-					} catch (\OCP\Files\LockNotAcquiredException $e) {
196
-						\OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core'));
197
-					}
198
-				}
199
-			}
200
-		}
201
-	}
169
+    /**
170
+     * Runs GC
171
+     * @throws \OC\ForbiddenException
172
+     */
173
+    public function gc() {
174
+        $storage = $this->getStorage();
175
+        if ($storage and $storage->is_dir('/')) {
176
+            // extra hour safety, in case of stray part chunks that take longer to write,
177
+            // because touch() is only called after the chunk was finished
178
+            $now = time() - 3600;
179
+            $dh = $storage->opendir('/');
180
+            if (!is_resource($dh)) {
181
+                return null;
182
+            }
183
+            while (($file = readdir($dh)) !== false) {
184
+                if ($file != '.' and $file != '..') {
185
+                    try {
186
+                        $mtime = $storage->filemtime('/' . $file);
187
+                        if ($mtime < $now) {
188
+                            $storage->unlink('/' . $file);
189
+                        }
190
+                    } catch (\OCP\Lock\LockedException $e) {
191
+                        // ignore locked chunks
192
+                        \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core'));
193
+                    } catch (\OCP\Files\ForbiddenException $e) {
194
+                        \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core'));
195
+                    } catch (\OCP\Files\LockNotAcquiredException $e) {
196
+                        \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core'));
197
+                    }
198
+                }
199
+            }
200
+        }
201
+    }
202 202
 }
Please login to merge, or discard this patch.
core/Controller/LostController.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@
 block discarded – undo
132 132
 	}
133 133
 
134 134
 	/**
135
-	 * @param $message
135
+	 * @param string $message
136 136
 	 * @param array $additional
137 137
 	 * @return array
138 138
 	 */
Please login to merge, or discard this patch.
Indentation   +299 added lines, -299 removed lines patch added patch discarded remove patch
@@ -55,303 +55,303 @@
 block discarded – undo
55 55
  */
56 56
 class LostController extends Controller {
57 57
 
58
-	/** @var IURLGenerator */
59
-	protected $urlGenerator;
60
-	/** @var IUserManager */
61
-	protected $userManager;
62
-	/** @var Defaults */
63
-	protected $defaults;
64
-	/** @var IL10N */
65
-	protected $l10n;
66
-	/** @var string */
67
-	protected $from;
68
-	/** @var IManager */
69
-	protected $encryptionManager;
70
-	/** @var IConfig */
71
-	protected $config;
72
-	/** @var ISecureRandom */
73
-	protected $secureRandom;
74
-	/** @var IMailer */
75
-	protected $mailer;
76
-	/** @var ITimeFactory */
77
-	protected $timeFactory;
78
-	/** @var ICrypto */
79
-	protected $crypto;
80
-
81
-	/**
82
-	 * @param string $appName
83
-	 * @param IRequest $request
84
-	 * @param IURLGenerator $urlGenerator
85
-	 * @param IUserManager $userManager
86
-	 * @param Defaults $defaults
87
-	 * @param IL10N $l10n
88
-	 * @param IConfig $config
89
-	 * @param ISecureRandom $secureRandom
90
-	 * @param string $defaultMailAddress
91
-	 * @param IManager $encryptionManager
92
-	 * @param IMailer $mailer
93
-	 * @param ITimeFactory $timeFactory
94
-	 * @param ICrypto $crypto
95
-	 */
96
-	public function __construct($appName,
97
-								IRequest $request,
98
-								IURLGenerator $urlGenerator,
99
-								IUserManager $userManager,
100
-								Defaults $defaults,
101
-								IL10N $l10n,
102
-								IConfig $config,
103
-								ISecureRandom $secureRandom,
104
-								$defaultMailAddress,
105
-								IManager $encryptionManager,
106
-								IMailer $mailer,
107
-								ITimeFactory $timeFactory,
108
-								ICrypto $crypto) {
109
-		parent::__construct($appName, $request);
110
-		$this->urlGenerator = $urlGenerator;
111
-		$this->userManager = $userManager;
112
-		$this->defaults = $defaults;
113
-		$this->l10n = $l10n;
114
-		$this->secureRandom = $secureRandom;
115
-		$this->from = $defaultMailAddress;
116
-		$this->encryptionManager = $encryptionManager;
117
-		$this->config = $config;
118
-		$this->mailer = $mailer;
119
-		$this->timeFactory = $timeFactory;
120
-		$this->crypto = $crypto;
121
-	}
122
-
123
-	/**
124
-	 * Someone wants to reset their password:
125
-	 *
126
-	 * @PublicPage
127
-	 * @NoCSRFRequired
128
-	 *
129
-	 * @param string $token
130
-	 * @param string $userId
131
-	 * @return TemplateResponse
132
-	 */
133
-	public function resetform($token, $userId) {
134
-		if ($this->config->getSystemValue('lost_password_link', '') !== '') {
135
-			return new TemplateResponse('core', 'error', [
136
-					'errors' => [['error' => $this->l10n->t('Password reset is disabled')]]
137
-				],
138
-				'guest'
139
-			);
140
-		}
141
-
142
-		try {
143
-			$this->checkPasswordResetToken($token, $userId);
144
-		} catch (\Exception $e) {
145
-			return new TemplateResponse(
146
-				'core', 'error', [
147
-					"errors" => array(array("error" => $e->getMessage()))
148
-				],
149
-				'guest'
150
-			);
151
-		}
152
-
153
-		return new TemplateResponse(
154
-			'core',
155
-			'lostpassword/resetpassword',
156
-			array(
157
-				'link' => $this->urlGenerator->linkToRouteAbsolute('core.lost.setPassword', array('userId' => $userId, 'token' => $token)),
158
-			),
159
-			'guest'
160
-		);
161
-	}
162
-
163
-	/**
164
-	 * @param string $token
165
-	 * @param string $userId
166
-	 * @throws \Exception
167
-	 */
168
-	protected function checkPasswordResetToken($token, $userId) {
169
-		$user = $this->userManager->get($userId);
170
-		if($user === null) {
171
-			throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
172
-		}
173
-
174
-		try {
175
-			$encryptedToken = $this->config->getUserValue($userId, 'core', 'lostpassword', null);
176
-			$mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : '';
177
-			$decryptedToken = $this->crypto->decrypt($encryptedToken, $mailAddress.$this->config->getSystemValue('secret'));
178
-		} catch (\Exception $e) {
179
-			throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
180
-		}
181
-
182
-		$splittedToken = explode(':', $decryptedToken);
183
-		if(count($splittedToken) !== 2) {
184
-			throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
185
-		}
186
-
187
-		if ($splittedToken[0] < ($this->timeFactory->getTime() - 60*60*12) ||
188
-			$user->getLastLogin() > $splittedToken[0]) {
189
-			throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired'));
190
-		}
191
-
192
-		if (!hash_equals($splittedToken[1], $token)) {
193
-			throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
194
-		}
195
-	}
196
-
197
-	/**
198
-	 * @param $message
199
-	 * @param array $additional
200
-	 * @return array
201
-	 */
202
-	private function error($message, array $additional=array()) {
203
-		return array_merge(array('status' => 'error', 'msg' => $message), $additional);
204
-	}
205
-
206
-	/**
207
-	 * @return array
208
-	 */
209
-	private function success() {
210
-		return array('status'=>'success');
211
-	}
212
-
213
-	/**
214
-	 * @PublicPage
215
-	 * @BruteForceProtection(action=passwordResetEmail)
216
-	 * @AnonRateThrottle(limit=10, period=300)
217
-	 *
218
-	 * @param string $user
219
-	 * @return JSONResponse
220
-	 */
221
-	public function email($user){
222
-		if ($this->config->getSystemValue('lost_password_link', '') !== '') {
223
-			return new JSONResponse($this->error($this->l10n->t('Password reset is disabled')));
224
-		}
225
-
226
-		// FIXME: use HTTP error codes
227
-		try {
228
-			$this->sendEmail($user);
229
-		} catch (\Exception $e){
230
-			$response = new JSONResponse($this->error($e->getMessage()));
231
-			$response->throttle();
232
-			return $response;
233
-		}
234
-
235
-		$response = new JSONResponse($this->success());
236
-		$response->throttle();
237
-		return $response;
238
-	}
239
-
240
-	/**
241
-	 * @PublicPage
242
-	 * @param string $token
243
-	 * @param string $userId
244
-	 * @param string $password
245
-	 * @param boolean $proceed
246
-	 * @return array
247
-	 */
248
-	public function setPassword($token, $userId, $password, $proceed) {
249
-		if ($this->config->getSystemValue('lost_password_link', '') !== '') {
250
-			return $this->error($this->l10n->t('Password reset is disabled'));
251
-		}
252
-
253
-		if ($this->encryptionManager->isEnabled() && !$proceed) {
254
-			return $this->error('', array('encryption' => true));
255
-		}
256
-
257
-		try {
258
-			$this->checkPasswordResetToken($token, $userId);
259
-			$user = $this->userManager->get($userId);
260
-
261
-			\OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'pre_passwordReset', array('uid' => $userId, 'password' => $password));
262
-
263
-			if (!$user->setPassword($password)) {
264
-				throw new \Exception();
265
-			}
266
-
267
-			\OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', array('uid' => $userId, 'password' => $password));
268
-
269
-			$this->config->deleteUserValue($userId, 'core', 'lostpassword');
270
-			@\OC::$server->getUserSession()->unsetMagicInCookie();
271
-		} catch (\Exception $e){
272
-			return $this->error($e->getMessage());
273
-		}
274
-
275
-		return $this->success();
276
-	}
277
-
278
-	/**
279
-	 * @param string $input
280
-	 * @throws \Exception
281
-	 */
282
-	protected function sendEmail($input) {
283
-		$user = $this->findUserByIdOrMail($input);
284
-		$email = $user->getEMailAddress();
285
-
286
-		if (empty($email)) {
287
-			throw new \Exception(
288
-				$this->l10n->t('Could not send reset email because there is no email address for this username. Please contact your administrator.')
289
-			);
290
-		}
291
-
292
-		// Generate the token. It is stored encrypted in the database with the
293
-		// secret being the users' email address appended with the system secret.
294
-		// This makes the token automatically invalidate once the user changes
295
-		// their email address.
296
-		$token = $this->secureRandom->generate(
297
-			21,
298
-			ISecureRandom::CHAR_DIGITS.
299
-			ISecureRandom::CHAR_LOWER.
300
-			ISecureRandom::CHAR_UPPER
301
-		);
302
-		$tokenValue = $this->timeFactory->getTime() .':'. $token;
303
-		$encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret'));
304
-		$this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue);
305
-
306
-		$link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user->getUID(), 'token' => $token));
307
-
308
-		$emailTemplate = $this->mailer->createEMailTemplate();
309
-
310
-		$emailTemplate->addHeader();
311
-		$emailTemplate->addHeading($this->l10n->t('Password reset'));
312
-
313
-		$emailTemplate->addBodyText(
314
-			$this->l10n->t('Click the following button to reset your password. If you have not requested the password reset, then ignore this email.'),
315
-			$this->l10n->t('Click the following link to reset your password. If you have not requested the password reset, then ignore this email.')
316
-		);
317
-
318
-		$emailTemplate->addBodyButton(
319
-			$this->l10n->t('Reset your password'),
320
-			$link,
321
-			false
322
-		);
323
-		$emailTemplate->addFooter();
324
-
325
-		try {
326
-			$message = $this->mailer->createMessage();
327
-			$message->setTo([$email => $user->getUID()]);
328
-			$message->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()]));
329
-			$message->setPlainBody($emailTemplate->renderText());
330
-			$message->setHtmlBody($emailTemplate->renderHtml());
331
-			$message->setFrom([$this->from => $this->defaults->getName()]);
332
-			$this->mailer->send($message);
333
-		} catch (\Exception $e) {
334
-			throw new \Exception($this->l10n->t(
335
-				'Couldn\'t send reset email. Please contact your administrator.'
336
-			));
337
-		}
338
-	}
339
-
340
-	/**
341
-	 * @param string $input
342
-	 * @return IUser
343
-	 * @throws \Exception
344
-	 */
345
-	protected function findUserByIdOrMail($input) {
346
-		$user = $this->userManager->get($input);
347
-		if ($user instanceof IUser) {
348
-			return $user;
349
-		}
350
-		$users = $this->userManager->getByEmail($input);
351
-		if (count($users) === 1) {
352
-			return $users[0];
353
-		}
354
-
355
-		throw new \InvalidArgumentException($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.'));
356
-	}
58
+    /** @var IURLGenerator */
59
+    protected $urlGenerator;
60
+    /** @var IUserManager */
61
+    protected $userManager;
62
+    /** @var Defaults */
63
+    protected $defaults;
64
+    /** @var IL10N */
65
+    protected $l10n;
66
+    /** @var string */
67
+    protected $from;
68
+    /** @var IManager */
69
+    protected $encryptionManager;
70
+    /** @var IConfig */
71
+    protected $config;
72
+    /** @var ISecureRandom */
73
+    protected $secureRandom;
74
+    /** @var IMailer */
75
+    protected $mailer;
76
+    /** @var ITimeFactory */
77
+    protected $timeFactory;
78
+    /** @var ICrypto */
79
+    protected $crypto;
80
+
81
+    /**
82
+     * @param string $appName
83
+     * @param IRequest $request
84
+     * @param IURLGenerator $urlGenerator
85
+     * @param IUserManager $userManager
86
+     * @param Defaults $defaults
87
+     * @param IL10N $l10n
88
+     * @param IConfig $config
89
+     * @param ISecureRandom $secureRandom
90
+     * @param string $defaultMailAddress
91
+     * @param IManager $encryptionManager
92
+     * @param IMailer $mailer
93
+     * @param ITimeFactory $timeFactory
94
+     * @param ICrypto $crypto
95
+     */
96
+    public function __construct($appName,
97
+                                IRequest $request,
98
+                                IURLGenerator $urlGenerator,
99
+                                IUserManager $userManager,
100
+                                Defaults $defaults,
101
+                                IL10N $l10n,
102
+                                IConfig $config,
103
+                                ISecureRandom $secureRandom,
104
+                                $defaultMailAddress,
105
+                                IManager $encryptionManager,
106
+                                IMailer $mailer,
107
+                                ITimeFactory $timeFactory,
108
+                                ICrypto $crypto) {
109
+        parent::__construct($appName, $request);
110
+        $this->urlGenerator = $urlGenerator;
111
+        $this->userManager = $userManager;
112
+        $this->defaults = $defaults;
113
+        $this->l10n = $l10n;
114
+        $this->secureRandom = $secureRandom;
115
+        $this->from = $defaultMailAddress;
116
+        $this->encryptionManager = $encryptionManager;
117
+        $this->config = $config;
118
+        $this->mailer = $mailer;
119
+        $this->timeFactory = $timeFactory;
120
+        $this->crypto = $crypto;
121
+    }
122
+
123
+    /**
124
+     * Someone wants to reset their password:
125
+     *
126
+     * @PublicPage
127
+     * @NoCSRFRequired
128
+     *
129
+     * @param string $token
130
+     * @param string $userId
131
+     * @return TemplateResponse
132
+     */
133
+    public function resetform($token, $userId) {
134
+        if ($this->config->getSystemValue('lost_password_link', '') !== '') {
135
+            return new TemplateResponse('core', 'error', [
136
+                    'errors' => [['error' => $this->l10n->t('Password reset is disabled')]]
137
+                ],
138
+                'guest'
139
+            );
140
+        }
141
+
142
+        try {
143
+            $this->checkPasswordResetToken($token, $userId);
144
+        } catch (\Exception $e) {
145
+            return new TemplateResponse(
146
+                'core', 'error', [
147
+                    "errors" => array(array("error" => $e->getMessage()))
148
+                ],
149
+                'guest'
150
+            );
151
+        }
152
+
153
+        return new TemplateResponse(
154
+            'core',
155
+            'lostpassword/resetpassword',
156
+            array(
157
+                'link' => $this->urlGenerator->linkToRouteAbsolute('core.lost.setPassword', array('userId' => $userId, 'token' => $token)),
158
+            ),
159
+            'guest'
160
+        );
161
+    }
162
+
163
+    /**
164
+     * @param string $token
165
+     * @param string $userId
166
+     * @throws \Exception
167
+     */
168
+    protected function checkPasswordResetToken($token, $userId) {
169
+        $user = $this->userManager->get($userId);
170
+        if($user === null) {
171
+            throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
172
+        }
173
+
174
+        try {
175
+            $encryptedToken = $this->config->getUserValue($userId, 'core', 'lostpassword', null);
176
+            $mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : '';
177
+            $decryptedToken = $this->crypto->decrypt($encryptedToken, $mailAddress.$this->config->getSystemValue('secret'));
178
+        } catch (\Exception $e) {
179
+            throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
180
+        }
181
+
182
+        $splittedToken = explode(':', $decryptedToken);
183
+        if(count($splittedToken) !== 2) {
184
+            throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
185
+        }
186
+
187
+        if ($splittedToken[0] < ($this->timeFactory->getTime() - 60*60*12) ||
188
+            $user->getLastLogin() > $splittedToken[0]) {
189
+            throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired'));
190
+        }
191
+
192
+        if (!hash_equals($splittedToken[1], $token)) {
193
+            throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
194
+        }
195
+    }
196
+
197
+    /**
198
+     * @param $message
199
+     * @param array $additional
200
+     * @return array
201
+     */
202
+    private function error($message, array $additional=array()) {
203
+        return array_merge(array('status' => 'error', 'msg' => $message), $additional);
204
+    }
205
+
206
+    /**
207
+     * @return array
208
+     */
209
+    private function success() {
210
+        return array('status'=>'success');
211
+    }
212
+
213
+    /**
214
+     * @PublicPage
215
+     * @BruteForceProtection(action=passwordResetEmail)
216
+     * @AnonRateThrottle(limit=10, period=300)
217
+     *
218
+     * @param string $user
219
+     * @return JSONResponse
220
+     */
221
+    public function email($user){
222
+        if ($this->config->getSystemValue('lost_password_link', '') !== '') {
223
+            return new JSONResponse($this->error($this->l10n->t('Password reset is disabled')));
224
+        }
225
+
226
+        // FIXME: use HTTP error codes
227
+        try {
228
+            $this->sendEmail($user);
229
+        } catch (\Exception $e){
230
+            $response = new JSONResponse($this->error($e->getMessage()));
231
+            $response->throttle();
232
+            return $response;
233
+        }
234
+
235
+        $response = new JSONResponse($this->success());
236
+        $response->throttle();
237
+        return $response;
238
+    }
239
+
240
+    /**
241
+     * @PublicPage
242
+     * @param string $token
243
+     * @param string $userId
244
+     * @param string $password
245
+     * @param boolean $proceed
246
+     * @return array
247
+     */
248
+    public function setPassword($token, $userId, $password, $proceed) {
249
+        if ($this->config->getSystemValue('lost_password_link', '') !== '') {
250
+            return $this->error($this->l10n->t('Password reset is disabled'));
251
+        }
252
+
253
+        if ($this->encryptionManager->isEnabled() && !$proceed) {
254
+            return $this->error('', array('encryption' => true));
255
+        }
256
+
257
+        try {
258
+            $this->checkPasswordResetToken($token, $userId);
259
+            $user = $this->userManager->get($userId);
260
+
261
+            \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'pre_passwordReset', array('uid' => $userId, 'password' => $password));
262
+
263
+            if (!$user->setPassword($password)) {
264
+                throw new \Exception();
265
+            }
266
+
267
+            \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', array('uid' => $userId, 'password' => $password));
268
+
269
+            $this->config->deleteUserValue($userId, 'core', 'lostpassword');
270
+            @\OC::$server->getUserSession()->unsetMagicInCookie();
271
+        } catch (\Exception $e){
272
+            return $this->error($e->getMessage());
273
+        }
274
+
275
+        return $this->success();
276
+    }
277
+
278
+    /**
279
+     * @param string $input
280
+     * @throws \Exception
281
+     */
282
+    protected function sendEmail($input) {
283
+        $user = $this->findUserByIdOrMail($input);
284
+        $email = $user->getEMailAddress();
285
+
286
+        if (empty($email)) {
287
+            throw new \Exception(
288
+                $this->l10n->t('Could not send reset email because there is no email address for this username. Please contact your administrator.')
289
+            );
290
+        }
291
+
292
+        // Generate the token. It is stored encrypted in the database with the
293
+        // secret being the users' email address appended with the system secret.
294
+        // This makes the token automatically invalidate once the user changes
295
+        // their email address.
296
+        $token = $this->secureRandom->generate(
297
+            21,
298
+            ISecureRandom::CHAR_DIGITS.
299
+            ISecureRandom::CHAR_LOWER.
300
+            ISecureRandom::CHAR_UPPER
301
+        );
302
+        $tokenValue = $this->timeFactory->getTime() .':'. $token;
303
+        $encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret'));
304
+        $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue);
305
+
306
+        $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user->getUID(), 'token' => $token));
307
+
308
+        $emailTemplate = $this->mailer->createEMailTemplate();
309
+
310
+        $emailTemplate->addHeader();
311
+        $emailTemplate->addHeading($this->l10n->t('Password reset'));
312
+
313
+        $emailTemplate->addBodyText(
314
+            $this->l10n->t('Click the following button to reset your password. If you have not requested the password reset, then ignore this email.'),
315
+            $this->l10n->t('Click the following link to reset your password. If you have not requested the password reset, then ignore this email.')
316
+        );
317
+
318
+        $emailTemplate->addBodyButton(
319
+            $this->l10n->t('Reset your password'),
320
+            $link,
321
+            false
322
+        );
323
+        $emailTemplate->addFooter();
324
+
325
+        try {
326
+            $message = $this->mailer->createMessage();
327
+            $message->setTo([$email => $user->getUID()]);
328
+            $message->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()]));
329
+            $message->setPlainBody($emailTemplate->renderText());
330
+            $message->setHtmlBody($emailTemplate->renderHtml());
331
+            $message->setFrom([$this->from => $this->defaults->getName()]);
332
+            $this->mailer->send($message);
333
+        } catch (\Exception $e) {
334
+            throw new \Exception($this->l10n->t(
335
+                'Couldn\'t send reset email. Please contact your administrator.'
336
+            ));
337
+        }
338
+    }
339
+
340
+    /**
341
+     * @param string $input
342
+     * @return IUser
343
+     * @throws \Exception
344
+     */
345
+    protected function findUserByIdOrMail($input) {
346
+        $user = $this->userManager->get($input);
347
+        if ($user instanceof IUser) {
348
+            return $user;
349
+        }
350
+        $users = $this->userManager->getByEmail($input);
351
+        if (count($users) === 1) {
352
+            return $users[0];
353
+        }
354
+
355
+        throw new \InvalidArgumentException($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.'));
356
+    }
357 357
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 	 */
168 168
 	protected function checkPasswordResetToken($token, $userId) {
169 169
 		$user = $this->userManager->get($userId);
170
-		if($user === null) {
170
+		if ($user === null) {
171 171
 			throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
172 172
 		}
173 173
 
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
 		}
181 181
 
182 182
 		$splittedToken = explode(':', $decryptedToken);
183
-		if(count($splittedToken) !== 2) {
183
+		if (count($splittedToken) !== 2) {
184 184
 			throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
185 185
 		}
186 186
 
187
-		if ($splittedToken[0] < ($this->timeFactory->getTime() - 60*60*12) ||
187
+		if ($splittedToken[0] < ($this->timeFactory->getTime() - 60 * 60 * 12) ||
188 188
 			$user->getLastLogin() > $splittedToken[0]) {
189 189
 			throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired'));
190 190
 		}
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 	 * @param array $additional
200 200
 	 * @return array
201 201
 	 */
202
-	private function error($message, array $additional=array()) {
202
+	private function error($message, array $additional = array()) {
203 203
 		return array_merge(array('status' => 'error', 'msg' => $message), $additional);
204 204
 	}
205 205
 
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	 * @param string $user
219 219
 	 * @return JSONResponse
220 220
 	 */
221
-	public function email($user){
221
+	public function email($user) {
222 222
 		if ($this->config->getSystemValue('lost_password_link', '') !== '') {
223 223
 			return new JSONResponse($this->error($this->l10n->t('Password reset is disabled')));
224 224
 		}
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 		// FIXME: use HTTP error codes
227 227
 		try {
228 228
 			$this->sendEmail($user);
229
-		} catch (\Exception $e){
229
+		} catch (\Exception $e) {
230 230
 			$response = new JSONResponse($this->error($e->getMessage()));
231 231
 			$response->throttle();
232 232
 			return $response;
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 
269 269
 			$this->config->deleteUserValue($userId, 'core', 'lostpassword');
270 270
 			@\OC::$server->getUserSession()->unsetMagicInCookie();
271
-		} catch (\Exception $e){
271
+		} catch (\Exception $e) {
272 272
 			return $this->error($e->getMessage());
273 273
 		}
274 274
 
@@ -299,8 +299,8 @@  discard block
 block discarded – undo
299 299
 			ISecureRandom::CHAR_LOWER.
300 300
 			ISecureRandom::CHAR_UPPER
301 301
 		);
302
-		$tokenValue = $this->timeFactory->getTime() .':'. $token;
303
-		$encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret'));
302
+		$tokenValue = $this->timeFactory->getTime().':'.$token;
303
+		$encryptedValue = $this->crypto->encrypt($tokenValue, $email.$this->config->getSystemValue('secret'));
304 304
 		$this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue);
305 305
 
306 306
 		$link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user->getUID(), 'token' => $token));
Please login to merge, or discard this patch.
apps/files_external/lib/Service/DBConfigService.php 3 patches
Doc Comments   +16 added lines patch added patch discarded remove patch
@@ -89,6 +89,9 @@  discard block
 block discarded – undo
89 89
 		return $this->getMountsFromQuery($query);
90 90
 	}
91 91
 
92
+	/**
93
+	 * @param string $userId
94
+	 */
92 95
 	public function getMountsForUser($userId, $groupIds) {
93 96
 		$builder = $this->connection->getQueryBuilder();
94 97
 		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
@@ -125,6 +128,10 @@  discard block
 block discarded – undo
125 128
 		return $this->getMountsFromQuery($query);
126 129
 	}
127 130
 
131
+	/**
132
+	 * @param integer $type
133
+	 * @param string|null $value
134
+	 */
128 135
 	protected function getForQuery(IQueryBuilder $builder, $type, $value) {
129 136
 		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
130 137
 			->from('external_mounts', 'm')
@@ -332,6 +339,9 @@  discard block
 block discarded – undo
332 339
 		}
333 340
 	}
334 341
 
342
+	/**
343
+	 * @param integer $mountId
344
+	 */
335 345
 	public function addApplicable($mountId, $type, $value) {
336 346
 		$this->connection->insertIfNotExist('*PREFIX*external_applicable', [
337 347
 			'mount_id' => $mountId,
@@ -340,6 +350,9 @@  discard block
 block discarded – undo
340 350
 		], ['mount_id', 'type', 'value']);
341 351
 	}
342 352
 
353
+	/**
354
+	 * @param integer $mountId
355
+	 */
343 356
 	public function removeApplicable($mountId, $type, $value) {
344 357
 		$builder = $this->connection->getQueryBuilder();
345 358
 		$query = $builder->delete('external_applicable')
@@ -473,6 +486,9 @@  discard block
 block discarded – undo
473 486
 		return array_combine($keys, $values);
474 487
 	}
475 488
 
489
+	/**
490
+	 * @param string $value
491
+	 */
476 492
 	private function encryptValue($value) {
477 493
 		return $this->crypto->encrypt($value);
478 494
 	}
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 */
179 179
 	public function getAdminMountsForMultiple($type, array $values) {
180 180
 		$builder = $this->connection->getQueryBuilder();
181
-		$params = array_map(function ($value) use ($builder) {
181
+		$params = array_map(function($value) use ($builder) {
182 182
 			return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR);
183 183
 		}, $values);
184 184
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 				'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)
232 232
 			]);
233 233
 		$query->execute();
234
-		return (int)$this->connection->lastInsertId('*PREFIX*external_mounts');
234
+		return (int) $this->connection->lastInsertId('*PREFIX*external_mounts');
235 235
 	}
236 236
 
237 237
 	/**
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 		}
368 368
 		$uniqueMounts = array_values($uniqueMounts);
369 369
 
370
-		$mountIds = array_map(function ($mount) {
370
+		$mountIds = array_map(function($mount) {
371 371
 			return $mount['mount_id'];
372 372
 		}, $uniqueMounts);
373 373
 		$mountIds = array_values(array_unique($mountIds));
@@ -376,9 +376,9 @@  discard block
 block discarded – undo
376 376
 		$config = $this->getConfigForMounts($mountIds);
377 377
 		$options = $this->getOptionsForMounts($mountIds);
378 378
 
379
-		return array_map(function ($mount, $applicable, $config, $options) {
380
-			$mount['type'] = (int)$mount['type'];
381
-			$mount['priority'] = (int)$mount['priority'];
379
+		return array_map(function($mount, $applicable, $config, $options) {
380
+			$mount['type'] = (int) $mount['type'];
381
+			$mount['priority'] = (int) $mount['priority'];
382 382
 			$mount['applicable'] = $applicable;
383 383
 			$mount['config'] = $config;
384 384
 			$mount['options'] = $options;
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 		}
401 401
 		$builder = $this->connection->getQueryBuilder();
402 402
 		$fields[] = 'mount_id';
403
-		$placeHolders = array_map(function ($id) use ($builder) {
403
+		$placeHolders = array_map(function($id) use ($builder) {
404 404
 			return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT);
405 405
 		}, $mountIds);
406 406
 		$query = $builder->select($fields)
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
 		}
415 415
 		foreach ($rows as $row) {
416 416
 			if (isset($row['type'])) {
417
-				$row['type'] = (int)$row['type'];
417
+				$row['type'] = (int) $row['type'];
418 418
 			}
419 419
 			$result[$row['mount_id']][] = $row;
420 420
 		}
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
 	public function getOptionsForMounts($mountIds) {
446 446
 		$mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds);
447 447
 		$optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions);
448
-		return array_map(function (array $options) {
449
-			return array_map(function ($option) {
448
+		return array_map(function(array $options) {
449
+			return array_map(function($option) {
450 450
 				return json_decode($option);
451 451
 			}, $options);
452 452
 		}, $optionsMap);
@@ -457,16 +457,16 @@  discard block
 block discarded – undo
457 457
 	 * @return array ['key1' => $value1, ...]
458 458
 	 */
459 459
 	private function createKeyValueMap(array $keyValuePairs) {
460
-		$decryptedPairts = array_map(function ($pair) {
460
+		$decryptedPairts = array_map(function($pair) {
461 461
 			if ($pair['key'] === 'password') {
462 462
 				$pair['value'] = $this->decryptValue($pair['value']);
463 463
 			}
464 464
 			return $pair;
465 465
 		}, $keyValuePairs);
466
-		$keys = array_map(function ($pair) {
466
+		$keys = array_map(function($pair) {
467 467
 			return $pair['key'];
468 468
 		}, $decryptedPairts);
469
-		$values = array_map(function ($pair) {
469
+		$values = array_map(function($pair) {
470 470
 			return $pair['value'];
471 471
 		}, $decryptedPairts);
472 472
 
Please login to merge, or discard this patch.
Indentation   +456 added lines, -456 removed lines patch added patch discarded remove patch
@@ -32,460 +32,460 @@
 block discarded – undo
32 32
  * Stores the mount config in the database
33 33
  */
34 34
 class DBConfigService {
35
-	const MOUNT_TYPE_ADMIN = 1;
36
-	const MOUNT_TYPE_PERSONAl = 2;
37
-
38
-	const APPLICABLE_TYPE_GLOBAL = 1;
39
-	const APPLICABLE_TYPE_GROUP = 2;
40
-	const APPLICABLE_TYPE_USER = 3;
41
-
42
-	/**
43
-	 * @var IDBConnection
44
-	 */
45
-	private $connection;
46
-
47
-	/**
48
-	 * @var ICrypto
49
-	 */
50
-	private $crypto;
51
-
52
-	/**
53
-	 * DBConfigService constructor.
54
-	 *
55
-	 * @param IDBConnection $connection
56
-	 * @param ICrypto $crypto
57
-	 */
58
-	public function __construct(IDBConnection $connection, ICrypto $crypto) {
59
-		$this->connection = $connection;
60
-		$this->crypto = $crypto;
61
-	}
62
-
63
-	/**
64
-	 * @param int $mountId
65
-	 * @return array
66
-	 */
67
-	public function getMountById($mountId) {
68
-		$builder = $this->connection->getQueryBuilder();
69
-		$query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
70
-			->from('external_mounts', 'm')
71
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
72
-		$mounts = $this->getMountsFromQuery($query);
73
-		if (count($mounts) > 0) {
74
-			return $mounts[0];
75
-		} else {
76
-			return null;
77
-		}
78
-	}
79
-
80
-	/**
81
-	 * Get all configured mounts
82
-	 *
83
-	 * @return array
84
-	 */
85
-	public function getAllMounts() {
86
-		$builder = $this->connection->getQueryBuilder();
87
-		$query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
88
-			->from('external_mounts');
89
-		return $this->getMountsFromQuery($query);
90
-	}
91
-
92
-	public function getMountsForUser($userId, $groupIds) {
93
-		$builder = $this->connection->getQueryBuilder();
94
-		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
95
-			->from('external_mounts', 'm')
96
-			->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
97
-			->where($builder->expr()->orX(
98
-				$builder->expr()->andX( // global mounts
99
-					$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)),
100
-					$builder->expr()->isNull('a.value')
101
-				),
102
-				$builder->expr()->andX( // mounts for user
103
-					$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)),
104
-					$builder->expr()->eq('a.value', $builder->createNamedParameter($userId))
105
-				),
106
-				$builder->expr()->andX( // mounts for group
107
-					$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)),
108
-					$builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY))
109
-				)
110
-			));
111
-
112
-		return $this->getMountsFromQuery($query);
113
-	}
114
-
115
-	/**
116
-	 * Get admin defined mounts
117
-	 *
118
-	 * @return array
119
-	 * @suppress SqlInjectionChecker
120
-	 */
121
-	public function getAdminMounts() {
122
-		$builder = $this->connection->getQueryBuilder();
123
-		$query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
124
-			->from('external_mounts')
125
-			->where($builder->expr()->eq('type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
126
-		return $this->getMountsFromQuery($query);
127
-	}
128
-
129
-	protected function getForQuery(IQueryBuilder $builder, $type, $value) {
130
-		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
131
-			->from('external_mounts', 'm')
132
-			->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
133
-			->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
134
-
135
-		if (is_null($value)) {
136
-			$query = $query->andWhere($builder->expr()->isNull('a.value'));
137
-		} else {
138
-			$query = $query->andWhere($builder->expr()->eq('a.value', $builder->createNamedParameter($value)));
139
-		}
140
-
141
-		return $query;
142
-	}
143
-
144
-	/**
145
-	 * Get mounts by applicable
146
-	 *
147
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
148
-	 * @param string|null $value user_id, group_id or null for global mounts
149
-	 * @return array
150
-	 */
151
-	public function getMountsFor($type, $value) {
152
-		$builder = $this->connection->getQueryBuilder();
153
-		$query = $this->getForQuery($builder, $type, $value);
154
-
155
-		return $this->getMountsFromQuery($query);
156
-	}
157
-
158
-	/**
159
-	 * Get admin defined mounts by applicable
160
-	 *
161
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
162
-	 * @param string|null $value user_id, group_id or null for global mounts
163
-	 * @return array
164
-	 * @suppress SqlInjectionChecker
165
-	 */
166
-	public function getAdminMountsFor($type, $value) {
167
-		$builder = $this->connection->getQueryBuilder();
168
-		$query = $this->getForQuery($builder, $type, $value);
169
-		$query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
170
-
171
-		return $this->getMountsFromQuery($query);
172
-	}
173
-
174
-	/**
175
-	 * Get admin defined mounts for multiple applicable
176
-	 *
177
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
178
-	 * @param string[] $values user_ids or group_ids
179
-	 * @return array
180
-	 * @suppress SqlInjectionChecker
181
-	 */
182
-	public function getAdminMountsForMultiple($type, array $values) {
183
-		$builder = $this->connection->getQueryBuilder();
184
-		$params = array_map(function ($value) use ($builder) {
185
-			return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR);
186
-		}, $values);
187
-
188
-		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
189
-			->from('external_mounts', 'm')
190
-			->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
191
-			->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)))
192
-			->andWhere($builder->expr()->in('a.value', $params));
193
-		$query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
194
-
195
-		return $this->getMountsFromQuery($query);
196
-	}
197
-
198
-	/**
199
-	 * Get user defined mounts by applicable
200
-	 *
201
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
202
-	 * @param string|null $value user_id, group_id or null for global mounts
203
-	 * @return array
204
-	 * @suppress SqlInjectionChecker
205
-	 */
206
-	public function getUserMountsFor($type, $value) {
207
-		$builder = $this->connection->getQueryBuilder();
208
-		$query = $this->getForQuery($builder, $type, $value);
209
-		$query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAl, IQueryBuilder::PARAM_INT)));
210
-
211
-		return $this->getMountsFromQuery($query);
212
-	}
213
-
214
-	/**
215
-	 * Add a mount to the database
216
-	 *
217
-	 * @param string $mountPoint
218
-	 * @param string $storageBackend
219
-	 * @param string $authBackend
220
-	 * @param int $priority
221
-	 * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL
222
-	 * @return int the id of the new mount
223
-	 */
224
-	public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) {
225
-		if (!$priority) {
226
-			$priority = 100;
227
-		}
228
-		$builder = $this->connection->getQueryBuilder();
229
-		$query = $builder->insert('external_mounts')
230
-			->values([
231
-				'mount_point' => $builder->createNamedParameter($mountPoint, IQueryBuilder::PARAM_STR),
232
-				'storage_backend' => $builder->createNamedParameter($storageBackend, IQueryBuilder::PARAM_STR),
233
-				'auth_backend' => $builder->createNamedParameter($authBackend, IQueryBuilder::PARAM_STR),
234
-				'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT),
235
-				'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)
236
-			]);
237
-		$query->execute();
238
-		return (int)$this->connection->lastInsertId('*PREFIX*external_mounts');
239
-	}
240
-
241
-	/**
242
-	 * Remove a mount from the database
243
-	 *
244
-	 * @param int $mountId
245
-	 */
246
-	public function removeMount($mountId) {
247
-		$builder = $this->connection->getQueryBuilder();
248
-		$query = $builder->delete('external_mounts')
249
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
250
-		$query->execute();
251
-
252
-		$query = $builder->delete('external_applicable')
253
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
254
-		$query->execute();
255
-
256
-		$query = $builder->delete('external_config')
257
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
258
-		$query->execute();
259
-
260
-		$query = $builder->delete('external_options')
261
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
262
-		$query->execute();
263
-	}
264
-
265
-	/**
266
-	 * @param int $mountId
267
-	 * @param string $newMountPoint
268
-	 */
269
-	public function setMountPoint($mountId, $newMountPoint) {
270
-		$builder = $this->connection->getQueryBuilder();
271
-
272
-		$query = $builder->update('external_mounts')
273
-			->set('mount_point', $builder->createNamedParameter($newMountPoint))
274
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
275
-
276
-		$query->execute();
277
-	}
278
-
279
-	/**
280
-	 * @param int $mountId
281
-	 * @param string $newAuthBackend
282
-	 */
283
-	public function setAuthBackend($mountId, $newAuthBackend) {
284
-		$builder = $this->connection->getQueryBuilder();
285
-
286
-		$query = $builder->update('external_mounts')
287
-			->set('auth_backend', $builder->createNamedParameter($newAuthBackend))
288
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
289
-
290
-		$query->execute();
291
-	}
292
-
293
-	/**
294
-	 * @param int $mountId
295
-	 * @param string $key
296
-	 * @param string $value
297
-	 */
298
-	public function setConfig($mountId, $key, $value) {
299
-		if ($key === 'password') {
300
-			$value = $this->encryptValue($value);
301
-		}
302
-		$count = $this->connection->insertIfNotExist('*PREFIX*external_config', [
303
-			'mount_id' => $mountId,
304
-			'key' => $key,
305
-			'value' => $value
306
-		], ['mount_id', 'key']);
307
-		if ($count === 0) {
308
-			$builder = $this->connection->getQueryBuilder();
309
-			$query = $builder->update('external_config')
310
-				->set('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))
311
-				->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
312
-				->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
313
-			$query->execute();
314
-		}
315
-	}
316
-
317
-	/**
318
-	 * @param int $mountId
319
-	 * @param string $key
320
-	 * @param string $value
321
-	 */
322
-	public function setOption($mountId, $key, $value) {
323
-
324
-		$count = $this->connection->insertIfNotExist('*PREFIX*external_options', [
325
-			'mount_id' => $mountId,
326
-			'key' => $key,
327
-			'value' => json_encode($value)
328
-		], ['mount_id', 'key']);
329
-		if ($count === 0) {
330
-			$builder = $this->connection->getQueryBuilder();
331
-			$query = $builder->update('external_options')
332
-				->set('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR))
333
-				->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
334
-				->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
335
-			$query->execute();
336
-		}
337
-	}
338
-
339
-	public function addApplicable($mountId, $type, $value) {
340
-		$this->connection->insertIfNotExist('*PREFIX*external_applicable', [
341
-			'mount_id' => $mountId,
342
-			'type' => $type,
343
-			'value' => $value
344
-		], ['mount_id', 'type', 'value']);
345
-	}
346
-
347
-	public function removeApplicable($mountId, $type, $value) {
348
-		$builder = $this->connection->getQueryBuilder();
349
-		$query = $builder->delete('external_applicable')
350
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
351
-			->andWhere($builder->expr()->eq('type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
352
-
353
-		if (is_null($value)) {
354
-			$query = $query->andWhere($builder->expr()->isNull('value'));
355
-		} else {
356
-			$query = $query->andWhere($builder->expr()->eq('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR)));
357
-		}
358
-
359
-		$query->execute();
360
-	}
361
-
362
-	private function getMountsFromQuery(IQueryBuilder $query) {
363
-		$result = $query->execute();
364
-		$mounts = $result->fetchAll();
365
-		$uniqueMounts = [];
366
-		foreach ($mounts as $mount) {
367
-			$id = $mount['mount_id'];
368
-			if (!isset($uniqueMounts[$id])) {
369
-				$uniqueMounts[$id] = $mount;
370
-			}
371
-		}
372
-		$uniqueMounts = array_values($uniqueMounts);
373
-
374
-		$mountIds = array_map(function ($mount) {
375
-			return $mount['mount_id'];
376
-		}, $uniqueMounts);
377
-		$mountIds = array_values(array_unique($mountIds));
378
-
379
-		$applicable = $this->getApplicableForMounts($mountIds);
380
-		$config = $this->getConfigForMounts($mountIds);
381
-		$options = $this->getOptionsForMounts($mountIds);
382
-
383
-		return array_map(function ($mount, $applicable, $config, $options) {
384
-			$mount['type'] = (int)$mount['type'];
385
-			$mount['priority'] = (int)$mount['priority'];
386
-			$mount['applicable'] = $applicable;
387
-			$mount['config'] = $config;
388
-			$mount['options'] = $options;
389
-			return $mount;
390
-		}, $uniqueMounts, $applicable, $config, $options);
391
-	}
392
-
393
-	/**
394
-	 * Get mount options from a table grouped by mount id
395
-	 *
396
-	 * @param string $table
397
-	 * @param string[] $fields
398
-	 * @param int[] $mountIds
399
-	 * @return array [$mountId => [['field1' => $value1, ...], ...], ...]
400
-	 */
401
-	private function selectForMounts($table, array $fields, array $mountIds) {
402
-		if (count($mountIds) === 0) {
403
-			return [];
404
-		}
405
-		$builder = $this->connection->getQueryBuilder();
406
-		$fields[] = 'mount_id';
407
-		$placeHolders = array_map(function ($id) use ($builder) {
408
-			return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT);
409
-		}, $mountIds);
410
-		$query = $builder->select($fields)
411
-			->from($table)
412
-			->where($builder->expr()->in('mount_id', $placeHolders));
413
-		$rows = $query->execute()->fetchAll();
414
-
415
-		$result = [];
416
-		foreach ($mountIds as $mountId) {
417
-			$result[$mountId] = [];
418
-		}
419
-		foreach ($rows as $row) {
420
-			if (isset($row['type'])) {
421
-				$row['type'] = (int)$row['type'];
422
-			}
423
-			$result[$row['mount_id']][] = $row;
424
-		}
425
-		return $result;
426
-	}
427
-
428
-	/**
429
-	 * @param int[] $mountIds
430
-	 * @return array [$id => [['type' => $type, 'value' => $value], ...], ...]
431
-	 */
432
-	public function getApplicableForMounts($mountIds) {
433
-		return $this->selectForMounts('external_applicable', ['type', 'value'], $mountIds);
434
-	}
435
-
436
-	/**
437
-	 * @param int[] $mountIds
438
-	 * @return array [$id => ['key1' => $value1, ...], ...]
439
-	 */
440
-	public function getConfigForMounts($mountIds) {
441
-		$mountConfigs = $this->selectForMounts('external_config', ['key', 'value'], $mountIds);
442
-		return array_map([$this, 'createKeyValueMap'], $mountConfigs);
443
-	}
444
-
445
-	/**
446
-	 * @param int[] $mountIds
447
-	 * @return array [$id => ['key1' => $value1, ...], ...]
448
-	 */
449
-	public function getOptionsForMounts($mountIds) {
450
-		$mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds);
451
-		$optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions);
452
-		return array_map(function (array $options) {
453
-			return array_map(function ($option) {
454
-				return json_decode($option);
455
-			}, $options);
456
-		}, $optionsMap);
457
-	}
458
-
459
-	/**
460
-	 * @param array $keyValuePairs [['key'=>$key, 'value=>$value], ...]
461
-	 * @return array ['key1' => $value1, ...]
462
-	 */
463
-	private function createKeyValueMap(array $keyValuePairs) {
464
-		$decryptedPairts = array_map(function ($pair) {
465
-			if ($pair['key'] === 'password') {
466
-				$pair['value'] = $this->decryptValue($pair['value']);
467
-			}
468
-			return $pair;
469
-		}, $keyValuePairs);
470
-		$keys = array_map(function ($pair) {
471
-			return $pair['key'];
472
-		}, $decryptedPairts);
473
-		$values = array_map(function ($pair) {
474
-			return $pair['value'];
475
-		}, $decryptedPairts);
476
-
477
-		return array_combine($keys, $values);
478
-	}
479
-
480
-	private function encryptValue($value) {
481
-		return $this->crypto->encrypt($value);
482
-	}
483
-
484
-	private function decryptValue($value) {
485
-		try {
486
-			return $this->crypto->decrypt($value);
487
-		} catch (\Exception $e) {
488
-			return $value;
489
-		}
490
-	}
35
+    const MOUNT_TYPE_ADMIN = 1;
36
+    const MOUNT_TYPE_PERSONAl = 2;
37
+
38
+    const APPLICABLE_TYPE_GLOBAL = 1;
39
+    const APPLICABLE_TYPE_GROUP = 2;
40
+    const APPLICABLE_TYPE_USER = 3;
41
+
42
+    /**
43
+     * @var IDBConnection
44
+     */
45
+    private $connection;
46
+
47
+    /**
48
+     * @var ICrypto
49
+     */
50
+    private $crypto;
51
+
52
+    /**
53
+     * DBConfigService constructor.
54
+     *
55
+     * @param IDBConnection $connection
56
+     * @param ICrypto $crypto
57
+     */
58
+    public function __construct(IDBConnection $connection, ICrypto $crypto) {
59
+        $this->connection = $connection;
60
+        $this->crypto = $crypto;
61
+    }
62
+
63
+    /**
64
+     * @param int $mountId
65
+     * @return array
66
+     */
67
+    public function getMountById($mountId) {
68
+        $builder = $this->connection->getQueryBuilder();
69
+        $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
70
+            ->from('external_mounts', 'm')
71
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
72
+        $mounts = $this->getMountsFromQuery($query);
73
+        if (count($mounts) > 0) {
74
+            return $mounts[0];
75
+        } else {
76
+            return null;
77
+        }
78
+    }
79
+
80
+    /**
81
+     * Get all configured mounts
82
+     *
83
+     * @return array
84
+     */
85
+    public function getAllMounts() {
86
+        $builder = $this->connection->getQueryBuilder();
87
+        $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
88
+            ->from('external_mounts');
89
+        return $this->getMountsFromQuery($query);
90
+    }
91
+
92
+    public function getMountsForUser($userId, $groupIds) {
93
+        $builder = $this->connection->getQueryBuilder();
94
+        $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
95
+            ->from('external_mounts', 'm')
96
+            ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
97
+            ->where($builder->expr()->orX(
98
+                $builder->expr()->andX( // global mounts
99
+                    $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)),
100
+                    $builder->expr()->isNull('a.value')
101
+                ),
102
+                $builder->expr()->andX( // mounts for user
103
+                    $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)),
104
+                    $builder->expr()->eq('a.value', $builder->createNamedParameter($userId))
105
+                ),
106
+                $builder->expr()->andX( // mounts for group
107
+                    $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)),
108
+                    $builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY))
109
+                )
110
+            ));
111
+
112
+        return $this->getMountsFromQuery($query);
113
+    }
114
+
115
+    /**
116
+     * Get admin defined mounts
117
+     *
118
+     * @return array
119
+     * @suppress SqlInjectionChecker
120
+     */
121
+    public function getAdminMounts() {
122
+        $builder = $this->connection->getQueryBuilder();
123
+        $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
124
+            ->from('external_mounts')
125
+            ->where($builder->expr()->eq('type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
126
+        return $this->getMountsFromQuery($query);
127
+    }
128
+
129
+    protected function getForQuery(IQueryBuilder $builder, $type, $value) {
130
+        $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
131
+            ->from('external_mounts', 'm')
132
+            ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
133
+            ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
134
+
135
+        if (is_null($value)) {
136
+            $query = $query->andWhere($builder->expr()->isNull('a.value'));
137
+        } else {
138
+            $query = $query->andWhere($builder->expr()->eq('a.value', $builder->createNamedParameter($value)));
139
+        }
140
+
141
+        return $query;
142
+    }
143
+
144
+    /**
145
+     * Get mounts by applicable
146
+     *
147
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
148
+     * @param string|null $value user_id, group_id or null for global mounts
149
+     * @return array
150
+     */
151
+    public function getMountsFor($type, $value) {
152
+        $builder = $this->connection->getQueryBuilder();
153
+        $query = $this->getForQuery($builder, $type, $value);
154
+
155
+        return $this->getMountsFromQuery($query);
156
+    }
157
+
158
+    /**
159
+     * Get admin defined mounts by applicable
160
+     *
161
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
162
+     * @param string|null $value user_id, group_id or null for global mounts
163
+     * @return array
164
+     * @suppress SqlInjectionChecker
165
+     */
166
+    public function getAdminMountsFor($type, $value) {
167
+        $builder = $this->connection->getQueryBuilder();
168
+        $query = $this->getForQuery($builder, $type, $value);
169
+        $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
170
+
171
+        return $this->getMountsFromQuery($query);
172
+    }
173
+
174
+    /**
175
+     * Get admin defined mounts for multiple applicable
176
+     *
177
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
178
+     * @param string[] $values user_ids or group_ids
179
+     * @return array
180
+     * @suppress SqlInjectionChecker
181
+     */
182
+    public function getAdminMountsForMultiple($type, array $values) {
183
+        $builder = $this->connection->getQueryBuilder();
184
+        $params = array_map(function ($value) use ($builder) {
185
+            return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR);
186
+        }, $values);
187
+
188
+        $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
189
+            ->from('external_mounts', 'm')
190
+            ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
191
+            ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)))
192
+            ->andWhere($builder->expr()->in('a.value', $params));
193
+        $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
194
+
195
+        return $this->getMountsFromQuery($query);
196
+    }
197
+
198
+    /**
199
+     * Get user defined mounts by applicable
200
+     *
201
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
202
+     * @param string|null $value user_id, group_id or null for global mounts
203
+     * @return array
204
+     * @suppress SqlInjectionChecker
205
+     */
206
+    public function getUserMountsFor($type, $value) {
207
+        $builder = $this->connection->getQueryBuilder();
208
+        $query = $this->getForQuery($builder, $type, $value);
209
+        $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAl, IQueryBuilder::PARAM_INT)));
210
+
211
+        return $this->getMountsFromQuery($query);
212
+    }
213
+
214
+    /**
215
+     * Add a mount to the database
216
+     *
217
+     * @param string $mountPoint
218
+     * @param string $storageBackend
219
+     * @param string $authBackend
220
+     * @param int $priority
221
+     * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL
222
+     * @return int the id of the new mount
223
+     */
224
+    public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) {
225
+        if (!$priority) {
226
+            $priority = 100;
227
+        }
228
+        $builder = $this->connection->getQueryBuilder();
229
+        $query = $builder->insert('external_mounts')
230
+            ->values([
231
+                'mount_point' => $builder->createNamedParameter($mountPoint, IQueryBuilder::PARAM_STR),
232
+                'storage_backend' => $builder->createNamedParameter($storageBackend, IQueryBuilder::PARAM_STR),
233
+                'auth_backend' => $builder->createNamedParameter($authBackend, IQueryBuilder::PARAM_STR),
234
+                'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT),
235
+                'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)
236
+            ]);
237
+        $query->execute();
238
+        return (int)$this->connection->lastInsertId('*PREFIX*external_mounts');
239
+    }
240
+
241
+    /**
242
+     * Remove a mount from the database
243
+     *
244
+     * @param int $mountId
245
+     */
246
+    public function removeMount($mountId) {
247
+        $builder = $this->connection->getQueryBuilder();
248
+        $query = $builder->delete('external_mounts')
249
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
250
+        $query->execute();
251
+
252
+        $query = $builder->delete('external_applicable')
253
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
254
+        $query->execute();
255
+
256
+        $query = $builder->delete('external_config')
257
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
258
+        $query->execute();
259
+
260
+        $query = $builder->delete('external_options')
261
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
262
+        $query->execute();
263
+    }
264
+
265
+    /**
266
+     * @param int $mountId
267
+     * @param string $newMountPoint
268
+     */
269
+    public function setMountPoint($mountId, $newMountPoint) {
270
+        $builder = $this->connection->getQueryBuilder();
271
+
272
+        $query = $builder->update('external_mounts')
273
+            ->set('mount_point', $builder->createNamedParameter($newMountPoint))
274
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
275
+
276
+        $query->execute();
277
+    }
278
+
279
+    /**
280
+     * @param int $mountId
281
+     * @param string $newAuthBackend
282
+     */
283
+    public function setAuthBackend($mountId, $newAuthBackend) {
284
+        $builder = $this->connection->getQueryBuilder();
285
+
286
+        $query = $builder->update('external_mounts')
287
+            ->set('auth_backend', $builder->createNamedParameter($newAuthBackend))
288
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
289
+
290
+        $query->execute();
291
+    }
292
+
293
+    /**
294
+     * @param int $mountId
295
+     * @param string $key
296
+     * @param string $value
297
+     */
298
+    public function setConfig($mountId, $key, $value) {
299
+        if ($key === 'password') {
300
+            $value = $this->encryptValue($value);
301
+        }
302
+        $count = $this->connection->insertIfNotExist('*PREFIX*external_config', [
303
+            'mount_id' => $mountId,
304
+            'key' => $key,
305
+            'value' => $value
306
+        ], ['mount_id', 'key']);
307
+        if ($count === 0) {
308
+            $builder = $this->connection->getQueryBuilder();
309
+            $query = $builder->update('external_config')
310
+                ->set('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))
311
+                ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
312
+                ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
313
+            $query->execute();
314
+        }
315
+    }
316
+
317
+    /**
318
+     * @param int $mountId
319
+     * @param string $key
320
+     * @param string $value
321
+     */
322
+    public function setOption($mountId, $key, $value) {
323
+
324
+        $count = $this->connection->insertIfNotExist('*PREFIX*external_options', [
325
+            'mount_id' => $mountId,
326
+            'key' => $key,
327
+            'value' => json_encode($value)
328
+        ], ['mount_id', 'key']);
329
+        if ($count === 0) {
330
+            $builder = $this->connection->getQueryBuilder();
331
+            $query = $builder->update('external_options')
332
+                ->set('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR))
333
+                ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
334
+                ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
335
+            $query->execute();
336
+        }
337
+    }
338
+
339
+    public function addApplicable($mountId, $type, $value) {
340
+        $this->connection->insertIfNotExist('*PREFIX*external_applicable', [
341
+            'mount_id' => $mountId,
342
+            'type' => $type,
343
+            'value' => $value
344
+        ], ['mount_id', 'type', 'value']);
345
+    }
346
+
347
+    public function removeApplicable($mountId, $type, $value) {
348
+        $builder = $this->connection->getQueryBuilder();
349
+        $query = $builder->delete('external_applicable')
350
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
351
+            ->andWhere($builder->expr()->eq('type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
352
+
353
+        if (is_null($value)) {
354
+            $query = $query->andWhere($builder->expr()->isNull('value'));
355
+        } else {
356
+            $query = $query->andWhere($builder->expr()->eq('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR)));
357
+        }
358
+
359
+        $query->execute();
360
+    }
361
+
362
+    private function getMountsFromQuery(IQueryBuilder $query) {
363
+        $result = $query->execute();
364
+        $mounts = $result->fetchAll();
365
+        $uniqueMounts = [];
366
+        foreach ($mounts as $mount) {
367
+            $id = $mount['mount_id'];
368
+            if (!isset($uniqueMounts[$id])) {
369
+                $uniqueMounts[$id] = $mount;
370
+            }
371
+        }
372
+        $uniqueMounts = array_values($uniqueMounts);
373
+
374
+        $mountIds = array_map(function ($mount) {
375
+            return $mount['mount_id'];
376
+        }, $uniqueMounts);
377
+        $mountIds = array_values(array_unique($mountIds));
378
+
379
+        $applicable = $this->getApplicableForMounts($mountIds);
380
+        $config = $this->getConfigForMounts($mountIds);
381
+        $options = $this->getOptionsForMounts($mountIds);
382
+
383
+        return array_map(function ($mount, $applicable, $config, $options) {
384
+            $mount['type'] = (int)$mount['type'];
385
+            $mount['priority'] = (int)$mount['priority'];
386
+            $mount['applicable'] = $applicable;
387
+            $mount['config'] = $config;
388
+            $mount['options'] = $options;
389
+            return $mount;
390
+        }, $uniqueMounts, $applicable, $config, $options);
391
+    }
392
+
393
+    /**
394
+     * Get mount options from a table grouped by mount id
395
+     *
396
+     * @param string $table
397
+     * @param string[] $fields
398
+     * @param int[] $mountIds
399
+     * @return array [$mountId => [['field1' => $value1, ...], ...], ...]
400
+     */
401
+    private function selectForMounts($table, array $fields, array $mountIds) {
402
+        if (count($mountIds) === 0) {
403
+            return [];
404
+        }
405
+        $builder = $this->connection->getQueryBuilder();
406
+        $fields[] = 'mount_id';
407
+        $placeHolders = array_map(function ($id) use ($builder) {
408
+            return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT);
409
+        }, $mountIds);
410
+        $query = $builder->select($fields)
411
+            ->from($table)
412
+            ->where($builder->expr()->in('mount_id', $placeHolders));
413
+        $rows = $query->execute()->fetchAll();
414
+
415
+        $result = [];
416
+        foreach ($mountIds as $mountId) {
417
+            $result[$mountId] = [];
418
+        }
419
+        foreach ($rows as $row) {
420
+            if (isset($row['type'])) {
421
+                $row['type'] = (int)$row['type'];
422
+            }
423
+            $result[$row['mount_id']][] = $row;
424
+        }
425
+        return $result;
426
+    }
427
+
428
+    /**
429
+     * @param int[] $mountIds
430
+     * @return array [$id => [['type' => $type, 'value' => $value], ...], ...]
431
+     */
432
+    public function getApplicableForMounts($mountIds) {
433
+        return $this->selectForMounts('external_applicable', ['type', 'value'], $mountIds);
434
+    }
435
+
436
+    /**
437
+     * @param int[] $mountIds
438
+     * @return array [$id => ['key1' => $value1, ...], ...]
439
+     */
440
+    public function getConfigForMounts($mountIds) {
441
+        $mountConfigs = $this->selectForMounts('external_config', ['key', 'value'], $mountIds);
442
+        return array_map([$this, 'createKeyValueMap'], $mountConfigs);
443
+    }
444
+
445
+    /**
446
+     * @param int[] $mountIds
447
+     * @return array [$id => ['key1' => $value1, ...], ...]
448
+     */
449
+    public function getOptionsForMounts($mountIds) {
450
+        $mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds);
451
+        $optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions);
452
+        return array_map(function (array $options) {
453
+            return array_map(function ($option) {
454
+                return json_decode($option);
455
+            }, $options);
456
+        }, $optionsMap);
457
+    }
458
+
459
+    /**
460
+     * @param array $keyValuePairs [['key'=>$key, 'value=>$value], ...]
461
+     * @return array ['key1' => $value1, ...]
462
+     */
463
+    private function createKeyValueMap(array $keyValuePairs) {
464
+        $decryptedPairts = array_map(function ($pair) {
465
+            if ($pair['key'] === 'password') {
466
+                $pair['value'] = $this->decryptValue($pair['value']);
467
+            }
468
+            return $pair;
469
+        }, $keyValuePairs);
470
+        $keys = array_map(function ($pair) {
471
+            return $pair['key'];
472
+        }, $decryptedPairts);
473
+        $values = array_map(function ($pair) {
474
+            return $pair['value'];
475
+        }, $decryptedPairts);
476
+
477
+        return array_combine($keys, $values);
478
+    }
479
+
480
+    private function encryptValue($value) {
481
+        return $this->crypto->encrypt($value);
482
+    }
483
+
484
+    private function decryptValue($value) {
485
+        try {
486
+            return $this->crypto->decrypt($value);
487
+        } catch (\Exception $e) {
488
+            return $value;
489
+        }
490
+    }
491 491
 }
Please login to merge, or discard this patch.
lib/private/AppFramework/OCS/BaseResponse.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 	/**
25 25
 	 * BaseResponse constructor.
26 26
 	 *
27
-	 * @param DataResponse|null $dataResponse
27
+	 * @param DataResponse $dataResponse
28 28
 	 * @param string $format
29 29
 	 * @param string|null $statusMessage
30 30
 	 * @param int|null $itemsCount
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -27,70 +27,70 @@
 block discarded – undo
27 27
 use OCP\AppFramework\Http\Response;
28 28
 
29 29
 abstract class BaseResponse extends Response   {
30
-	/** @var array */
31
-	protected $data;
30
+    /** @var array */
31
+    protected $data;
32 32
 
33
-	/** @var string */
34
-	protected $format;
33
+    /** @var string */
34
+    protected $format;
35 35
 
36
-	/** @var string */
37
-	protected $statusMessage;
36
+    /** @var string */
37
+    protected $statusMessage;
38 38
 
39
-	/** @var int */
40
-	protected $itemsCount;
39
+    /** @var int */
40
+    protected $itemsCount;
41 41
 
42
-	/** @var int */
43
-	protected $itemsPerPage;
42
+    /** @var int */
43
+    protected $itemsPerPage;
44 44
 
45
-	/**
46
-	 * BaseResponse constructor.
47
-	 *
48
-	 * @param DataResponse|null $dataResponse
49
-	 * @param string $format
50
-	 * @param string|null $statusMessage
51
-	 * @param int|null $itemsCount
52
-	 * @param int|null $itemsPerPage
53
-	 */
54
-	public function __construct(DataResponse $dataResponse,
55
-								$format = 'xml',
56
-								$statusMessage = null,
57
-								$itemsCount = null,
58
-								$itemsPerPage = null) {
59
-		$this->format = $format;
60
-		$this->statusMessage = $statusMessage;
61
-		$this->itemsCount = $itemsCount;
62
-		$this->itemsPerPage = $itemsPerPage;
45
+    /**
46
+     * BaseResponse constructor.
47
+     *
48
+     * @param DataResponse|null $dataResponse
49
+     * @param string $format
50
+     * @param string|null $statusMessage
51
+     * @param int|null $itemsCount
52
+     * @param int|null $itemsPerPage
53
+     */
54
+    public function __construct(DataResponse $dataResponse,
55
+                                $format = 'xml',
56
+                                $statusMessage = null,
57
+                                $itemsCount = null,
58
+                                $itemsPerPage = null) {
59
+        $this->format = $format;
60
+        $this->statusMessage = $statusMessage;
61
+        $this->itemsCount = $itemsCount;
62
+        $this->itemsPerPage = $itemsPerPage;
63 63
 
64
-		$this->data = $dataResponse->getData();
64
+        $this->data = $dataResponse->getData();
65 65
 
66
-		$this->setHeaders($dataResponse->getHeaders());
67
-		$this->setStatus($dataResponse->getStatus());
68
-		$this->setETag($dataResponse->getETag());
69
-		$this->setLastModified($dataResponse->getLastModified());
70
-		$this->setCookies($dataResponse->getCookies());
71
-		$this->setContentSecurityPolicy(new EmptyContentSecurityPolicy());
66
+        $this->setHeaders($dataResponse->getHeaders());
67
+        $this->setStatus($dataResponse->getStatus());
68
+        $this->setETag($dataResponse->getETag());
69
+        $this->setLastModified($dataResponse->getLastModified());
70
+        $this->setCookies($dataResponse->getCookies());
71
+        $this->setContentSecurityPolicy(new EmptyContentSecurityPolicy());
72 72
 
73
-		if ($format === 'json') {
74
-			$this->addHeader(
75
-				'Content-Type', 'application/json; charset=utf-8'
76
-			);
77
-		} else {
78
-			$this->addHeader(
79
-				'Content-Type', 'application/xml; charset=utf-8'
80
-			);
81
-		}
82
-	}
73
+        if ($format === 'json') {
74
+            $this->addHeader(
75
+                'Content-Type', 'application/json; charset=utf-8'
76
+            );
77
+        } else {
78
+            $this->addHeader(
79
+                'Content-Type', 'application/xml; charset=utf-8'
80
+            );
81
+        }
82
+    }
83 83
 
84
-	/**
85
-	 * @param string[] $meta
86
-	 * @return string
87
-	 */
88
-	protected function renderResult($meta) {
89
-		// TODO rewrite functions
90
-		return \OC_API::renderResult($this->format, $meta, $this->data);
91
-	}
84
+    /**
85
+     * @param string[] $meta
86
+     * @return string
87
+     */
88
+    protected function renderResult($meta) {
89
+        // TODO rewrite functions
90
+        return \OC_API::renderResult($this->format, $meta, $this->data);
91
+    }
92 92
 
93
-	public function getOCSStatus() {
94
-		return parent::getStatus();
95
-	}
93
+    public function getOCSStatus() {
94
+        return parent::getStatus();
95
+    }
96 96
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
 use OCP\AppFramework\Http\EmptyContentSecurityPolicy;
27 27
 use OCP\AppFramework\Http\Response;
28 28
 
29
-abstract class BaseResponse extends Response   {
29
+abstract class BaseResponse extends Response {
30 30
 	/** @var array */
31 31
 	protected $data;
32 32
 
Please login to merge, or discard this patch.
lib/private/Server.php 4 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1143,7 +1143,7 @@  discard block
 block discarded – undo
1143 1143
 	 * Get the certificate manager for the user
1144 1144
 	 *
1145 1145
 	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1146
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1146
+	 * @return null|CertificateManager | null if $uid is null and no user is logged in
1147 1147
 	 */
1148 1148
 	public function getCertificateManager($userId = '') {
1149 1149
 		if ($userId === '') {
@@ -1464,6 +1464,7 @@  discard block
 block discarded – undo
1464 1464
 	}
1465 1465
 
1466 1466
 	/**
1467
+	 * @param string $app
1467 1468
 	 * @return \OCP\Files\IAppData
1468 1469
 	 */
1469 1470
 	public function getAppDataDir($app) {
Please login to merge, or discard this patch.
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -52,8 +52,6 @@  discard block
 block discarded – undo
52 52
 use OC\Command\AsyncBus;
53 53
 use OC\Contacts\ContactsMenu\ActionFactory;
54 54
 use OC\Diagnostics\EventLogger;
55
-use OC\Diagnostics\NullEventLogger;
56
-use OC\Diagnostics\NullQueryLogger;
57 55
 use OC\Diagnostics\QueryLogger;
58 56
 use OC\Federation\CloudIdManager;
59 57
 use OC\Files\Config\UserMountCache;
@@ -98,7 +96,6 @@  discard block
 block discarded – undo
98 96
 use OC\Tagging\TagMapper;
99 97
 use OC\Template\SCSSCacher;
100 98
 use OCA\Theming\ThemingDefaults;
101
-
102 99
 use OCP\App\IAppManager;
103 100
 use OCP\Defaults;
104 101
 use OCA\Theming\Util;
Please login to merge, or discard this patch.
Indentation   +1660 added lines, -1660 removed lines patch added patch discarded remove patch
@@ -128,1669 +128,1669 @@
 block discarded – undo
128 128
  * TODO: hookup all manager classes
129 129
  */
130 130
 class Server extends ServerContainer implements IServerContainer {
131
-	/** @var string */
132
-	private $webRoot;
133
-
134
-	/**
135
-	 * @param string $webRoot
136
-	 * @param \OC\Config $config
137
-	 */
138
-	public function __construct($webRoot, \OC\Config $config) {
139
-		parent::__construct();
140
-		$this->webRoot = $webRoot;
141
-
142
-		$this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) {
143
-			return $c;
144
-		});
145
-
146
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
147
-		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
148
-
149
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
150
-
151
-
152
-
153
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
154
-			return new PreviewManager(
155
-				$c->getConfig(),
156
-				$c->getRootFolder(),
157
-				$c->getAppDataDir('preview'),
158
-				$c->getEventDispatcher(),
159
-				$c->getSession()->get('user_id')
160
-			);
161
-		});
162
-		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
163
-
164
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
165
-			return new \OC\Preview\Watcher(
166
-				$c->getAppDataDir('preview')
167
-			);
168
-		});
169
-
170
-		$this->registerService('EncryptionManager', function (Server $c) {
171
-			$view = new View();
172
-			$util = new Encryption\Util(
173
-				$view,
174
-				$c->getUserManager(),
175
-				$c->getGroupManager(),
176
-				$c->getConfig()
177
-			);
178
-			return new Encryption\Manager(
179
-				$c->getConfig(),
180
-				$c->getLogger(),
181
-				$c->getL10N('core'),
182
-				new View(),
183
-				$util,
184
-				new ArrayCache()
185
-			);
186
-		});
187
-
188
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
189
-			$util = new Encryption\Util(
190
-				new View(),
191
-				$c->getUserManager(),
192
-				$c->getGroupManager(),
193
-				$c->getConfig()
194
-			);
195
-			return new Encryption\File(
196
-				$util,
197
-				$c->getRootFolder(),
198
-				$c->getShareManager()
199
-			);
200
-		});
201
-
202
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
203
-			$view = new View();
204
-			$util = new Encryption\Util(
205
-				$view,
206
-				$c->getUserManager(),
207
-				$c->getGroupManager(),
208
-				$c->getConfig()
209
-			);
210
-
211
-			return new Encryption\Keys\Storage($view, $util);
212
-		});
213
-		$this->registerService('TagMapper', function (Server $c) {
214
-			return new TagMapper($c->getDatabaseConnection());
215
-		});
216
-
217
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
218
-			$tagMapper = $c->query('TagMapper');
219
-			return new TagManager($tagMapper, $c->getUserSession());
220
-		});
221
-		$this->registerAlias('TagManager', \OCP\ITagManager::class);
222
-
223
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
224
-			$config = $c->getConfig();
225
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
226
-			/** @var \OC\SystemTag\ManagerFactory $factory */
227
-			$factory = new $factoryClass($this);
228
-			return $factory;
229
-		});
230
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
231
-			return $c->query('SystemTagManagerFactory')->getManager();
232
-		});
233
-		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
234
-
235
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
236
-			return $c->query('SystemTagManagerFactory')->getObjectMapper();
237
-		});
238
-		$this->registerService('RootFolder', function (Server $c) {
239
-			$manager = \OC\Files\Filesystem::getMountManager(null);
240
-			$view = new View();
241
-			$root = new Root(
242
-				$manager,
243
-				$view,
244
-				null,
245
-				$c->getUserMountCache(),
246
-				$this->getLogger(),
247
-				$this->getUserManager()
248
-			);
249
-			$connector = new HookConnector($root, $view);
250
-			$connector->viewToNode();
251
-
252
-			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
253
-			$previewConnector->connectWatcher();
254
-
255
-			return $root;
256
-		});
257
-		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
258
-
259
-		$this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) {
260
-			return new LazyRoot(function() use ($c) {
261
-				return $c->query('RootFolder');
262
-			});
263
-		});
264
-		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
265
-
266
-		$this->registerService(\OCP\IUserManager::class, function (Server $c) {
267
-			$config = $c->getConfig();
268
-			return new \OC\User\Manager($config);
269
-		});
270
-		$this->registerAlias('UserManager', \OCP\IUserManager::class);
271
-
272
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
273
-			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
274
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
275
-				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
276
-			});
277
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
278
-				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
279
-			});
280
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
281
-				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
282
-			});
283
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
284
-				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
285
-			});
286
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
287
-				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
288
-			});
289
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
290
-				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
291
-				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
292
-				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
293
-			});
294
-			return $groupManager;
295
-		});
296
-		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
297
-
298
-		$this->registerService(Store::class, function(Server $c) {
299
-			$session = $c->getSession();
300
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
301
-				$tokenProvider = $c->query('OC\Authentication\Token\IProvider');
302
-			} else {
303
-				$tokenProvider = null;
304
-			}
305
-			$logger = $c->getLogger();
306
-			return new Store($session, $logger, $tokenProvider);
307
-		});
308
-		$this->registerAlias(IStore::class, Store::class);
309
-		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
310
-			$dbConnection = $c->getDatabaseConnection();
311
-			return new Authentication\Token\DefaultTokenMapper($dbConnection);
312
-		});
313
-		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
314
-			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
315
-			$crypto = $c->getCrypto();
316
-			$config = $c->getConfig();
317
-			$logger = $c->getLogger();
318
-			$timeFactory = new TimeFactory();
319
-			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
320
-		});
321
-		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
322
-
323
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
324
-			$manager = $c->getUserManager();
325
-			$session = new \OC\Session\Memory('');
326
-			$timeFactory = new TimeFactory();
327
-			// Token providers might require a working database. This code
328
-			// might however be called when ownCloud is not yet setup.
329
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
330
-				$defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
331
-			} else {
332
-				$defaultTokenProvider = null;
333
-			}
334
-
335
-			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
336
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
337
-				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
338
-			});
339
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
340
-				/** @var $user \OC\User\User */
341
-				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
342
-			});
343
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
344
-				/** @var $user \OC\User\User */
345
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
346
-			});
347
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
348
-				/** @var $user \OC\User\User */
349
-				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
350
-			});
351
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
352
-				/** @var $user \OC\User\User */
353
-				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
354
-			});
355
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
356
-				/** @var $user \OC\User\User */
357
-				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
358
-			});
359
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
360
-				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
361
-			});
362
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
363
-				/** @var $user \OC\User\User */
364
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
365
-			});
366
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
367
-				/** @var $user \OC\User\User */
368
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
369
-			});
370
-			$userSession->listen('\OC\User', 'logout', function () {
371
-				\OC_Hook::emit('OC_User', 'logout', array());
372
-			});
373
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
374
-				/** @var $user \OC\User\User */
375
-				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
376
-			});
377
-			return $userSession;
378
-		});
379
-		$this->registerAlias('UserSession', \OCP\IUserSession::class);
380
-
381
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
382
-			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
383
-		});
384
-
385
-		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
386
-		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
387
-
388
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
389
-			return new \OC\AllConfig(
390
-				$c->getSystemConfig()
391
-			);
392
-		});
393
-		$this->registerAlias('AllConfig', \OC\AllConfig::class);
394
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
395
-
396
-		$this->registerService('SystemConfig', function ($c) use ($config) {
397
-			return new \OC\SystemConfig($config);
398
-		});
399
-
400
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
401
-			return new \OC\AppConfig($c->getDatabaseConnection());
402
-		});
403
-		$this->registerAlias('AppConfig', \OC\AppConfig::class);
404
-		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
405
-
406
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
407
-			return new \OC\L10N\Factory(
408
-				$c->getConfig(),
409
-				$c->getRequest(),
410
-				$c->getUserSession(),
411
-				\OC::$SERVERROOT
412
-			);
413
-		});
414
-		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
415
-
416
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
417
-			$config = $c->getConfig();
418
-			$cacheFactory = $c->getMemCacheFactory();
419
-			$request = $c->getRequest();
420
-			return new \OC\URLGenerator(
421
-				$config,
422
-				$cacheFactory,
423
-				$request
424
-			);
425
-		});
426
-		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
427
-
428
-		$this->registerService('AppHelper', function ($c) {
429
-			return new \OC\AppHelper();
430
-		});
431
-		$this->registerAlias('AppFetcher', AppFetcher::class);
432
-		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
433
-
434
-		$this->registerService(\OCP\ICache::class, function ($c) {
435
-			return new Cache\File();
436
-		});
437
-		$this->registerAlias('UserCache', \OCP\ICache::class);
438
-
439
-		$this->registerService(Factory::class, function (Server $c) {
440
-
441
-			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
442
-				'\\OC\\Memcache\\ArrayCache',
443
-				'\\OC\\Memcache\\ArrayCache',
444
-				'\\OC\\Memcache\\ArrayCache'
445
-			);
446
-			$config = $c->getConfig();
447
-			$request = $c->getRequest();
448
-			$urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
449
-
450
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
451
-				$v = \OC_App::getAppVersions();
452
-				$v['core'] = implode(',', \OC_Util::getVersion());
453
-				$version = implode(',', $v);
454
-				$instanceId = \OC_Util::getInstanceId();
455
-				$path = \OC::$SERVERROOT;
456
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl());
457
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
458
-					$config->getSystemValue('memcache.local', null),
459
-					$config->getSystemValue('memcache.distributed', null),
460
-					$config->getSystemValue('memcache.locking', null)
461
-				);
462
-			}
463
-			return $arrayCacheFactory;
464
-
465
-		});
466
-		$this->registerAlias('MemCacheFactory', Factory::class);
467
-		$this->registerAlias(ICacheFactory::class, Factory::class);
468
-
469
-		$this->registerService('RedisFactory', function (Server $c) {
470
-			$systemConfig = $c->getSystemConfig();
471
-			return new RedisFactory($systemConfig);
472
-		});
473
-
474
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
475
-			return new \OC\Activity\Manager(
476
-				$c->getRequest(),
477
-				$c->getUserSession(),
478
-				$c->getConfig(),
479
-				$c->query(IValidator::class)
480
-			);
481
-		});
482
-		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
483
-
484
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
485
-			return new \OC\Activity\EventMerger(
486
-				$c->getL10N('lib')
487
-			);
488
-		});
489
-		$this->registerAlias(IValidator::class, Validator::class);
490
-
491
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
492
-			return new AvatarManager(
493
-				$c->getUserManager(),
494
-				$c->getAppDataDir('avatar'),
495
-				$c->getL10N('lib'),
496
-				$c->getLogger(),
497
-				$c->getConfig()
498
-			);
499
-		});
500
-		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
501
-
502
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
503
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
504
-			$logger = Log::getLogClass($logType);
505
-			call_user_func(array($logger, 'init'));
506
-
507
-			return new Log($logger);
508
-		});
509
-		$this->registerAlias('Logger', \OCP\ILogger::class);
510
-
511
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
512
-			$config = $c->getConfig();
513
-			return new \OC\BackgroundJob\JobList(
514
-				$c->getDatabaseConnection(),
515
-				$config,
516
-				new TimeFactory()
517
-			);
518
-		});
519
-		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
520
-
521
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
522
-			$cacheFactory = $c->getMemCacheFactory();
523
-			$logger = $c->getLogger();
524
-			if ($cacheFactory->isAvailable()) {
525
-				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
526
-			} else {
527
-				$router = new \OC\Route\Router($logger);
528
-			}
529
-			return $router;
530
-		});
531
-		$this->registerAlias('Router', \OCP\Route\IRouter::class);
532
-
533
-		$this->registerService(\OCP\ISearch::class, function ($c) {
534
-			return new Search();
535
-		});
536
-		$this->registerAlias('Search', \OCP\ISearch::class);
537
-
538
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) {
539
-			return new \OC\Security\RateLimiting\Limiter(
540
-				$this->getUserSession(),
541
-				$this->getRequest(),
542
-				new \OC\AppFramework\Utility\TimeFactory(),
543
-				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
544
-			);
545
-		});
546
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
547
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
548
-				$this->getMemCacheFactory(),
549
-				new \OC\AppFramework\Utility\TimeFactory()
550
-			);
551
-		});
552
-
553
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
554
-			return new SecureRandom();
555
-		});
556
-		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
557
-
558
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
559
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
560
-		});
561
-		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
562
-
563
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
564
-			return new Hasher($c->getConfig());
565
-		});
566
-		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
567
-
568
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
569
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
570
-		});
571
-		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
572
-
573
-		$this->registerService(IDBConnection::class, function (Server $c) {
574
-			$systemConfig = $c->getSystemConfig();
575
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
576
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
577
-			if (!$factory->isValidType($type)) {
578
-				throw new \OC\DatabaseException('Invalid database type');
579
-			}
580
-			$connectionParams = $factory->createConnectionParams();
581
-			$connection = $factory->getConnection($type, $connectionParams);
582
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
583
-			return $connection;
584
-		});
585
-		$this->registerAlias('DatabaseConnection', IDBConnection::class);
586
-
587
-		$this->registerService('HTTPHelper', function (Server $c) {
588
-			$config = $c->getConfig();
589
-			return new HTTPHelper(
590
-				$config,
591
-				$c->getHTTPClientService()
592
-			);
593
-		});
594
-
595
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
596
-			$user = \OC_User::getUser();
597
-			$uid = $user ? $user : null;
598
-			return new ClientService(
599
-				$c->getConfig(),
600
-				new \OC\Security\CertificateManager(
601
-					$uid,
602
-					new View(),
603
-					$c->getConfig(),
604
-					$c->getLogger(),
605
-					$c->getSecureRandom()
606
-				)
607
-			);
608
-		});
609
-		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
610
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
611
-			$eventLogger = new EventLogger();
612
-			if ($c->getSystemConfig()->getValue('debug', false)) {
613
-				// In debug mode, module is being activated by default
614
-				$eventLogger->activate();
615
-			}
616
-			return $eventLogger;
617
-		});
618
-		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
619
-
620
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
621
-			$queryLogger = new QueryLogger();
622
-			if ($c->getSystemConfig()->getValue('debug', false)) {
623
-				// In debug mode, module is being activated by default
624
-				$queryLogger->activate();
625
-			}
626
-			return $queryLogger;
627
-		});
628
-		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
629
-
630
-		$this->registerService(TempManager::class, function (Server $c) {
631
-			return new TempManager(
632
-				$c->getLogger(),
633
-				$c->getConfig()
634
-			);
635
-		});
636
-		$this->registerAlias('TempManager', TempManager::class);
637
-		$this->registerAlias(ITempManager::class, TempManager::class);
638
-
639
-		$this->registerService(AppManager::class, function (Server $c) {
640
-			return new \OC\App\AppManager(
641
-				$c->getUserSession(),
642
-				$c->getAppConfig(),
643
-				$c->getGroupManager(),
644
-				$c->getMemCacheFactory(),
645
-				$c->getEventDispatcher()
646
-			);
647
-		});
648
-		$this->registerAlias('AppManager', AppManager::class);
649
-		$this->registerAlias(IAppManager::class, AppManager::class);
650
-
651
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
652
-			return new DateTimeZone(
653
-				$c->getConfig(),
654
-				$c->getSession()
655
-			);
656
-		});
657
-		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
658
-
659
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
660
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
661
-
662
-			return new DateTimeFormatter(
663
-				$c->getDateTimeZone()->getTimeZone(),
664
-				$c->getL10N('lib', $language)
665
-			);
666
-		});
667
-		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
668
-
669
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
670
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
671
-			$listener = new UserMountCacheListener($mountCache);
672
-			$listener->listen($c->getUserManager());
673
-			return $mountCache;
674
-		});
675
-		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
676
-
677
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
678
-			$loader = \OC\Files\Filesystem::getLoader();
679
-			$mountCache = $c->query('UserMountCache');
680
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
681
-
682
-			// builtin providers
683
-
684
-			$config = $c->getConfig();
685
-			$manager->registerProvider(new CacheMountProvider($config));
686
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
687
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
688
-
689
-			return $manager;
690
-		});
691
-		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
692
-
693
-		$this->registerService('IniWrapper', function ($c) {
694
-			return new IniGetWrapper();
695
-		});
696
-		$this->registerService('AsyncCommandBus', function (Server $c) {
697
-			$jobList = $c->getJobList();
698
-			return new AsyncBus($jobList);
699
-		});
700
-		$this->registerService('TrustedDomainHelper', function ($c) {
701
-			return new TrustedDomainHelper($this->getConfig());
702
-		});
703
-		$this->registerService('Throttler', function(Server $c) {
704
-			return new Throttler(
705
-				$c->getDatabaseConnection(),
706
-				new TimeFactory(),
707
-				$c->getLogger(),
708
-				$c->getConfig()
709
-			);
710
-		});
711
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
712
-			// IConfig and IAppManager requires a working database. This code
713
-			// might however be called when ownCloud is not yet setup.
714
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
715
-				$config = $c->getConfig();
716
-				$appManager = $c->getAppManager();
717
-			} else {
718
-				$config = null;
719
-				$appManager = null;
720
-			}
721
-
722
-			return new Checker(
723
-					new EnvironmentHelper(),
724
-					new FileAccessHelper(),
725
-					new AppLocator(),
726
-					$config,
727
-					$c->getMemCacheFactory(),
728
-					$appManager,
729
-					$c->getTempManager()
730
-			);
731
-		});
732
-		$this->registerService(\OCP\IRequest::class, function ($c) {
733
-			if (isset($this['urlParams'])) {
734
-				$urlParams = $this['urlParams'];
735
-			} else {
736
-				$urlParams = [];
737
-			}
738
-
739
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
740
-				&& in_array('fakeinput', stream_get_wrappers())
741
-			) {
742
-				$stream = 'fakeinput://data';
743
-			} else {
744
-				$stream = 'php://input';
745
-			}
746
-
747
-			return new Request(
748
-				[
749
-					'get' => $_GET,
750
-					'post' => $_POST,
751
-					'files' => $_FILES,
752
-					'server' => $_SERVER,
753
-					'env' => $_ENV,
754
-					'cookies' => $_COOKIE,
755
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
756
-						? $_SERVER['REQUEST_METHOD']
757
-						: null,
758
-					'urlParams' => $urlParams,
759
-				],
760
-				$this->getSecureRandom(),
761
-				$this->getConfig(),
762
-				$this->getCsrfTokenManager(),
763
-				$stream
764
-			);
765
-		});
766
-		$this->registerAlias('Request', \OCP\IRequest::class);
767
-
768
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
769
-			return new Mailer(
770
-				$c->getConfig(),
771
-				$c->getLogger(),
772
-				$c->query(Defaults::class),
773
-				$c->getURLGenerator(),
774
-				$c->getL10N('lib')
775
-			);
776
-		});
777
-		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
778
-
779
-		$this->registerService('LDAPProvider', function(Server $c) {
780
-			$config = $c->getConfig();
781
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
782
-			if(is_null($factoryClass)) {
783
-				throw new \Exception('ldapProviderFactory not set');
784
-			}
785
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
786
-			$factory = new $factoryClass($this);
787
-			return $factory->getLDAPProvider();
788
-		});
789
-		$this->registerService(ILockingProvider::class, function (Server $c) {
790
-			$ini = $c->getIniWrapper();
791
-			$config = $c->getConfig();
792
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
793
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
794
-				/** @var \OC\Memcache\Factory $memcacheFactory */
795
-				$memcacheFactory = $c->getMemCacheFactory();
796
-				$memcache = $memcacheFactory->createLocking('lock');
797
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
798
-					return new MemcacheLockingProvider($memcache, $ttl);
799
-				}
800
-				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
801
-			}
802
-			return new NoopLockingProvider();
803
-		});
804
-		$this->registerAlias('LockingProvider', ILockingProvider::class);
805
-
806
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
807
-			return new \OC\Files\Mount\Manager();
808
-		});
809
-		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
810
-
811
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
812
-			return new \OC\Files\Type\Detection(
813
-				$c->getURLGenerator(),
814
-				\OC::$configDir,
815
-				\OC::$SERVERROOT . '/resources/config/'
816
-			);
817
-		});
818
-		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
819
-
820
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
821
-			return new \OC\Files\Type\Loader(
822
-				$c->getDatabaseConnection()
823
-			);
824
-		});
825
-		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
826
-		$this->registerService(BundleFetcher::class, function () {
827
-			return new BundleFetcher($this->getL10N('lib'));
828
-		});
829
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
830
-			return new Manager(
831
-				$c->query(IValidator::class)
832
-			);
833
-		});
834
-		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
835
-
836
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
837
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
838
-			$manager->registerCapability(function () use ($c) {
839
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
840
-			});
841
-			$manager->registerCapability(function () use ($c) {
842
-				return $c->query(\OC\Security\Bruteforce\Capabilities::class);
843
-			});
844
-			return $manager;
845
-		});
846
-		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
847
-
848
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
849
-			$config = $c->getConfig();
850
-			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
851
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
852
-			$factory = new $factoryClass($this);
853
-			return $factory->getManager();
854
-		});
855
-		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
856
-
857
-		$this->registerService('ThemingDefaults', function(Server $c) {
858
-			/*
131
+    /** @var string */
132
+    private $webRoot;
133
+
134
+    /**
135
+     * @param string $webRoot
136
+     * @param \OC\Config $config
137
+     */
138
+    public function __construct($webRoot, \OC\Config $config) {
139
+        parent::__construct();
140
+        $this->webRoot = $webRoot;
141
+
142
+        $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) {
143
+            return $c;
144
+        });
145
+
146
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
147
+        $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
148
+
149
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
150
+
151
+
152
+
153
+        $this->registerService(\OCP\IPreview::class, function (Server $c) {
154
+            return new PreviewManager(
155
+                $c->getConfig(),
156
+                $c->getRootFolder(),
157
+                $c->getAppDataDir('preview'),
158
+                $c->getEventDispatcher(),
159
+                $c->getSession()->get('user_id')
160
+            );
161
+        });
162
+        $this->registerAlias('PreviewManager', \OCP\IPreview::class);
163
+
164
+        $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
165
+            return new \OC\Preview\Watcher(
166
+                $c->getAppDataDir('preview')
167
+            );
168
+        });
169
+
170
+        $this->registerService('EncryptionManager', function (Server $c) {
171
+            $view = new View();
172
+            $util = new Encryption\Util(
173
+                $view,
174
+                $c->getUserManager(),
175
+                $c->getGroupManager(),
176
+                $c->getConfig()
177
+            );
178
+            return new Encryption\Manager(
179
+                $c->getConfig(),
180
+                $c->getLogger(),
181
+                $c->getL10N('core'),
182
+                new View(),
183
+                $util,
184
+                new ArrayCache()
185
+            );
186
+        });
187
+
188
+        $this->registerService('EncryptionFileHelper', function (Server $c) {
189
+            $util = new Encryption\Util(
190
+                new View(),
191
+                $c->getUserManager(),
192
+                $c->getGroupManager(),
193
+                $c->getConfig()
194
+            );
195
+            return new Encryption\File(
196
+                $util,
197
+                $c->getRootFolder(),
198
+                $c->getShareManager()
199
+            );
200
+        });
201
+
202
+        $this->registerService('EncryptionKeyStorage', function (Server $c) {
203
+            $view = new View();
204
+            $util = new Encryption\Util(
205
+                $view,
206
+                $c->getUserManager(),
207
+                $c->getGroupManager(),
208
+                $c->getConfig()
209
+            );
210
+
211
+            return new Encryption\Keys\Storage($view, $util);
212
+        });
213
+        $this->registerService('TagMapper', function (Server $c) {
214
+            return new TagMapper($c->getDatabaseConnection());
215
+        });
216
+
217
+        $this->registerService(\OCP\ITagManager::class, function (Server $c) {
218
+            $tagMapper = $c->query('TagMapper');
219
+            return new TagManager($tagMapper, $c->getUserSession());
220
+        });
221
+        $this->registerAlias('TagManager', \OCP\ITagManager::class);
222
+
223
+        $this->registerService('SystemTagManagerFactory', function (Server $c) {
224
+            $config = $c->getConfig();
225
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
226
+            /** @var \OC\SystemTag\ManagerFactory $factory */
227
+            $factory = new $factoryClass($this);
228
+            return $factory;
229
+        });
230
+        $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
231
+            return $c->query('SystemTagManagerFactory')->getManager();
232
+        });
233
+        $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
234
+
235
+        $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
236
+            return $c->query('SystemTagManagerFactory')->getObjectMapper();
237
+        });
238
+        $this->registerService('RootFolder', function (Server $c) {
239
+            $manager = \OC\Files\Filesystem::getMountManager(null);
240
+            $view = new View();
241
+            $root = new Root(
242
+                $manager,
243
+                $view,
244
+                null,
245
+                $c->getUserMountCache(),
246
+                $this->getLogger(),
247
+                $this->getUserManager()
248
+            );
249
+            $connector = new HookConnector($root, $view);
250
+            $connector->viewToNode();
251
+
252
+            $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
253
+            $previewConnector->connectWatcher();
254
+
255
+            return $root;
256
+        });
257
+        $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
258
+
259
+        $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) {
260
+            return new LazyRoot(function() use ($c) {
261
+                return $c->query('RootFolder');
262
+            });
263
+        });
264
+        $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
265
+
266
+        $this->registerService(\OCP\IUserManager::class, function (Server $c) {
267
+            $config = $c->getConfig();
268
+            return new \OC\User\Manager($config);
269
+        });
270
+        $this->registerAlias('UserManager', \OCP\IUserManager::class);
271
+
272
+        $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
273
+            $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
274
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
275
+                \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
276
+            });
277
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
278
+                \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
279
+            });
280
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
281
+                \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
282
+            });
283
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
284
+                \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
285
+            });
286
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
287
+                \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
288
+            });
289
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
290
+                \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
291
+                //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
292
+                \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
293
+            });
294
+            return $groupManager;
295
+        });
296
+        $this->registerAlias('GroupManager', \OCP\IGroupManager::class);
297
+
298
+        $this->registerService(Store::class, function(Server $c) {
299
+            $session = $c->getSession();
300
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
301
+                $tokenProvider = $c->query('OC\Authentication\Token\IProvider');
302
+            } else {
303
+                $tokenProvider = null;
304
+            }
305
+            $logger = $c->getLogger();
306
+            return new Store($session, $logger, $tokenProvider);
307
+        });
308
+        $this->registerAlias(IStore::class, Store::class);
309
+        $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
310
+            $dbConnection = $c->getDatabaseConnection();
311
+            return new Authentication\Token\DefaultTokenMapper($dbConnection);
312
+        });
313
+        $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
314
+            $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
315
+            $crypto = $c->getCrypto();
316
+            $config = $c->getConfig();
317
+            $logger = $c->getLogger();
318
+            $timeFactory = new TimeFactory();
319
+            return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
320
+        });
321
+        $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
322
+
323
+        $this->registerService(\OCP\IUserSession::class, function (Server $c) {
324
+            $manager = $c->getUserManager();
325
+            $session = new \OC\Session\Memory('');
326
+            $timeFactory = new TimeFactory();
327
+            // Token providers might require a working database. This code
328
+            // might however be called when ownCloud is not yet setup.
329
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
330
+                $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
331
+            } else {
332
+                $defaultTokenProvider = null;
333
+            }
334
+
335
+            $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
336
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
337
+                \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
338
+            });
339
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
340
+                /** @var $user \OC\User\User */
341
+                \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
342
+            });
343
+            $userSession->listen('\OC\User', 'preDelete', function ($user) {
344
+                /** @var $user \OC\User\User */
345
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
346
+            });
347
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
348
+                /** @var $user \OC\User\User */
349
+                \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
350
+            });
351
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
352
+                /** @var $user \OC\User\User */
353
+                \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
354
+            });
355
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
356
+                /** @var $user \OC\User\User */
357
+                \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
358
+            });
359
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
360
+                \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
361
+            });
362
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
363
+                /** @var $user \OC\User\User */
364
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
365
+            });
366
+            $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
367
+                /** @var $user \OC\User\User */
368
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
369
+            });
370
+            $userSession->listen('\OC\User', 'logout', function () {
371
+                \OC_Hook::emit('OC_User', 'logout', array());
372
+            });
373
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
374
+                /** @var $user \OC\User\User */
375
+                \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
376
+            });
377
+            return $userSession;
378
+        });
379
+        $this->registerAlias('UserSession', \OCP\IUserSession::class);
380
+
381
+        $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
382
+            return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
383
+        });
384
+
385
+        $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
386
+        $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
387
+
388
+        $this->registerService(\OC\AllConfig::class, function (Server $c) {
389
+            return new \OC\AllConfig(
390
+                $c->getSystemConfig()
391
+            );
392
+        });
393
+        $this->registerAlias('AllConfig', \OC\AllConfig::class);
394
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
395
+
396
+        $this->registerService('SystemConfig', function ($c) use ($config) {
397
+            return new \OC\SystemConfig($config);
398
+        });
399
+
400
+        $this->registerService(\OC\AppConfig::class, function (Server $c) {
401
+            return new \OC\AppConfig($c->getDatabaseConnection());
402
+        });
403
+        $this->registerAlias('AppConfig', \OC\AppConfig::class);
404
+        $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
405
+
406
+        $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
407
+            return new \OC\L10N\Factory(
408
+                $c->getConfig(),
409
+                $c->getRequest(),
410
+                $c->getUserSession(),
411
+                \OC::$SERVERROOT
412
+            );
413
+        });
414
+        $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
415
+
416
+        $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
417
+            $config = $c->getConfig();
418
+            $cacheFactory = $c->getMemCacheFactory();
419
+            $request = $c->getRequest();
420
+            return new \OC\URLGenerator(
421
+                $config,
422
+                $cacheFactory,
423
+                $request
424
+            );
425
+        });
426
+        $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
427
+
428
+        $this->registerService('AppHelper', function ($c) {
429
+            return new \OC\AppHelper();
430
+        });
431
+        $this->registerAlias('AppFetcher', AppFetcher::class);
432
+        $this->registerAlias('CategoryFetcher', CategoryFetcher::class);
433
+
434
+        $this->registerService(\OCP\ICache::class, function ($c) {
435
+            return new Cache\File();
436
+        });
437
+        $this->registerAlias('UserCache', \OCP\ICache::class);
438
+
439
+        $this->registerService(Factory::class, function (Server $c) {
440
+
441
+            $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
442
+                '\\OC\\Memcache\\ArrayCache',
443
+                '\\OC\\Memcache\\ArrayCache',
444
+                '\\OC\\Memcache\\ArrayCache'
445
+            );
446
+            $config = $c->getConfig();
447
+            $request = $c->getRequest();
448
+            $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
449
+
450
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
451
+                $v = \OC_App::getAppVersions();
452
+                $v['core'] = implode(',', \OC_Util::getVersion());
453
+                $version = implode(',', $v);
454
+                $instanceId = \OC_Util::getInstanceId();
455
+                $path = \OC::$SERVERROOT;
456
+                $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl());
457
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
458
+                    $config->getSystemValue('memcache.local', null),
459
+                    $config->getSystemValue('memcache.distributed', null),
460
+                    $config->getSystemValue('memcache.locking', null)
461
+                );
462
+            }
463
+            return $arrayCacheFactory;
464
+
465
+        });
466
+        $this->registerAlias('MemCacheFactory', Factory::class);
467
+        $this->registerAlias(ICacheFactory::class, Factory::class);
468
+
469
+        $this->registerService('RedisFactory', function (Server $c) {
470
+            $systemConfig = $c->getSystemConfig();
471
+            return new RedisFactory($systemConfig);
472
+        });
473
+
474
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
475
+            return new \OC\Activity\Manager(
476
+                $c->getRequest(),
477
+                $c->getUserSession(),
478
+                $c->getConfig(),
479
+                $c->query(IValidator::class)
480
+            );
481
+        });
482
+        $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
483
+
484
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
485
+            return new \OC\Activity\EventMerger(
486
+                $c->getL10N('lib')
487
+            );
488
+        });
489
+        $this->registerAlias(IValidator::class, Validator::class);
490
+
491
+        $this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
492
+            return new AvatarManager(
493
+                $c->getUserManager(),
494
+                $c->getAppDataDir('avatar'),
495
+                $c->getL10N('lib'),
496
+                $c->getLogger(),
497
+                $c->getConfig()
498
+            );
499
+        });
500
+        $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
501
+
502
+        $this->registerService(\OCP\ILogger::class, function (Server $c) {
503
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
504
+            $logger = Log::getLogClass($logType);
505
+            call_user_func(array($logger, 'init'));
506
+
507
+            return new Log($logger);
508
+        });
509
+        $this->registerAlias('Logger', \OCP\ILogger::class);
510
+
511
+        $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
512
+            $config = $c->getConfig();
513
+            return new \OC\BackgroundJob\JobList(
514
+                $c->getDatabaseConnection(),
515
+                $config,
516
+                new TimeFactory()
517
+            );
518
+        });
519
+        $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
520
+
521
+        $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
522
+            $cacheFactory = $c->getMemCacheFactory();
523
+            $logger = $c->getLogger();
524
+            if ($cacheFactory->isAvailable()) {
525
+                $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
526
+            } else {
527
+                $router = new \OC\Route\Router($logger);
528
+            }
529
+            return $router;
530
+        });
531
+        $this->registerAlias('Router', \OCP\Route\IRouter::class);
532
+
533
+        $this->registerService(\OCP\ISearch::class, function ($c) {
534
+            return new Search();
535
+        });
536
+        $this->registerAlias('Search', \OCP\ISearch::class);
537
+
538
+        $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) {
539
+            return new \OC\Security\RateLimiting\Limiter(
540
+                $this->getUserSession(),
541
+                $this->getRequest(),
542
+                new \OC\AppFramework\Utility\TimeFactory(),
543
+                $c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
544
+            );
545
+        });
546
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
547
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
548
+                $this->getMemCacheFactory(),
549
+                new \OC\AppFramework\Utility\TimeFactory()
550
+            );
551
+        });
552
+
553
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
554
+            return new SecureRandom();
555
+        });
556
+        $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
557
+
558
+        $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
559
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
560
+        });
561
+        $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
562
+
563
+        $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
564
+            return new Hasher($c->getConfig());
565
+        });
566
+        $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
567
+
568
+        $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
569
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
570
+        });
571
+        $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
572
+
573
+        $this->registerService(IDBConnection::class, function (Server $c) {
574
+            $systemConfig = $c->getSystemConfig();
575
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
576
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
577
+            if (!$factory->isValidType($type)) {
578
+                throw new \OC\DatabaseException('Invalid database type');
579
+            }
580
+            $connectionParams = $factory->createConnectionParams();
581
+            $connection = $factory->getConnection($type, $connectionParams);
582
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
583
+            return $connection;
584
+        });
585
+        $this->registerAlias('DatabaseConnection', IDBConnection::class);
586
+
587
+        $this->registerService('HTTPHelper', function (Server $c) {
588
+            $config = $c->getConfig();
589
+            return new HTTPHelper(
590
+                $config,
591
+                $c->getHTTPClientService()
592
+            );
593
+        });
594
+
595
+        $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
596
+            $user = \OC_User::getUser();
597
+            $uid = $user ? $user : null;
598
+            return new ClientService(
599
+                $c->getConfig(),
600
+                new \OC\Security\CertificateManager(
601
+                    $uid,
602
+                    new View(),
603
+                    $c->getConfig(),
604
+                    $c->getLogger(),
605
+                    $c->getSecureRandom()
606
+                )
607
+            );
608
+        });
609
+        $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
610
+        $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
611
+            $eventLogger = new EventLogger();
612
+            if ($c->getSystemConfig()->getValue('debug', false)) {
613
+                // In debug mode, module is being activated by default
614
+                $eventLogger->activate();
615
+            }
616
+            return $eventLogger;
617
+        });
618
+        $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
619
+
620
+        $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
621
+            $queryLogger = new QueryLogger();
622
+            if ($c->getSystemConfig()->getValue('debug', false)) {
623
+                // In debug mode, module is being activated by default
624
+                $queryLogger->activate();
625
+            }
626
+            return $queryLogger;
627
+        });
628
+        $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
629
+
630
+        $this->registerService(TempManager::class, function (Server $c) {
631
+            return new TempManager(
632
+                $c->getLogger(),
633
+                $c->getConfig()
634
+            );
635
+        });
636
+        $this->registerAlias('TempManager', TempManager::class);
637
+        $this->registerAlias(ITempManager::class, TempManager::class);
638
+
639
+        $this->registerService(AppManager::class, function (Server $c) {
640
+            return new \OC\App\AppManager(
641
+                $c->getUserSession(),
642
+                $c->getAppConfig(),
643
+                $c->getGroupManager(),
644
+                $c->getMemCacheFactory(),
645
+                $c->getEventDispatcher()
646
+            );
647
+        });
648
+        $this->registerAlias('AppManager', AppManager::class);
649
+        $this->registerAlias(IAppManager::class, AppManager::class);
650
+
651
+        $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
652
+            return new DateTimeZone(
653
+                $c->getConfig(),
654
+                $c->getSession()
655
+            );
656
+        });
657
+        $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
658
+
659
+        $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
660
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
661
+
662
+            return new DateTimeFormatter(
663
+                $c->getDateTimeZone()->getTimeZone(),
664
+                $c->getL10N('lib', $language)
665
+            );
666
+        });
667
+        $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
668
+
669
+        $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
670
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
671
+            $listener = new UserMountCacheListener($mountCache);
672
+            $listener->listen($c->getUserManager());
673
+            return $mountCache;
674
+        });
675
+        $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
676
+
677
+        $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
678
+            $loader = \OC\Files\Filesystem::getLoader();
679
+            $mountCache = $c->query('UserMountCache');
680
+            $manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
681
+
682
+            // builtin providers
683
+
684
+            $config = $c->getConfig();
685
+            $manager->registerProvider(new CacheMountProvider($config));
686
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
687
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
688
+
689
+            return $manager;
690
+        });
691
+        $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
692
+
693
+        $this->registerService('IniWrapper', function ($c) {
694
+            return new IniGetWrapper();
695
+        });
696
+        $this->registerService('AsyncCommandBus', function (Server $c) {
697
+            $jobList = $c->getJobList();
698
+            return new AsyncBus($jobList);
699
+        });
700
+        $this->registerService('TrustedDomainHelper', function ($c) {
701
+            return new TrustedDomainHelper($this->getConfig());
702
+        });
703
+        $this->registerService('Throttler', function(Server $c) {
704
+            return new Throttler(
705
+                $c->getDatabaseConnection(),
706
+                new TimeFactory(),
707
+                $c->getLogger(),
708
+                $c->getConfig()
709
+            );
710
+        });
711
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
712
+            // IConfig and IAppManager requires a working database. This code
713
+            // might however be called when ownCloud is not yet setup.
714
+            if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
715
+                $config = $c->getConfig();
716
+                $appManager = $c->getAppManager();
717
+            } else {
718
+                $config = null;
719
+                $appManager = null;
720
+            }
721
+
722
+            return new Checker(
723
+                    new EnvironmentHelper(),
724
+                    new FileAccessHelper(),
725
+                    new AppLocator(),
726
+                    $config,
727
+                    $c->getMemCacheFactory(),
728
+                    $appManager,
729
+                    $c->getTempManager()
730
+            );
731
+        });
732
+        $this->registerService(\OCP\IRequest::class, function ($c) {
733
+            if (isset($this['urlParams'])) {
734
+                $urlParams = $this['urlParams'];
735
+            } else {
736
+                $urlParams = [];
737
+            }
738
+
739
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
740
+                && in_array('fakeinput', stream_get_wrappers())
741
+            ) {
742
+                $stream = 'fakeinput://data';
743
+            } else {
744
+                $stream = 'php://input';
745
+            }
746
+
747
+            return new Request(
748
+                [
749
+                    'get' => $_GET,
750
+                    'post' => $_POST,
751
+                    'files' => $_FILES,
752
+                    'server' => $_SERVER,
753
+                    'env' => $_ENV,
754
+                    'cookies' => $_COOKIE,
755
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
756
+                        ? $_SERVER['REQUEST_METHOD']
757
+                        : null,
758
+                    'urlParams' => $urlParams,
759
+                ],
760
+                $this->getSecureRandom(),
761
+                $this->getConfig(),
762
+                $this->getCsrfTokenManager(),
763
+                $stream
764
+            );
765
+        });
766
+        $this->registerAlias('Request', \OCP\IRequest::class);
767
+
768
+        $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
769
+            return new Mailer(
770
+                $c->getConfig(),
771
+                $c->getLogger(),
772
+                $c->query(Defaults::class),
773
+                $c->getURLGenerator(),
774
+                $c->getL10N('lib')
775
+            );
776
+        });
777
+        $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
778
+
779
+        $this->registerService('LDAPProvider', function(Server $c) {
780
+            $config = $c->getConfig();
781
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
782
+            if(is_null($factoryClass)) {
783
+                throw new \Exception('ldapProviderFactory not set');
784
+            }
785
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
786
+            $factory = new $factoryClass($this);
787
+            return $factory->getLDAPProvider();
788
+        });
789
+        $this->registerService(ILockingProvider::class, function (Server $c) {
790
+            $ini = $c->getIniWrapper();
791
+            $config = $c->getConfig();
792
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
793
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
794
+                /** @var \OC\Memcache\Factory $memcacheFactory */
795
+                $memcacheFactory = $c->getMemCacheFactory();
796
+                $memcache = $memcacheFactory->createLocking('lock');
797
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
798
+                    return new MemcacheLockingProvider($memcache, $ttl);
799
+                }
800
+                return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
801
+            }
802
+            return new NoopLockingProvider();
803
+        });
804
+        $this->registerAlias('LockingProvider', ILockingProvider::class);
805
+
806
+        $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
807
+            return new \OC\Files\Mount\Manager();
808
+        });
809
+        $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
810
+
811
+        $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
812
+            return new \OC\Files\Type\Detection(
813
+                $c->getURLGenerator(),
814
+                \OC::$configDir,
815
+                \OC::$SERVERROOT . '/resources/config/'
816
+            );
817
+        });
818
+        $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
819
+
820
+        $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
821
+            return new \OC\Files\Type\Loader(
822
+                $c->getDatabaseConnection()
823
+            );
824
+        });
825
+        $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
826
+        $this->registerService(BundleFetcher::class, function () {
827
+            return new BundleFetcher($this->getL10N('lib'));
828
+        });
829
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
830
+            return new Manager(
831
+                $c->query(IValidator::class)
832
+            );
833
+        });
834
+        $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
835
+
836
+        $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
837
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
838
+            $manager->registerCapability(function () use ($c) {
839
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
840
+            });
841
+            $manager->registerCapability(function () use ($c) {
842
+                return $c->query(\OC\Security\Bruteforce\Capabilities::class);
843
+            });
844
+            return $manager;
845
+        });
846
+        $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
847
+
848
+        $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
849
+            $config = $c->getConfig();
850
+            $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
851
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
852
+            $factory = new $factoryClass($this);
853
+            return $factory->getManager();
854
+        });
855
+        $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
856
+
857
+        $this->registerService('ThemingDefaults', function(Server $c) {
858
+            /*
859 859
 			 * Dark magic for autoloader.
860 860
 			 * If we do a class_exists it will try to load the class which will
861 861
 			 * make composer cache the result. Resulting in errors when enabling
862 862
 			 * the theming app.
863 863
 			 */
864
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
865
-			if (isset($prefixes['OCA\\Theming\\'])) {
866
-				$classExists = true;
867
-			} else {
868
-				$classExists = false;
869
-			}
870
-
871
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
872
-				return new ThemingDefaults(
873
-					$c->getConfig(),
874
-					$c->getL10N('theming'),
875
-					$c->getURLGenerator(),
876
-					$c->getAppDataDir('theming'),
877
-					$c->getMemCacheFactory(),
878
-					new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming'))
879
-				);
880
-			}
881
-			return new \OC_Defaults();
882
-		});
883
-		$this->registerService(SCSSCacher::class, function(Server $c) {
884
-			/** @var Factory $cacheFactory */
885
-			$cacheFactory = $c->query(Factory::class);
886
-			return new SCSSCacher(
887
-				$c->getLogger(),
888
-				$c->query(\OC\Files\AppData\Factory::class),
889
-				$c->getURLGenerator(),
890
-				$c->getConfig(),
891
-				$c->getThemingDefaults(),
892
-				\OC::$SERVERROOT,
893
-				$cacheFactory->create('SCSS')
894
-			);
895
-		});
896
-		$this->registerService(EventDispatcher::class, function () {
897
-			return new EventDispatcher();
898
-		});
899
-		$this->registerAlias('EventDispatcher', EventDispatcher::class);
900
-		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
901
-
902
-		$this->registerService('CryptoWrapper', function (Server $c) {
903
-			// FIXME: Instantiiated here due to cyclic dependency
904
-			$request = new Request(
905
-				[
906
-					'get' => $_GET,
907
-					'post' => $_POST,
908
-					'files' => $_FILES,
909
-					'server' => $_SERVER,
910
-					'env' => $_ENV,
911
-					'cookies' => $_COOKIE,
912
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
913
-						? $_SERVER['REQUEST_METHOD']
914
-						: null,
915
-				],
916
-				$c->getSecureRandom(),
917
-				$c->getConfig()
918
-			);
919
-
920
-			return new CryptoWrapper(
921
-				$c->getConfig(),
922
-				$c->getCrypto(),
923
-				$c->getSecureRandom(),
924
-				$request
925
-			);
926
-		});
927
-		$this->registerService('CsrfTokenManager', function (Server $c) {
928
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
929
-
930
-			return new CsrfTokenManager(
931
-				$tokenGenerator,
932
-				$c->query(SessionStorage::class)
933
-			);
934
-		});
935
-		$this->registerService(SessionStorage::class, function (Server $c) {
936
-			return new SessionStorage($c->getSession());
937
-		});
938
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
939
-			return new ContentSecurityPolicyManager();
940
-		});
941
-		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
942
-
943
-		$this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
944
-			return new ContentSecurityPolicyNonceManager(
945
-				$c->getCsrfTokenManager(),
946
-				$c->getRequest()
947
-			);
948
-		});
949
-
950
-		$this->registerService(\OCP\Share\IManager::class, function(Server $c) {
951
-			$config = $c->getConfig();
952
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
953
-			/** @var \OCP\Share\IProviderFactory $factory */
954
-			$factory = new $factoryClass($this);
955
-
956
-			$manager = new \OC\Share20\Manager(
957
-				$c->getLogger(),
958
-				$c->getConfig(),
959
-				$c->getSecureRandom(),
960
-				$c->getHasher(),
961
-				$c->getMountManager(),
962
-				$c->getGroupManager(),
963
-				$c->getL10N('core'),
964
-				$factory,
965
-				$c->getUserManager(),
966
-				$c->getLazyRootFolder(),
967
-				$c->getEventDispatcher()
968
-			);
969
-
970
-			return $manager;
971
-		});
972
-		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
973
-
974
-		$this->registerService('SettingsManager', function(Server $c) {
975
-			$manager = new \OC\Settings\Manager(
976
-				$c->getLogger(),
977
-				$c->getDatabaseConnection(),
978
-				$c->getL10N('lib'),
979
-				$c->getConfig(),
980
-				$c->getEncryptionManager(),
981
-				$c->getUserManager(),
982
-				$c->getLockingProvider(),
983
-				$c->getRequest(),
984
-				new \OC\Settings\Mapper($c->getDatabaseConnection()),
985
-				$c->getURLGenerator(),
986
-				$c->query(AccountManager::class),
987
-				$c->getGroupManager(),
988
-				$c->getL10NFactory(),
989
-				$c->getThemingDefaults(),
990
-				$c->getAppManager()
991
-			);
992
-			return $manager;
993
-		});
994
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
995
-			return new \OC\Files\AppData\Factory(
996
-				$c->getRootFolder(),
997
-				$c->getSystemConfig()
998
-			);
999
-		});
1000
-
1001
-		$this->registerService('LockdownManager', function (Server $c) {
1002
-			return new LockdownManager(function() use ($c) {
1003
-				return $c->getSession();
1004
-			});
1005
-		});
1006
-
1007
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1008
-			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1009
-		});
1010
-
1011
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1012
-			return new CloudIdManager();
1013
-		});
1014
-
1015
-		/* To trick DI since we don't extend the DIContainer here */
1016
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
1017
-			return new CleanPreviewsBackgroundJob(
1018
-				$c->getRootFolder(),
1019
-				$c->getLogger(),
1020
-				$c->getJobList(),
1021
-				new TimeFactory()
1022
-			);
1023
-		});
1024
-
1025
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1026
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1027
-
1028
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1029
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1030
-
1031
-		$this->registerService(Defaults::class, function (Server $c) {
1032
-			return new Defaults(
1033
-				$c->getThemingDefaults()
1034
-			);
1035
-		});
1036
-		$this->registerAlias('Defaults', \OCP\Defaults::class);
1037
-
1038
-		$this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
1039
-			return $c->query(\OCP\IUserSession::class)->getSession();
1040
-		});
1041
-
1042
-		$this->registerService(IShareHelper::class, function(Server $c) {
1043
-			return new ShareHelper(
1044
-				$c->query(\OCP\Share\IManager::class)
1045
-			);
1046
-		});
1047
-	}
1048
-
1049
-	/**
1050
-	 * @return \OCP\Contacts\IManager
1051
-	 */
1052
-	public function getContactsManager() {
1053
-		return $this->query('ContactsManager');
1054
-	}
1055
-
1056
-	/**
1057
-	 * @return \OC\Encryption\Manager
1058
-	 */
1059
-	public function getEncryptionManager() {
1060
-		return $this->query('EncryptionManager');
1061
-	}
1062
-
1063
-	/**
1064
-	 * @return \OC\Encryption\File
1065
-	 */
1066
-	public function getEncryptionFilesHelper() {
1067
-		return $this->query('EncryptionFileHelper');
1068
-	}
1069
-
1070
-	/**
1071
-	 * @return \OCP\Encryption\Keys\IStorage
1072
-	 */
1073
-	public function getEncryptionKeyStorage() {
1074
-		return $this->query('EncryptionKeyStorage');
1075
-	}
1076
-
1077
-	/**
1078
-	 * The current request object holding all information about the request
1079
-	 * currently being processed is returned from this method.
1080
-	 * In case the current execution was not initiated by a web request null is returned
1081
-	 *
1082
-	 * @return \OCP\IRequest
1083
-	 */
1084
-	public function getRequest() {
1085
-		return $this->query('Request');
1086
-	}
1087
-
1088
-	/**
1089
-	 * Returns the preview manager which can create preview images for a given file
1090
-	 *
1091
-	 * @return \OCP\IPreview
1092
-	 */
1093
-	public function getPreviewManager() {
1094
-		return $this->query('PreviewManager');
1095
-	}
1096
-
1097
-	/**
1098
-	 * Returns the tag manager which can get and set tags for different object types
1099
-	 *
1100
-	 * @see \OCP\ITagManager::load()
1101
-	 * @return \OCP\ITagManager
1102
-	 */
1103
-	public function getTagManager() {
1104
-		return $this->query('TagManager');
1105
-	}
1106
-
1107
-	/**
1108
-	 * Returns the system-tag manager
1109
-	 *
1110
-	 * @return \OCP\SystemTag\ISystemTagManager
1111
-	 *
1112
-	 * @since 9.0.0
1113
-	 */
1114
-	public function getSystemTagManager() {
1115
-		return $this->query('SystemTagManager');
1116
-	}
1117
-
1118
-	/**
1119
-	 * Returns the system-tag object mapper
1120
-	 *
1121
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1122
-	 *
1123
-	 * @since 9.0.0
1124
-	 */
1125
-	public function getSystemTagObjectMapper() {
1126
-		return $this->query('SystemTagObjectMapper');
1127
-	}
1128
-
1129
-	/**
1130
-	 * Returns the avatar manager, used for avatar functionality
1131
-	 *
1132
-	 * @return \OCP\IAvatarManager
1133
-	 */
1134
-	public function getAvatarManager() {
1135
-		return $this->query('AvatarManager');
1136
-	}
1137
-
1138
-	/**
1139
-	 * Returns the root folder of ownCloud's data directory
1140
-	 *
1141
-	 * @return \OCP\Files\IRootFolder
1142
-	 */
1143
-	public function getRootFolder() {
1144
-		return $this->query('LazyRootFolder');
1145
-	}
1146
-
1147
-	/**
1148
-	 * Returns the root folder of ownCloud's data directory
1149
-	 * This is the lazy variant so this gets only initialized once it
1150
-	 * is actually used.
1151
-	 *
1152
-	 * @return \OCP\Files\IRootFolder
1153
-	 */
1154
-	public function getLazyRootFolder() {
1155
-		return $this->query('LazyRootFolder');
1156
-	}
1157
-
1158
-	/**
1159
-	 * Returns a view to ownCloud's files folder
1160
-	 *
1161
-	 * @param string $userId user ID
1162
-	 * @return \OCP\Files\Folder|null
1163
-	 */
1164
-	public function getUserFolder($userId = null) {
1165
-		if ($userId === null) {
1166
-			$user = $this->getUserSession()->getUser();
1167
-			if (!$user) {
1168
-				return null;
1169
-			}
1170
-			$userId = $user->getUID();
1171
-		}
1172
-		$root = $this->getRootFolder();
1173
-		return $root->getUserFolder($userId);
1174
-	}
1175
-
1176
-	/**
1177
-	 * Returns an app-specific view in ownClouds data directory
1178
-	 *
1179
-	 * @return \OCP\Files\Folder
1180
-	 * @deprecated since 9.2.0 use IAppData
1181
-	 */
1182
-	public function getAppFolder() {
1183
-		$dir = '/' . \OC_App::getCurrentApp();
1184
-		$root = $this->getRootFolder();
1185
-		if (!$root->nodeExists($dir)) {
1186
-			$folder = $root->newFolder($dir);
1187
-		} else {
1188
-			$folder = $root->get($dir);
1189
-		}
1190
-		return $folder;
1191
-	}
1192
-
1193
-	/**
1194
-	 * @return \OC\User\Manager
1195
-	 */
1196
-	public function getUserManager() {
1197
-		return $this->query('UserManager');
1198
-	}
1199
-
1200
-	/**
1201
-	 * @return \OC\Group\Manager
1202
-	 */
1203
-	public function getGroupManager() {
1204
-		return $this->query('GroupManager');
1205
-	}
1206
-
1207
-	/**
1208
-	 * @return \OC\User\Session
1209
-	 */
1210
-	public function getUserSession() {
1211
-		return $this->query('UserSession');
1212
-	}
1213
-
1214
-	/**
1215
-	 * @return \OCP\ISession
1216
-	 */
1217
-	public function getSession() {
1218
-		return $this->query('UserSession')->getSession();
1219
-	}
1220
-
1221
-	/**
1222
-	 * @param \OCP\ISession $session
1223
-	 */
1224
-	public function setSession(\OCP\ISession $session) {
1225
-		$this->query(SessionStorage::class)->setSession($session);
1226
-		$this->query('UserSession')->setSession($session);
1227
-		$this->query(Store::class)->setSession($session);
1228
-	}
1229
-
1230
-	/**
1231
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1232
-	 */
1233
-	public function getTwoFactorAuthManager() {
1234
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1235
-	}
1236
-
1237
-	/**
1238
-	 * @return \OC\NavigationManager
1239
-	 */
1240
-	public function getNavigationManager() {
1241
-		return $this->query('NavigationManager');
1242
-	}
1243
-
1244
-	/**
1245
-	 * @return \OCP\IConfig
1246
-	 */
1247
-	public function getConfig() {
1248
-		return $this->query('AllConfig');
1249
-	}
1250
-
1251
-	/**
1252
-	 * @internal For internal use only
1253
-	 * @return \OC\SystemConfig
1254
-	 */
1255
-	public function getSystemConfig() {
1256
-		return $this->query('SystemConfig');
1257
-	}
1258
-
1259
-	/**
1260
-	 * Returns the app config manager
1261
-	 *
1262
-	 * @return \OCP\IAppConfig
1263
-	 */
1264
-	public function getAppConfig() {
1265
-		return $this->query('AppConfig');
1266
-	}
1267
-
1268
-	/**
1269
-	 * @return \OCP\L10N\IFactory
1270
-	 */
1271
-	public function getL10NFactory() {
1272
-		return $this->query('L10NFactory');
1273
-	}
1274
-
1275
-	/**
1276
-	 * get an L10N instance
1277
-	 *
1278
-	 * @param string $app appid
1279
-	 * @param string $lang
1280
-	 * @return IL10N
1281
-	 */
1282
-	public function getL10N($app, $lang = null) {
1283
-		return $this->getL10NFactory()->get($app, $lang);
1284
-	}
1285
-
1286
-	/**
1287
-	 * @return \OCP\IURLGenerator
1288
-	 */
1289
-	public function getURLGenerator() {
1290
-		return $this->query('URLGenerator');
1291
-	}
1292
-
1293
-	/**
1294
-	 * @return \OCP\IHelper
1295
-	 */
1296
-	public function getHelper() {
1297
-		return $this->query('AppHelper');
1298
-	}
1299
-
1300
-	/**
1301
-	 * @return AppFetcher
1302
-	 */
1303
-	public function getAppFetcher() {
1304
-		return $this->query(AppFetcher::class);
1305
-	}
1306
-
1307
-	/**
1308
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1309
-	 * getMemCacheFactory() instead.
1310
-	 *
1311
-	 * @return \OCP\ICache
1312
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1313
-	 */
1314
-	public function getCache() {
1315
-		return $this->query('UserCache');
1316
-	}
1317
-
1318
-	/**
1319
-	 * Returns an \OCP\CacheFactory instance
1320
-	 *
1321
-	 * @return \OCP\ICacheFactory
1322
-	 */
1323
-	public function getMemCacheFactory() {
1324
-		return $this->query('MemCacheFactory');
1325
-	}
1326
-
1327
-	/**
1328
-	 * Returns an \OC\RedisFactory instance
1329
-	 *
1330
-	 * @return \OC\RedisFactory
1331
-	 */
1332
-	public function getGetRedisFactory() {
1333
-		return $this->query('RedisFactory');
1334
-	}
1335
-
1336
-
1337
-	/**
1338
-	 * Returns the current session
1339
-	 *
1340
-	 * @return \OCP\IDBConnection
1341
-	 */
1342
-	public function getDatabaseConnection() {
1343
-		return $this->query('DatabaseConnection');
1344
-	}
1345
-
1346
-	/**
1347
-	 * Returns the activity manager
1348
-	 *
1349
-	 * @return \OCP\Activity\IManager
1350
-	 */
1351
-	public function getActivityManager() {
1352
-		return $this->query('ActivityManager');
1353
-	}
1354
-
1355
-	/**
1356
-	 * Returns an job list for controlling background jobs
1357
-	 *
1358
-	 * @return \OCP\BackgroundJob\IJobList
1359
-	 */
1360
-	public function getJobList() {
1361
-		return $this->query('JobList');
1362
-	}
1363
-
1364
-	/**
1365
-	 * Returns a logger instance
1366
-	 *
1367
-	 * @return \OCP\ILogger
1368
-	 */
1369
-	public function getLogger() {
1370
-		return $this->query('Logger');
1371
-	}
1372
-
1373
-	/**
1374
-	 * Returns a router for generating and matching urls
1375
-	 *
1376
-	 * @return \OCP\Route\IRouter
1377
-	 */
1378
-	public function getRouter() {
1379
-		return $this->query('Router');
1380
-	}
1381
-
1382
-	/**
1383
-	 * Returns a search instance
1384
-	 *
1385
-	 * @return \OCP\ISearch
1386
-	 */
1387
-	public function getSearch() {
1388
-		return $this->query('Search');
1389
-	}
1390
-
1391
-	/**
1392
-	 * Returns a SecureRandom instance
1393
-	 *
1394
-	 * @return \OCP\Security\ISecureRandom
1395
-	 */
1396
-	public function getSecureRandom() {
1397
-		return $this->query('SecureRandom');
1398
-	}
1399
-
1400
-	/**
1401
-	 * Returns a Crypto instance
1402
-	 *
1403
-	 * @return \OCP\Security\ICrypto
1404
-	 */
1405
-	public function getCrypto() {
1406
-		return $this->query('Crypto');
1407
-	}
1408
-
1409
-	/**
1410
-	 * Returns a Hasher instance
1411
-	 *
1412
-	 * @return \OCP\Security\IHasher
1413
-	 */
1414
-	public function getHasher() {
1415
-		return $this->query('Hasher');
1416
-	}
1417
-
1418
-	/**
1419
-	 * Returns a CredentialsManager instance
1420
-	 *
1421
-	 * @return \OCP\Security\ICredentialsManager
1422
-	 */
1423
-	public function getCredentialsManager() {
1424
-		return $this->query('CredentialsManager');
1425
-	}
1426
-
1427
-	/**
1428
-	 * Returns an instance of the HTTP helper class
1429
-	 *
1430
-	 * @deprecated Use getHTTPClientService()
1431
-	 * @return \OC\HTTPHelper
1432
-	 */
1433
-	public function getHTTPHelper() {
1434
-		return $this->query('HTTPHelper');
1435
-	}
1436
-
1437
-	/**
1438
-	 * Get the certificate manager for the user
1439
-	 *
1440
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1441
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1442
-	 */
1443
-	public function getCertificateManager($userId = '') {
1444
-		if ($userId === '') {
1445
-			$userSession = $this->getUserSession();
1446
-			$user = $userSession->getUser();
1447
-			if (is_null($user)) {
1448
-				return null;
1449
-			}
1450
-			$userId = $user->getUID();
1451
-		}
1452
-		return new CertificateManager(
1453
-			$userId,
1454
-			new View(),
1455
-			$this->getConfig(),
1456
-			$this->getLogger(),
1457
-			$this->getSecureRandom()
1458
-		);
1459
-	}
1460
-
1461
-	/**
1462
-	 * Returns an instance of the HTTP client service
1463
-	 *
1464
-	 * @return \OCP\Http\Client\IClientService
1465
-	 */
1466
-	public function getHTTPClientService() {
1467
-		return $this->query('HttpClientService');
1468
-	}
1469
-
1470
-	/**
1471
-	 * Create a new event source
1472
-	 *
1473
-	 * @return \OCP\IEventSource
1474
-	 */
1475
-	public function createEventSource() {
1476
-		return new \OC_EventSource();
1477
-	}
1478
-
1479
-	/**
1480
-	 * Get the active event logger
1481
-	 *
1482
-	 * The returned logger only logs data when debug mode is enabled
1483
-	 *
1484
-	 * @return \OCP\Diagnostics\IEventLogger
1485
-	 */
1486
-	public function getEventLogger() {
1487
-		return $this->query('EventLogger');
1488
-	}
1489
-
1490
-	/**
1491
-	 * Get the active query logger
1492
-	 *
1493
-	 * The returned logger only logs data when debug mode is enabled
1494
-	 *
1495
-	 * @return \OCP\Diagnostics\IQueryLogger
1496
-	 */
1497
-	public function getQueryLogger() {
1498
-		return $this->query('QueryLogger');
1499
-	}
1500
-
1501
-	/**
1502
-	 * Get the manager for temporary files and folders
1503
-	 *
1504
-	 * @return \OCP\ITempManager
1505
-	 */
1506
-	public function getTempManager() {
1507
-		return $this->query('TempManager');
1508
-	}
1509
-
1510
-	/**
1511
-	 * Get the app manager
1512
-	 *
1513
-	 * @return \OCP\App\IAppManager
1514
-	 */
1515
-	public function getAppManager() {
1516
-		return $this->query('AppManager');
1517
-	}
1518
-
1519
-	/**
1520
-	 * Creates a new mailer
1521
-	 *
1522
-	 * @return \OCP\Mail\IMailer
1523
-	 */
1524
-	public function getMailer() {
1525
-		return $this->query('Mailer');
1526
-	}
1527
-
1528
-	/**
1529
-	 * Get the webroot
1530
-	 *
1531
-	 * @return string
1532
-	 */
1533
-	public function getWebRoot() {
1534
-		return $this->webRoot;
1535
-	}
1536
-
1537
-	/**
1538
-	 * @return \OC\OCSClient
1539
-	 */
1540
-	public function getOcsClient() {
1541
-		return $this->query('OcsClient');
1542
-	}
1543
-
1544
-	/**
1545
-	 * @return \OCP\IDateTimeZone
1546
-	 */
1547
-	public function getDateTimeZone() {
1548
-		return $this->query('DateTimeZone');
1549
-	}
1550
-
1551
-	/**
1552
-	 * @return \OCP\IDateTimeFormatter
1553
-	 */
1554
-	public function getDateTimeFormatter() {
1555
-		return $this->query('DateTimeFormatter');
1556
-	}
1557
-
1558
-	/**
1559
-	 * @return \OCP\Files\Config\IMountProviderCollection
1560
-	 */
1561
-	public function getMountProviderCollection() {
1562
-		return $this->query('MountConfigManager');
1563
-	}
1564
-
1565
-	/**
1566
-	 * Get the IniWrapper
1567
-	 *
1568
-	 * @return IniGetWrapper
1569
-	 */
1570
-	public function getIniWrapper() {
1571
-		return $this->query('IniWrapper');
1572
-	}
1573
-
1574
-	/**
1575
-	 * @return \OCP\Command\IBus
1576
-	 */
1577
-	public function getCommandBus() {
1578
-		return $this->query('AsyncCommandBus');
1579
-	}
1580
-
1581
-	/**
1582
-	 * Get the trusted domain helper
1583
-	 *
1584
-	 * @return TrustedDomainHelper
1585
-	 */
1586
-	public function getTrustedDomainHelper() {
1587
-		return $this->query('TrustedDomainHelper');
1588
-	}
1589
-
1590
-	/**
1591
-	 * Get the locking provider
1592
-	 *
1593
-	 * @return \OCP\Lock\ILockingProvider
1594
-	 * @since 8.1.0
1595
-	 */
1596
-	public function getLockingProvider() {
1597
-		return $this->query('LockingProvider');
1598
-	}
1599
-
1600
-	/**
1601
-	 * @return \OCP\Files\Mount\IMountManager
1602
-	 **/
1603
-	function getMountManager() {
1604
-		return $this->query('MountManager');
1605
-	}
1606
-
1607
-	/** @return \OCP\Files\Config\IUserMountCache */
1608
-	function getUserMountCache() {
1609
-		return $this->query('UserMountCache');
1610
-	}
1611
-
1612
-	/**
1613
-	 * Get the MimeTypeDetector
1614
-	 *
1615
-	 * @return \OCP\Files\IMimeTypeDetector
1616
-	 */
1617
-	public function getMimeTypeDetector() {
1618
-		return $this->query('MimeTypeDetector');
1619
-	}
1620
-
1621
-	/**
1622
-	 * Get the MimeTypeLoader
1623
-	 *
1624
-	 * @return \OCP\Files\IMimeTypeLoader
1625
-	 */
1626
-	public function getMimeTypeLoader() {
1627
-		return $this->query('MimeTypeLoader');
1628
-	}
1629
-
1630
-	/**
1631
-	 * Get the manager of all the capabilities
1632
-	 *
1633
-	 * @return \OC\CapabilitiesManager
1634
-	 */
1635
-	public function getCapabilitiesManager() {
1636
-		return $this->query('CapabilitiesManager');
1637
-	}
1638
-
1639
-	/**
1640
-	 * Get the EventDispatcher
1641
-	 *
1642
-	 * @return EventDispatcherInterface
1643
-	 * @since 8.2.0
1644
-	 */
1645
-	public function getEventDispatcher() {
1646
-		return $this->query('EventDispatcher');
1647
-	}
1648
-
1649
-	/**
1650
-	 * Get the Notification Manager
1651
-	 *
1652
-	 * @return \OCP\Notification\IManager
1653
-	 * @since 8.2.0
1654
-	 */
1655
-	public function getNotificationManager() {
1656
-		return $this->query('NotificationManager');
1657
-	}
1658
-
1659
-	/**
1660
-	 * @return \OCP\Comments\ICommentsManager
1661
-	 */
1662
-	public function getCommentsManager() {
1663
-		return $this->query('CommentsManager');
1664
-	}
1665
-
1666
-	/**
1667
-	 * @return \OCA\Theming\ThemingDefaults
1668
-	 */
1669
-	public function getThemingDefaults() {
1670
-		return $this->query('ThemingDefaults');
1671
-	}
1672
-
1673
-	/**
1674
-	 * @return \OC\IntegrityCheck\Checker
1675
-	 */
1676
-	public function getIntegrityCodeChecker() {
1677
-		return $this->query('IntegrityCodeChecker');
1678
-	}
1679
-
1680
-	/**
1681
-	 * @return \OC\Session\CryptoWrapper
1682
-	 */
1683
-	public function getSessionCryptoWrapper() {
1684
-		return $this->query('CryptoWrapper');
1685
-	}
1686
-
1687
-	/**
1688
-	 * @return CsrfTokenManager
1689
-	 */
1690
-	public function getCsrfTokenManager() {
1691
-		return $this->query('CsrfTokenManager');
1692
-	}
1693
-
1694
-	/**
1695
-	 * @return Throttler
1696
-	 */
1697
-	public function getBruteForceThrottler() {
1698
-		return $this->query('Throttler');
1699
-	}
1700
-
1701
-	/**
1702
-	 * @return IContentSecurityPolicyManager
1703
-	 */
1704
-	public function getContentSecurityPolicyManager() {
1705
-		return $this->query('ContentSecurityPolicyManager');
1706
-	}
1707
-
1708
-	/**
1709
-	 * @return ContentSecurityPolicyNonceManager
1710
-	 */
1711
-	public function getContentSecurityPolicyNonceManager() {
1712
-		return $this->query('ContentSecurityPolicyNonceManager');
1713
-	}
1714
-
1715
-	/**
1716
-	 * Not a public API as of 8.2, wait for 9.0
1717
-	 *
1718
-	 * @return \OCA\Files_External\Service\BackendService
1719
-	 */
1720
-	public function getStoragesBackendService() {
1721
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1722
-	}
1723
-
1724
-	/**
1725
-	 * Not a public API as of 8.2, wait for 9.0
1726
-	 *
1727
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1728
-	 */
1729
-	public function getGlobalStoragesService() {
1730
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1731
-	}
1732
-
1733
-	/**
1734
-	 * Not a public API as of 8.2, wait for 9.0
1735
-	 *
1736
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1737
-	 */
1738
-	public function getUserGlobalStoragesService() {
1739
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1740
-	}
1741
-
1742
-	/**
1743
-	 * Not a public API as of 8.2, wait for 9.0
1744
-	 *
1745
-	 * @return \OCA\Files_External\Service\UserStoragesService
1746
-	 */
1747
-	public function getUserStoragesService() {
1748
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1749
-	}
1750
-
1751
-	/**
1752
-	 * @return \OCP\Share\IManager
1753
-	 */
1754
-	public function getShareManager() {
1755
-		return $this->query('ShareManager');
1756
-	}
1757
-
1758
-	/**
1759
-	 * Returns the LDAP Provider
1760
-	 *
1761
-	 * @return \OCP\LDAP\ILDAPProvider
1762
-	 */
1763
-	public function getLDAPProvider() {
1764
-		return $this->query('LDAPProvider');
1765
-	}
1766
-
1767
-	/**
1768
-	 * @return \OCP\Settings\IManager
1769
-	 */
1770
-	public function getSettingsManager() {
1771
-		return $this->query('SettingsManager');
1772
-	}
1773
-
1774
-	/**
1775
-	 * @return \OCP\Files\IAppData
1776
-	 */
1777
-	public function getAppDataDir($app) {
1778
-		/** @var \OC\Files\AppData\Factory $factory */
1779
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
1780
-		return $factory->get($app);
1781
-	}
1782
-
1783
-	/**
1784
-	 * @return \OCP\Lockdown\ILockdownManager
1785
-	 */
1786
-	public function getLockdownManager() {
1787
-		return $this->query('LockdownManager');
1788
-	}
1789
-
1790
-	/**
1791
-	 * @return \OCP\Federation\ICloudIdManager
1792
-	 */
1793
-	public function getCloudIdManager() {
1794
-		return $this->query(ICloudIdManager::class);
1795
-	}
864
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
865
+            if (isset($prefixes['OCA\\Theming\\'])) {
866
+                $classExists = true;
867
+            } else {
868
+                $classExists = false;
869
+            }
870
+
871
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
872
+                return new ThemingDefaults(
873
+                    $c->getConfig(),
874
+                    $c->getL10N('theming'),
875
+                    $c->getURLGenerator(),
876
+                    $c->getAppDataDir('theming'),
877
+                    $c->getMemCacheFactory(),
878
+                    new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming'))
879
+                );
880
+            }
881
+            return new \OC_Defaults();
882
+        });
883
+        $this->registerService(SCSSCacher::class, function(Server $c) {
884
+            /** @var Factory $cacheFactory */
885
+            $cacheFactory = $c->query(Factory::class);
886
+            return new SCSSCacher(
887
+                $c->getLogger(),
888
+                $c->query(\OC\Files\AppData\Factory::class),
889
+                $c->getURLGenerator(),
890
+                $c->getConfig(),
891
+                $c->getThemingDefaults(),
892
+                \OC::$SERVERROOT,
893
+                $cacheFactory->create('SCSS')
894
+            );
895
+        });
896
+        $this->registerService(EventDispatcher::class, function () {
897
+            return new EventDispatcher();
898
+        });
899
+        $this->registerAlias('EventDispatcher', EventDispatcher::class);
900
+        $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
901
+
902
+        $this->registerService('CryptoWrapper', function (Server $c) {
903
+            // FIXME: Instantiiated here due to cyclic dependency
904
+            $request = new Request(
905
+                [
906
+                    'get' => $_GET,
907
+                    'post' => $_POST,
908
+                    'files' => $_FILES,
909
+                    'server' => $_SERVER,
910
+                    'env' => $_ENV,
911
+                    'cookies' => $_COOKIE,
912
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
913
+                        ? $_SERVER['REQUEST_METHOD']
914
+                        : null,
915
+                ],
916
+                $c->getSecureRandom(),
917
+                $c->getConfig()
918
+            );
919
+
920
+            return new CryptoWrapper(
921
+                $c->getConfig(),
922
+                $c->getCrypto(),
923
+                $c->getSecureRandom(),
924
+                $request
925
+            );
926
+        });
927
+        $this->registerService('CsrfTokenManager', function (Server $c) {
928
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
929
+
930
+            return new CsrfTokenManager(
931
+                $tokenGenerator,
932
+                $c->query(SessionStorage::class)
933
+            );
934
+        });
935
+        $this->registerService(SessionStorage::class, function (Server $c) {
936
+            return new SessionStorage($c->getSession());
937
+        });
938
+        $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
939
+            return new ContentSecurityPolicyManager();
940
+        });
941
+        $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
942
+
943
+        $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
944
+            return new ContentSecurityPolicyNonceManager(
945
+                $c->getCsrfTokenManager(),
946
+                $c->getRequest()
947
+            );
948
+        });
949
+
950
+        $this->registerService(\OCP\Share\IManager::class, function(Server $c) {
951
+            $config = $c->getConfig();
952
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
953
+            /** @var \OCP\Share\IProviderFactory $factory */
954
+            $factory = new $factoryClass($this);
955
+
956
+            $manager = new \OC\Share20\Manager(
957
+                $c->getLogger(),
958
+                $c->getConfig(),
959
+                $c->getSecureRandom(),
960
+                $c->getHasher(),
961
+                $c->getMountManager(),
962
+                $c->getGroupManager(),
963
+                $c->getL10N('core'),
964
+                $factory,
965
+                $c->getUserManager(),
966
+                $c->getLazyRootFolder(),
967
+                $c->getEventDispatcher()
968
+            );
969
+
970
+            return $manager;
971
+        });
972
+        $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
973
+
974
+        $this->registerService('SettingsManager', function(Server $c) {
975
+            $manager = new \OC\Settings\Manager(
976
+                $c->getLogger(),
977
+                $c->getDatabaseConnection(),
978
+                $c->getL10N('lib'),
979
+                $c->getConfig(),
980
+                $c->getEncryptionManager(),
981
+                $c->getUserManager(),
982
+                $c->getLockingProvider(),
983
+                $c->getRequest(),
984
+                new \OC\Settings\Mapper($c->getDatabaseConnection()),
985
+                $c->getURLGenerator(),
986
+                $c->query(AccountManager::class),
987
+                $c->getGroupManager(),
988
+                $c->getL10NFactory(),
989
+                $c->getThemingDefaults(),
990
+                $c->getAppManager()
991
+            );
992
+            return $manager;
993
+        });
994
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
995
+            return new \OC\Files\AppData\Factory(
996
+                $c->getRootFolder(),
997
+                $c->getSystemConfig()
998
+            );
999
+        });
1000
+
1001
+        $this->registerService('LockdownManager', function (Server $c) {
1002
+            return new LockdownManager(function() use ($c) {
1003
+                return $c->getSession();
1004
+            });
1005
+        });
1006
+
1007
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1008
+            return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1009
+        });
1010
+
1011
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
1012
+            return new CloudIdManager();
1013
+        });
1014
+
1015
+        /* To trick DI since we don't extend the DIContainer here */
1016
+        $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
1017
+            return new CleanPreviewsBackgroundJob(
1018
+                $c->getRootFolder(),
1019
+                $c->getLogger(),
1020
+                $c->getJobList(),
1021
+                new TimeFactory()
1022
+            );
1023
+        });
1024
+
1025
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1026
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1027
+
1028
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1029
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1030
+
1031
+        $this->registerService(Defaults::class, function (Server $c) {
1032
+            return new Defaults(
1033
+                $c->getThemingDefaults()
1034
+            );
1035
+        });
1036
+        $this->registerAlias('Defaults', \OCP\Defaults::class);
1037
+
1038
+        $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
1039
+            return $c->query(\OCP\IUserSession::class)->getSession();
1040
+        });
1041
+
1042
+        $this->registerService(IShareHelper::class, function(Server $c) {
1043
+            return new ShareHelper(
1044
+                $c->query(\OCP\Share\IManager::class)
1045
+            );
1046
+        });
1047
+    }
1048
+
1049
+    /**
1050
+     * @return \OCP\Contacts\IManager
1051
+     */
1052
+    public function getContactsManager() {
1053
+        return $this->query('ContactsManager');
1054
+    }
1055
+
1056
+    /**
1057
+     * @return \OC\Encryption\Manager
1058
+     */
1059
+    public function getEncryptionManager() {
1060
+        return $this->query('EncryptionManager');
1061
+    }
1062
+
1063
+    /**
1064
+     * @return \OC\Encryption\File
1065
+     */
1066
+    public function getEncryptionFilesHelper() {
1067
+        return $this->query('EncryptionFileHelper');
1068
+    }
1069
+
1070
+    /**
1071
+     * @return \OCP\Encryption\Keys\IStorage
1072
+     */
1073
+    public function getEncryptionKeyStorage() {
1074
+        return $this->query('EncryptionKeyStorage');
1075
+    }
1076
+
1077
+    /**
1078
+     * The current request object holding all information about the request
1079
+     * currently being processed is returned from this method.
1080
+     * In case the current execution was not initiated by a web request null is returned
1081
+     *
1082
+     * @return \OCP\IRequest
1083
+     */
1084
+    public function getRequest() {
1085
+        return $this->query('Request');
1086
+    }
1087
+
1088
+    /**
1089
+     * Returns the preview manager which can create preview images for a given file
1090
+     *
1091
+     * @return \OCP\IPreview
1092
+     */
1093
+    public function getPreviewManager() {
1094
+        return $this->query('PreviewManager');
1095
+    }
1096
+
1097
+    /**
1098
+     * Returns the tag manager which can get and set tags for different object types
1099
+     *
1100
+     * @see \OCP\ITagManager::load()
1101
+     * @return \OCP\ITagManager
1102
+     */
1103
+    public function getTagManager() {
1104
+        return $this->query('TagManager');
1105
+    }
1106
+
1107
+    /**
1108
+     * Returns the system-tag manager
1109
+     *
1110
+     * @return \OCP\SystemTag\ISystemTagManager
1111
+     *
1112
+     * @since 9.0.0
1113
+     */
1114
+    public function getSystemTagManager() {
1115
+        return $this->query('SystemTagManager');
1116
+    }
1117
+
1118
+    /**
1119
+     * Returns the system-tag object mapper
1120
+     *
1121
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
1122
+     *
1123
+     * @since 9.0.0
1124
+     */
1125
+    public function getSystemTagObjectMapper() {
1126
+        return $this->query('SystemTagObjectMapper');
1127
+    }
1128
+
1129
+    /**
1130
+     * Returns the avatar manager, used for avatar functionality
1131
+     *
1132
+     * @return \OCP\IAvatarManager
1133
+     */
1134
+    public function getAvatarManager() {
1135
+        return $this->query('AvatarManager');
1136
+    }
1137
+
1138
+    /**
1139
+     * Returns the root folder of ownCloud's data directory
1140
+     *
1141
+     * @return \OCP\Files\IRootFolder
1142
+     */
1143
+    public function getRootFolder() {
1144
+        return $this->query('LazyRootFolder');
1145
+    }
1146
+
1147
+    /**
1148
+     * Returns the root folder of ownCloud's data directory
1149
+     * This is the lazy variant so this gets only initialized once it
1150
+     * is actually used.
1151
+     *
1152
+     * @return \OCP\Files\IRootFolder
1153
+     */
1154
+    public function getLazyRootFolder() {
1155
+        return $this->query('LazyRootFolder');
1156
+    }
1157
+
1158
+    /**
1159
+     * Returns a view to ownCloud's files folder
1160
+     *
1161
+     * @param string $userId user ID
1162
+     * @return \OCP\Files\Folder|null
1163
+     */
1164
+    public function getUserFolder($userId = null) {
1165
+        if ($userId === null) {
1166
+            $user = $this->getUserSession()->getUser();
1167
+            if (!$user) {
1168
+                return null;
1169
+            }
1170
+            $userId = $user->getUID();
1171
+        }
1172
+        $root = $this->getRootFolder();
1173
+        return $root->getUserFolder($userId);
1174
+    }
1175
+
1176
+    /**
1177
+     * Returns an app-specific view in ownClouds data directory
1178
+     *
1179
+     * @return \OCP\Files\Folder
1180
+     * @deprecated since 9.2.0 use IAppData
1181
+     */
1182
+    public function getAppFolder() {
1183
+        $dir = '/' . \OC_App::getCurrentApp();
1184
+        $root = $this->getRootFolder();
1185
+        if (!$root->nodeExists($dir)) {
1186
+            $folder = $root->newFolder($dir);
1187
+        } else {
1188
+            $folder = $root->get($dir);
1189
+        }
1190
+        return $folder;
1191
+    }
1192
+
1193
+    /**
1194
+     * @return \OC\User\Manager
1195
+     */
1196
+    public function getUserManager() {
1197
+        return $this->query('UserManager');
1198
+    }
1199
+
1200
+    /**
1201
+     * @return \OC\Group\Manager
1202
+     */
1203
+    public function getGroupManager() {
1204
+        return $this->query('GroupManager');
1205
+    }
1206
+
1207
+    /**
1208
+     * @return \OC\User\Session
1209
+     */
1210
+    public function getUserSession() {
1211
+        return $this->query('UserSession');
1212
+    }
1213
+
1214
+    /**
1215
+     * @return \OCP\ISession
1216
+     */
1217
+    public function getSession() {
1218
+        return $this->query('UserSession')->getSession();
1219
+    }
1220
+
1221
+    /**
1222
+     * @param \OCP\ISession $session
1223
+     */
1224
+    public function setSession(\OCP\ISession $session) {
1225
+        $this->query(SessionStorage::class)->setSession($session);
1226
+        $this->query('UserSession')->setSession($session);
1227
+        $this->query(Store::class)->setSession($session);
1228
+    }
1229
+
1230
+    /**
1231
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1232
+     */
1233
+    public function getTwoFactorAuthManager() {
1234
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1235
+    }
1236
+
1237
+    /**
1238
+     * @return \OC\NavigationManager
1239
+     */
1240
+    public function getNavigationManager() {
1241
+        return $this->query('NavigationManager');
1242
+    }
1243
+
1244
+    /**
1245
+     * @return \OCP\IConfig
1246
+     */
1247
+    public function getConfig() {
1248
+        return $this->query('AllConfig');
1249
+    }
1250
+
1251
+    /**
1252
+     * @internal For internal use only
1253
+     * @return \OC\SystemConfig
1254
+     */
1255
+    public function getSystemConfig() {
1256
+        return $this->query('SystemConfig');
1257
+    }
1258
+
1259
+    /**
1260
+     * Returns the app config manager
1261
+     *
1262
+     * @return \OCP\IAppConfig
1263
+     */
1264
+    public function getAppConfig() {
1265
+        return $this->query('AppConfig');
1266
+    }
1267
+
1268
+    /**
1269
+     * @return \OCP\L10N\IFactory
1270
+     */
1271
+    public function getL10NFactory() {
1272
+        return $this->query('L10NFactory');
1273
+    }
1274
+
1275
+    /**
1276
+     * get an L10N instance
1277
+     *
1278
+     * @param string $app appid
1279
+     * @param string $lang
1280
+     * @return IL10N
1281
+     */
1282
+    public function getL10N($app, $lang = null) {
1283
+        return $this->getL10NFactory()->get($app, $lang);
1284
+    }
1285
+
1286
+    /**
1287
+     * @return \OCP\IURLGenerator
1288
+     */
1289
+    public function getURLGenerator() {
1290
+        return $this->query('URLGenerator');
1291
+    }
1292
+
1293
+    /**
1294
+     * @return \OCP\IHelper
1295
+     */
1296
+    public function getHelper() {
1297
+        return $this->query('AppHelper');
1298
+    }
1299
+
1300
+    /**
1301
+     * @return AppFetcher
1302
+     */
1303
+    public function getAppFetcher() {
1304
+        return $this->query(AppFetcher::class);
1305
+    }
1306
+
1307
+    /**
1308
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1309
+     * getMemCacheFactory() instead.
1310
+     *
1311
+     * @return \OCP\ICache
1312
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1313
+     */
1314
+    public function getCache() {
1315
+        return $this->query('UserCache');
1316
+    }
1317
+
1318
+    /**
1319
+     * Returns an \OCP\CacheFactory instance
1320
+     *
1321
+     * @return \OCP\ICacheFactory
1322
+     */
1323
+    public function getMemCacheFactory() {
1324
+        return $this->query('MemCacheFactory');
1325
+    }
1326
+
1327
+    /**
1328
+     * Returns an \OC\RedisFactory instance
1329
+     *
1330
+     * @return \OC\RedisFactory
1331
+     */
1332
+    public function getGetRedisFactory() {
1333
+        return $this->query('RedisFactory');
1334
+    }
1335
+
1336
+
1337
+    /**
1338
+     * Returns the current session
1339
+     *
1340
+     * @return \OCP\IDBConnection
1341
+     */
1342
+    public function getDatabaseConnection() {
1343
+        return $this->query('DatabaseConnection');
1344
+    }
1345
+
1346
+    /**
1347
+     * Returns the activity manager
1348
+     *
1349
+     * @return \OCP\Activity\IManager
1350
+     */
1351
+    public function getActivityManager() {
1352
+        return $this->query('ActivityManager');
1353
+    }
1354
+
1355
+    /**
1356
+     * Returns an job list for controlling background jobs
1357
+     *
1358
+     * @return \OCP\BackgroundJob\IJobList
1359
+     */
1360
+    public function getJobList() {
1361
+        return $this->query('JobList');
1362
+    }
1363
+
1364
+    /**
1365
+     * Returns a logger instance
1366
+     *
1367
+     * @return \OCP\ILogger
1368
+     */
1369
+    public function getLogger() {
1370
+        return $this->query('Logger');
1371
+    }
1372
+
1373
+    /**
1374
+     * Returns a router for generating and matching urls
1375
+     *
1376
+     * @return \OCP\Route\IRouter
1377
+     */
1378
+    public function getRouter() {
1379
+        return $this->query('Router');
1380
+    }
1381
+
1382
+    /**
1383
+     * Returns a search instance
1384
+     *
1385
+     * @return \OCP\ISearch
1386
+     */
1387
+    public function getSearch() {
1388
+        return $this->query('Search');
1389
+    }
1390
+
1391
+    /**
1392
+     * Returns a SecureRandom instance
1393
+     *
1394
+     * @return \OCP\Security\ISecureRandom
1395
+     */
1396
+    public function getSecureRandom() {
1397
+        return $this->query('SecureRandom');
1398
+    }
1399
+
1400
+    /**
1401
+     * Returns a Crypto instance
1402
+     *
1403
+     * @return \OCP\Security\ICrypto
1404
+     */
1405
+    public function getCrypto() {
1406
+        return $this->query('Crypto');
1407
+    }
1408
+
1409
+    /**
1410
+     * Returns a Hasher instance
1411
+     *
1412
+     * @return \OCP\Security\IHasher
1413
+     */
1414
+    public function getHasher() {
1415
+        return $this->query('Hasher');
1416
+    }
1417
+
1418
+    /**
1419
+     * Returns a CredentialsManager instance
1420
+     *
1421
+     * @return \OCP\Security\ICredentialsManager
1422
+     */
1423
+    public function getCredentialsManager() {
1424
+        return $this->query('CredentialsManager');
1425
+    }
1426
+
1427
+    /**
1428
+     * Returns an instance of the HTTP helper class
1429
+     *
1430
+     * @deprecated Use getHTTPClientService()
1431
+     * @return \OC\HTTPHelper
1432
+     */
1433
+    public function getHTTPHelper() {
1434
+        return $this->query('HTTPHelper');
1435
+    }
1436
+
1437
+    /**
1438
+     * Get the certificate manager for the user
1439
+     *
1440
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1441
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1442
+     */
1443
+    public function getCertificateManager($userId = '') {
1444
+        if ($userId === '') {
1445
+            $userSession = $this->getUserSession();
1446
+            $user = $userSession->getUser();
1447
+            if (is_null($user)) {
1448
+                return null;
1449
+            }
1450
+            $userId = $user->getUID();
1451
+        }
1452
+        return new CertificateManager(
1453
+            $userId,
1454
+            new View(),
1455
+            $this->getConfig(),
1456
+            $this->getLogger(),
1457
+            $this->getSecureRandom()
1458
+        );
1459
+    }
1460
+
1461
+    /**
1462
+     * Returns an instance of the HTTP client service
1463
+     *
1464
+     * @return \OCP\Http\Client\IClientService
1465
+     */
1466
+    public function getHTTPClientService() {
1467
+        return $this->query('HttpClientService');
1468
+    }
1469
+
1470
+    /**
1471
+     * Create a new event source
1472
+     *
1473
+     * @return \OCP\IEventSource
1474
+     */
1475
+    public function createEventSource() {
1476
+        return new \OC_EventSource();
1477
+    }
1478
+
1479
+    /**
1480
+     * Get the active event logger
1481
+     *
1482
+     * The returned logger only logs data when debug mode is enabled
1483
+     *
1484
+     * @return \OCP\Diagnostics\IEventLogger
1485
+     */
1486
+    public function getEventLogger() {
1487
+        return $this->query('EventLogger');
1488
+    }
1489
+
1490
+    /**
1491
+     * Get the active query logger
1492
+     *
1493
+     * The returned logger only logs data when debug mode is enabled
1494
+     *
1495
+     * @return \OCP\Diagnostics\IQueryLogger
1496
+     */
1497
+    public function getQueryLogger() {
1498
+        return $this->query('QueryLogger');
1499
+    }
1500
+
1501
+    /**
1502
+     * Get the manager for temporary files and folders
1503
+     *
1504
+     * @return \OCP\ITempManager
1505
+     */
1506
+    public function getTempManager() {
1507
+        return $this->query('TempManager');
1508
+    }
1509
+
1510
+    /**
1511
+     * Get the app manager
1512
+     *
1513
+     * @return \OCP\App\IAppManager
1514
+     */
1515
+    public function getAppManager() {
1516
+        return $this->query('AppManager');
1517
+    }
1518
+
1519
+    /**
1520
+     * Creates a new mailer
1521
+     *
1522
+     * @return \OCP\Mail\IMailer
1523
+     */
1524
+    public function getMailer() {
1525
+        return $this->query('Mailer');
1526
+    }
1527
+
1528
+    /**
1529
+     * Get the webroot
1530
+     *
1531
+     * @return string
1532
+     */
1533
+    public function getWebRoot() {
1534
+        return $this->webRoot;
1535
+    }
1536
+
1537
+    /**
1538
+     * @return \OC\OCSClient
1539
+     */
1540
+    public function getOcsClient() {
1541
+        return $this->query('OcsClient');
1542
+    }
1543
+
1544
+    /**
1545
+     * @return \OCP\IDateTimeZone
1546
+     */
1547
+    public function getDateTimeZone() {
1548
+        return $this->query('DateTimeZone');
1549
+    }
1550
+
1551
+    /**
1552
+     * @return \OCP\IDateTimeFormatter
1553
+     */
1554
+    public function getDateTimeFormatter() {
1555
+        return $this->query('DateTimeFormatter');
1556
+    }
1557
+
1558
+    /**
1559
+     * @return \OCP\Files\Config\IMountProviderCollection
1560
+     */
1561
+    public function getMountProviderCollection() {
1562
+        return $this->query('MountConfigManager');
1563
+    }
1564
+
1565
+    /**
1566
+     * Get the IniWrapper
1567
+     *
1568
+     * @return IniGetWrapper
1569
+     */
1570
+    public function getIniWrapper() {
1571
+        return $this->query('IniWrapper');
1572
+    }
1573
+
1574
+    /**
1575
+     * @return \OCP\Command\IBus
1576
+     */
1577
+    public function getCommandBus() {
1578
+        return $this->query('AsyncCommandBus');
1579
+    }
1580
+
1581
+    /**
1582
+     * Get the trusted domain helper
1583
+     *
1584
+     * @return TrustedDomainHelper
1585
+     */
1586
+    public function getTrustedDomainHelper() {
1587
+        return $this->query('TrustedDomainHelper');
1588
+    }
1589
+
1590
+    /**
1591
+     * Get the locking provider
1592
+     *
1593
+     * @return \OCP\Lock\ILockingProvider
1594
+     * @since 8.1.0
1595
+     */
1596
+    public function getLockingProvider() {
1597
+        return $this->query('LockingProvider');
1598
+    }
1599
+
1600
+    /**
1601
+     * @return \OCP\Files\Mount\IMountManager
1602
+     **/
1603
+    function getMountManager() {
1604
+        return $this->query('MountManager');
1605
+    }
1606
+
1607
+    /** @return \OCP\Files\Config\IUserMountCache */
1608
+    function getUserMountCache() {
1609
+        return $this->query('UserMountCache');
1610
+    }
1611
+
1612
+    /**
1613
+     * Get the MimeTypeDetector
1614
+     *
1615
+     * @return \OCP\Files\IMimeTypeDetector
1616
+     */
1617
+    public function getMimeTypeDetector() {
1618
+        return $this->query('MimeTypeDetector');
1619
+    }
1620
+
1621
+    /**
1622
+     * Get the MimeTypeLoader
1623
+     *
1624
+     * @return \OCP\Files\IMimeTypeLoader
1625
+     */
1626
+    public function getMimeTypeLoader() {
1627
+        return $this->query('MimeTypeLoader');
1628
+    }
1629
+
1630
+    /**
1631
+     * Get the manager of all the capabilities
1632
+     *
1633
+     * @return \OC\CapabilitiesManager
1634
+     */
1635
+    public function getCapabilitiesManager() {
1636
+        return $this->query('CapabilitiesManager');
1637
+    }
1638
+
1639
+    /**
1640
+     * Get the EventDispatcher
1641
+     *
1642
+     * @return EventDispatcherInterface
1643
+     * @since 8.2.0
1644
+     */
1645
+    public function getEventDispatcher() {
1646
+        return $this->query('EventDispatcher');
1647
+    }
1648
+
1649
+    /**
1650
+     * Get the Notification Manager
1651
+     *
1652
+     * @return \OCP\Notification\IManager
1653
+     * @since 8.2.0
1654
+     */
1655
+    public function getNotificationManager() {
1656
+        return $this->query('NotificationManager');
1657
+    }
1658
+
1659
+    /**
1660
+     * @return \OCP\Comments\ICommentsManager
1661
+     */
1662
+    public function getCommentsManager() {
1663
+        return $this->query('CommentsManager');
1664
+    }
1665
+
1666
+    /**
1667
+     * @return \OCA\Theming\ThemingDefaults
1668
+     */
1669
+    public function getThemingDefaults() {
1670
+        return $this->query('ThemingDefaults');
1671
+    }
1672
+
1673
+    /**
1674
+     * @return \OC\IntegrityCheck\Checker
1675
+     */
1676
+    public function getIntegrityCodeChecker() {
1677
+        return $this->query('IntegrityCodeChecker');
1678
+    }
1679
+
1680
+    /**
1681
+     * @return \OC\Session\CryptoWrapper
1682
+     */
1683
+    public function getSessionCryptoWrapper() {
1684
+        return $this->query('CryptoWrapper');
1685
+    }
1686
+
1687
+    /**
1688
+     * @return CsrfTokenManager
1689
+     */
1690
+    public function getCsrfTokenManager() {
1691
+        return $this->query('CsrfTokenManager');
1692
+    }
1693
+
1694
+    /**
1695
+     * @return Throttler
1696
+     */
1697
+    public function getBruteForceThrottler() {
1698
+        return $this->query('Throttler');
1699
+    }
1700
+
1701
+    /**
1702
+     * @return IContentSecurityPolicyManager
1703
+     */
1704
+    public function getContentSecurityPolicyManager() {
1705
+        return $this->query('ContentSecurityPolicyManager');
1706
+    }
1707
+
1708
+    /**
1709
+     * @return ContentSecurityPolicyNonceManager
1710
+     */
1711
+    public function getContentSecurityPolicyNonceManager() {
1712
+        return $this->query('ContentSecurityPolicyNonceManager');
1713
+    }
1714
+
1715
+    /**
1716
+     * Not a public API as of 8.2, wait for 9.0
1717
+     *
1718
+     * @return \OCA\Files_External\Service\BackendService
1719
+     */
1720
+    public function getStoragesBackendService() {
1721
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1722
+    }
1723
+
1724
+    /**
1725
+     * Not a public API as of 8.2, wait for 9.0
1726
+     *
1727
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1728
+     */
1729
+    public function getGlobalStoragesService() {
1730
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1731
+    }
1732
+
1733
+    /**
1734
+     * Not a public API as of 8.2, wait for 9.0
1735
+     *
1736
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1737
+     */
1738
+    public function getUserGlobalStoragesService() {
1739
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1740
+    }
1741
+
1742
+    /**
1743
+     * Not a public API as of 8.2, wait for 9.0
1744
+     *
1745
+     * @return \OCA\Files_External\Service\UserStoragesService
1746
+     */
1747
+    public function getUserStoragesService() {
1748
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1749
+    }
1750
+
1751
+    /**
1752
+     * @return \OCP\Share\IManager
1753
+     */
1754
+    public function getShareManager() {
1755
+        return $this->query('ShareManager');
1756
+    }
1757
+
1758
+    /**
1759
+     * Returns the LDAP Provider
1760
+     *
1761
+     * @return \OCP\LDAP\ILDAPProvider
1762
+     */
1763
+    public function getLDAPProvider() {
1764
+        return $this->query('LDAPProvider');
1765
+    }
1766
+
1767
+    /**
1768
+     * @return \OCP\Settings\IManager
1769
+     */
1770
+    public function getSettingsManager() {
1771
+        return $this->query('SettingsManager');
1772
+    }
1773
+
1774
+    /**
1775
+     * @return \OCP\Files\IAppData
1776
+     */
1777
+    public function getAppDataDir($app) {
1778
+        /** @var \OC\Files\AppData\Factory $factory */
1779
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
1780
+        return $factory->get($app);
1781
+    }
1782
+
1783
+    /**
1784
+     * @return \OCP\Lockdown\ILockdownManager
1785
+     */
1786
+    public function getLockdownManager() {
1787
+        return $this->query('LockdownManager');
1788
+    }
1789
+
1790
+    /**
1791
+     * @return \OCP\Federation\ICloudIdManager
1792
+     */
1793
+    public function getCloudIdManager() {
1794
+        return $this->query(ICloudIdManager::class);
1795
+    }
1796 1796
 }
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 
151 151
 
152 152
 
153
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
153
+		$this->registerService(\OCP\IPreview::class, function(Server $c) {
154 154
 			return new PreviewManager(
155 155
 				$c->getConfig(),
156 156
 				$c->getRootFolder(),
@@ -161,13 +161,13 @@  discard block
 block discarded – undo
161 161
 		});
162 162
 		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
163 163
 
164
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
164
+		$this->registerService(\OC\Preview\Watcher::class, function(Server $c) {
165 165
 			return new \OC\Preview\Watcher(
166 166
 				$c->getAppDataDir('preview')
167 167
 			);
168 168
 		});
169 169
 
170
-		$this->registerService('EncryptionManager', function (Server $c) {
170
+		$this->registerService('EncryptionManager', function(Server $c) {
171 171
 			$view = new View();
172 172
 			$util = new Encryption\Util(
173 173
 				$view,
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 			);
186 186
 		});
187 187
 
188
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
188
+		$this->registerService('EncryptionFileHelper', function(Server $c) {
189 189
 			$util = new Encryption\Util(
190 190
 				new View(),
191 191
 				$c->getUserManager(),
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 			);
200 200
 		});
201 201
 
202
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
202
+		$this->registerService('EncryptionKeyStorage', function(Server $c) {
203 203
 			$view = new View();
204 204
 			$util = new Encryption\Util(
205 205
 				$view,
@@ -210,32 +210,32 @@  discard block
 block discarded – undo
210 210
 
211 211
 			return new Encryption\Keys\Storage($view, $util);
212 212
 		});
213
-		$this->registerService('TagMapper', function (Server $c) {
213
+		$this->registerService('TagMapper', function(Server $c) {
214 214
 			return new TagMapper($c->getDatabaseConnection());
215 215
 		});
216 216
 
217
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
217
+		$this->registerService(\OCP\ITagManager::class, function(Server $c) {
218 218
 			$tagMapper = $c->query('TagMapper');
219 219
 			return new TagManager($tagMapper, $c->getUserSession());
220 220
 		});
221 221
 		$this->registerAlias('TagManager', \OCP\ITagManager::class);
222 222
 
223
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
223
+		$this->registerService('SystemTagManagerFactory', function(Server $c) {
224 224
 			$config = $c->getConfig();
225 225
 			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
226 226
 			/** @var \OC\SystemTag\ManagerFactory $factory */
227 227
 			$factory = new $factoryClass($this);
228 228
 			return $factory;
229 229
 		});
230
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
230
+		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) {
231 231
 			return $c->query('SystemTagManagerFactory')->getManager();
232 232
 		});
233 233
 		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
234 234
 
235
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
235
+		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) {
236 236
 			return $c->query('SystemTagManagerFactory')->getObjectMapper();
237 237
 		});
238
-		$this->registerService('RootFolder', function (Server $c) {
238
+		$this->registerService('RootFolder', function(Server $c) {
239 239
 			$manager = \OC\Files\Filesystem::getMountManager(null);
240 240
 			$view = new View();
241 241
 			$root = new Root(
@@ -263,30 +263,30 @@  discard block
 block discarded – undo
263 263
 		});
264 264
 		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
265 265
 
266
-		$this->registerService(\OCP\IUserManager::class, function (Server $c) {
266
+		$this->registerService(\OCP\IUserManager::class, function(Server $c) {
267 267
 			$config = $c->getConfig();
268 268
 			return new \OC\User\Manager($config);
269 269
 		});
270 270
 		$this->registerAlias('UserManager', \OCP\IUserManager::class);
271 271
 
272
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
272
+		$this->registerService(\OCP\IGroupManager::class, function(Server $c) {
273 273
 			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
274
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
274
+			$groupManager->listen('\OC\Group', 'preCreate', function($gid) {
275 275
 				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
276 276
 			});
277
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
277
+			$groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) {
278 278
 				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
279 279
 			});
280
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
280
+			$groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) {
281 281
 				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
282 282
 			});
283
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
283
+			$groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) {
284 284
 				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
285 285
 			});
286
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
286
+			$groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
287 287
 				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
288 288
 			});
289
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
289
+			$groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
290 290
 				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
291 291
 				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
292 292
 				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
@@ -306,11 +306,11 @@  discard block
 block discarded – undo
306 306
 			return new Store($session, $logger, $tokenProvider);
307 307
 		});
308 308
 		$this->registerAlias(IStore::class, Store::class);
309
-		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
309
+		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function(Server $c) {
310 310
 			$dbConnection = $c->getDatabaseConnection();
311 311
 			return new Authentication\Token\DefaultTokenMapper($dbConnection);
312 312
 		});
313
-		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
313
+		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function(Server $c) {
314 314
 			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
315 315
 			$crypto = $c->getCrypto();
316 316
 			$config = $c->getConfig();
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 		});
321 321
 		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
322 322
 
323
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
323
+		$this->registerService(\OCP\IUserSession::class, function(Server $c) {
324 324
 			$manager = $c->getUserManager();
325 325
 			$session = new \OC\Session\Memory('');
326 326
 			$timeFactory = new TimeFactory();
@@ -333,44 +333,44 @@  discard block
 block discarded – undo
333 333
 			}
334 334
 
335 335
 			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
336
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
336
+			$userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) {
337 337
 				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
338 338
 			});
339
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
339
+			$userSession->listen('\OC\User', 'postCreateUser', function($user, $password) {
340 340
 				/** @var $user \OC\User\User */
341 341
 				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
342 342
 			});
343
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
343
+			$userSession->listen('\OC\User', 'preDelete', function($user) {
344 344
 				/** @var $user \OC\User\User */
345 345
 				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
346 346
 			});
347
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
347
+			$userSession->listen('\OC\User', 'postDelete', function($user) {
348 348
 				/** @var $user \OC\User\User */
349 349
 				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
350 350
 			});
351
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
351
+			$userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) {
352 352
 				/** @var $user \OC\User\User */
353 353
 				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
354 354
 			});
355
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
355
+			$userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) {
356 356
 				/** @var $user \OC\User\User */
357 357
 				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
358 358
 			});
359
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
359
+			$userSession->listen('\OC\User', 'preLogin', function($uid, $password) {
360 360
 				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
361 361
 			});
362
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
362
+			$userSession->listen('\OC\User', 'postLogin', function($user, $password) {
363 363
 				/** @var $user \OC\User\User */
364 364
 				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
365 365
 			});
366
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
366
+			$userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) {
367 367
 				/** @var $user \OC\User\User */
368 368
 				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
369 369
 			});
370
-			$userSession->listen('\OC\User', 'logout', function () {
370
+			$userSession->listen('\OC\User', 'logout', function() {
371 371
 				\OC_Hook::emit('OC_User', 'logout', array());
372 372
 			});
373
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
373
+			$userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) {
374 374
 				/** @var $user \OC\User\User */
375 375
 				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
376 376
 			});
@@ -378,14 +378,14 @@  discard block
 block discarded – undo
378 378
 		});
379 379
 		$this->registerAlias('UserSession', \OCP\IUserSession::class);
380 380
 
381
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
381
+		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) {
382 382
 			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
383 383
 		});
384 384
 
385 385
 		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
386 386
 		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
387 387
 
388
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
388
+		$this->registerService(\OC\AllConfig::class, function(Server $c) {
389 389
 			return new \OC\AllConfig(
390 390
 				$c->getSystemConfig()
391 391
 			);
@@ -393,17 +393,17 @@  discard block
 block discarded – undo
393 393
 		$this->registerAlias('AllConfig', \OC\AllConfig::class);
394 394
 		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
395 395
 
396
-		$this->registerService('SystemConfig', function ($c) use ($config) {
396
+		$this->registerService('SystemConfig', function($c) use ($config) {
397 397
 			return new \OC\SystemConfig($config);
398 398
 		});
399 399
 
400
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
400
+		$this->registerService(\OC\AppConfig::class, function(Server $c) {
401 401
 			return new \OC\AppConfig($c->getDatabaseConnection());
402 402
 		});
403 403
 		$this->registerAlias('AppConfig', \OC\AppConfig::class);
404 404
 		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
405 405
 
406
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
406
+		$this->registerService(\OCP\L10N\IFactory::class, function(Server $c) {
407 407
 			return new \OC\L10N\Factory(
408 408
 				$c->getConfig(),
409 409
 				$c->getRequest(),
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 		});
414 414
 		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
415 415
 
416
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
416
+		$this->registerService(\OCP\IURLGenerator::class, function(Server $c) {
417 417
 			$config = $c->getConfig();
418 418
 			$cacheFactory = $c->getMemCacheFactory();
419 419
 			$request = $c->getRequest();
@@ -425,18 +425,18 @@  discard block
 block discarded – undo
425 425
 		});
426 426
 		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
427 427
 
428
-		$this->registerService('AppHelper', function ($c) {
428
+		$this->registerService('AppHelper', function($c) {
429 429
 			return new \OC\AppHelper();
430 430
 		});
431 431
 		$this->registerAlias('AppFetcher', AppFetcher::class);
432 432
 		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
433 433
 
434
-		$this->registerService(\OCP\ICache::class, function ($c) {
434
+		$this->registerService(\OCP\ICache::class, function($c) {
435 435
 			return new Cache\File();
436 436
 		});
437 437
 		$this->registerAlias('UserCache', \OCP\ICache::class);
438 438
 
439
-		$this->registerService(Factory::class, function (Server $c) {
439
+		$this->registerService(Factory::class, function(Server $c) {
440 440
 
441 441
 			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
442 442
 				'\\OC\\Memcache\\ArrayCache',
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 				$version = implode(',', $v);
454 454
 				$instanceId = \OC_Util::getInstanceId();
455 455
 				$path = \OC::$SERVERROOT;
456
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl());
456
+				$prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.$urlGenerator->getBaseUrl());
457 457
 				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
458 458
 					$config->getSystemValue('memcache.local', null),
459 459
 					$config->getSystemValue('memcache.distributed', null),
@@ -466,12 +466,12 @@  discard block
 block discarded – undo
466 466
 		$this->registerAlias('MemCacheFactory', Factory::class);
467 467
 		$this->registerAlias(ICacheFactory::class, Factory::class);
468 468
 
469
-		$this->registerService('RedisFactory', function (Server $c) {
469
+		$this->registerService('RedisFactory', function(Server $c) {
470 470
 			$systemConfig = $c->getSystemConfig();
471 471
 			return new RedisFactory($systemConfig);
472 472
 		});
473 473
 
474
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
474
+		$this->registerService(\OCP\Activity\IManager::class, function(Server $c) {
475 475
 			return new \OC\Activity\Manager(
476 476
 				$c->getRequest(),
477 477
 				$c->getUserSession(),
@@ -481,14 +481,14 @@  discard block
 block discarded – undo
481 481
 		});
482 482
 		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
483 483
 
484
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
484
+		$this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) {
485 485
 			return new \OC\Activity\EventMerger(
486 486
 				$c->getL10N('lib')
487 487
 			);
488 488
 		});
489 489
 		$this->registerAlias(IValidator::class, Validator::class);
490 490
 
491
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
491
+		$this->registerService(\OCP\IAvatarManager::class, function(Server $c) {
492 492
 			return new AvatarManager(
493 493
 				$c->getUserManager(),
494 494
 				$c->getAppDataDir('avatar'),
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 		});
500 500
 		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
501 501
 
502
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
502
+		$this->registerService(\OCP\ILogger::class, function(Server $c) {
503 503
 			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
504 504
 			$logger = Log::getLogClass($logType);
505 505
 			call_user_func(array($logger, 'init'));
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
 		});
509 509
 		$this->registerAlias('Logger', \OCP\ILogger::class);
510 510
 
511
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
511
+		$this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) {
512 512
 			$config = $c->getConfig();
513 513
 			return new \OC\BackgroundJob\JobList(
514 514
 				$c->getDatabaseConnection(),
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
 		});
519 519
 		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
520 520
 
521
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
521
+		$this->registerService(\OCP\Route\IRouter::class, function(Server $c) {
522 522
 			$cacheFactory = $c->getMemCacheFactory();
523 523
 			$logger = $c->getLogger();
524 524
 			if ($cacheFactory->isAvailable()) {
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 		});
531 531
 		$this->registerAlias('Router', \OCP\Route\IRouter::class);
532 532
 
533
-		$this->registerService(\OCP\ISearch::class, function ($c) {
533
+		$this->registerService(\OCP\ISearch::class, function($c) {
534 534
 			return new Search();
535 535
 		});
536 536
 		$this->registerAlias('Search', \OCP\ISearch::class);
@@ -550,27 +550,27 @@  discard block
 block discarded – undo
550 550
 			);
551 551
 		});
552 552
 
553
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
553
+		$this->registerService(\OCP\Security\ISecureRandom::class, function($c) {
554 554
 			return new SecureRandom();
555 555
 		});
556 556
 		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
557 557
 
558
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
558
+		$this->registerService(\OCP\Security\ICrypto::class, function(Server $c) {
559 559
 			return new Crypto($c->getConfig(), $c->getSecureRandom());
560 560
 		});
561 561
 		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
562 562
 
563
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
563
+		$this->registerService(\OCP\Security\IHasher::class, function(Server $c) {
564 564
 			return new Hasher($c->getConfig());
565 565
 		});
566 566
 		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
567 567
 
568
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
568
+		$this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) {
569 569
 			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
570 570
 		});
571 571
 		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
572 572
 
573
-		$this->registerService(IDBConnection::class, function (Server $c) {
573
+		$this->registerService(IDBConnection::class, function(Server $c) {
574 574
 			$systemConfig = $c->getSystemConfig();
575 575
 			$factory = new \OC\DB\ConnectionFactory($systemConfig);
576 576
 			$type = $systemConfig->getValue('dbtype', 'sqlite');
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
 		});
585 585
 		$this->registerAlias('DatabaseConnection', IDBConnection::class);
586 586
 
587
-		$this->registerService('HTTPHelper', function (Server $c) {
587
+		$this->registerService('HTTPHelper', function(Server $c) {
588 588
 			$config = $c->getConfig();
589 589
 			return new HTTPHelper(
590 590
 				$config,
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 			);
593 593
 		});
594 594
 
595
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
595
+		$this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) {
596 596
 			$user = \OC_User::getUser();
597 597
 			$uid = $user ? $user : null;
598 598
 			return new ClientService(
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 			);
608 608
 		});
609 609
 		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
610
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
610
+		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) {
611 611
 			$eventLogger = new EventLogger();
612 612
 			if ($c->getSystemConfig()->getValue('debug', false)) {
613 613
 				// In debug mode, module is being activated by default
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
 		});
618 618
 		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
619 619
 
620
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
620
+		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) {
621 621
 			$queryLogger = new QueryLogger();
622 622
 			if ($c->getSystemConfig()->getValue('debug', false)) {
623 623
 				// In debug mode, module is being activated by default
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
 		});
628 628
 		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
629 629
 
630
-		$this->registerService(TempManager::class, function (Server $c) {
630
+		$this->registerService(TempManager::class, function(Server $c) {
631 631
 			return new TempManager(
632 632
 				$c->getLogger(),
633 633
 				$c->getConfig()
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
 		$this->registerAlias('TempManager', TempManager::class);
637 637
 		$this->registerAlias(ITempManager::class, TempManager::class);
638 638
 
639
-		$this->registerService(AppManager::class, function (Server $c) {
639
+		$this->registerService(AppManager::class, function(Server $c) {
640 640
 			return new \OC\App\AppManager(
641 641
 				$c->getUserSession(),
642 642
 				$c->getAppConfig(),
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
 		$this->registerAlias('AppManager', AppManager::class);
649 649
 		$this->registerAlias(IAppManager::class, AppManager::class);
650 650
 
651
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
651
+		$this->registerService(\OCP\IDateTimeZone::class, function(Server $c) {
652 652
 			return new DateTimeZone(
653 653
 				$c->getConfig(),
654 654
 				$c->getSession()
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
 		});
657 657
 		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
658 658
 
659
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
659
+		$this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) {
660 660
 			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
661 661
 
662 662
 			return new DateTimeFormatter(
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
 		});
667 667
 		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
668 668
 
669
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
669
+		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) {
670 670
 			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
671 671
 			$listener = new UserMountCacheListener($mountCache);
672 672
 			$listener->listen($c->getUserManager());
@@ -674,10 +674,10 @@  discard block
 block discarded – undo
674 674
 		});
675 675
 		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
676 676
 
677
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
677
+		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) {
678 678
 			$loader = \OC\Files\Filesystem::getLoader();
679 679
 			$mountCache = $c->query('UserMountCache');
680
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
680
+			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
681 681
 
682 682
 			// builtin providers
683 683
 
@@ -690,14 +690,14 @@  discard block
 block discarded – undo
690 690
 		});
691 691
 		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
692 692
 
693
-		$this->registerService('IniWrapper', function ($c) {
693
+		$this->registerService('IniWrapper', function($c) {
694 694
 			return new IniGetWrapper();
695 695
 		});
696
-		$this->registerService('AsyncCommandBus', function (Server $c) {
696
+		$this->registerService('AsyncCommandBus', function(Server $c) {
697 697
 			$jobList = $c->getJobList();
698 698
 			return new AsyncBus($jobList);
699 699
 		});
700
-		$this->registerService('TrustedDomainHelper', function ($c) {
700
+		$this->registerService('TrustedDomainHelper', function($c) {
701 701
 			return new TrustedDomainHelper($this->getConfig());
702 702
 		});
703 703
 		$this->registerService('Throttler', function(Server $c) {
@@ -708,10 +708,10 @@  discard block
 block discarded – undo
708 708
 				$c->getConfig()
709 709
 			);
710 710
 		});
711
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
711
+		$this->registerService('IntegrityCodeChecker', function(Server $c) {
712 712
 			// IConfig and IAppManager requires a working database. This code
713 713
 			// might however be called when ownCloud is not yet setup.
714
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
714
+			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
715 715
 				$config = $c->getConfig();
716 716
 				$appManager = $c->getAppManager();
717 717
 			} else {
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
 					$c->getTempManager()
730 730
 			);
731 731
 		});
732
-		$this->registerService(\OCP\IRequest::class, function ($c) {
732
+		$this->registerService(\OCP\IRequest::class, function($c) {
733 733
 			if (isset($this['urlParams'])) {
734 734
 				$urlParams = $this['urlParams'];
735 735
 			} else {
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
 		});
766 766
 		$this->registerAlias('Request', \OCP\IRequest::class);
767 767
 
768
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
768
+		$this->registerService(\OCP\Mail\IMailer::class, function(Server $c) {
769 769
 			return new Mailer(
770 770
 				$c->getConfig(),
771 771
 				$c->getLogger(),
@@ -779,14 +779,14 @@  discard block
 block discarded – undo
779 779
 		$this->registerService('LDAPProvider', function(Server $c) {
780 780
 			$config = $c->getConfig();
781 781
 			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
782
-			if(is_null($factoryClass)) {
782
+			if (is_null($factoryClass)) {
783 783
 				throw new \Exception('ldapProviderFactory not set');
784 784
 			}
785 785
 			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
786 786
 			$factory = new $factoryClass($this);
787 787
 			return $factory->getLDAPProvider();
788 788
 		});
789
-		$this->registerService(ILockingProvider::class, function (Server $c) {
789
+		$this->registerService(ILockingProvider::class, function(Server $c) {
790 790
 			$ini = $c->getIniWrapper();
791 791
 			$config = $c->getConfig();
792 792
 			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
@@ -803,42 +803,42 @@  discard block
 block discarded – undo
803 803
 		});
804 804
 		$this->registerAlias('LockingProvider', ILockingProvider::class);
805 805
 
806
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
806
+		$this->registerService(\OCP\Files\Mount\IMountManager::class, function() {
807 807
 			return new \OC\Files\Mount\Manager();
808 808
 		});
809 809
 		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
810 810
 
811
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
811
+		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) {
812 812
 			return new \OC\Files\Type\Detection(
813 813
 				$c->getURLGenerator(),
814 814
 				\OC::$configDir,
815
-				\OC::$SERVERROOT . '/resources/config/'
815
+				\OC::$SERVERROOT.'/resources/config/'
816 816
 			);
817 817
 		});
818 818
 		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
819 819
 
820
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
820
+		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) {
821 821
 			return new \OC\Files\Type\Loader(
822 822
 				$c->getDatabaseConnection()
823 823
 			);
824 824
 		});
825 825
 		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
826
-		$this->registerService(BundleFetcher::class, function () {
826
+		$this->registerService(BundleFetcher::class, function() {
827 827
 			return new BundleFetcher($this->getL10N('lib'));
828 828
 		});
829
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
829
+		$this->registerService(\OCP\Notification\IManager::class, function(Server $c) {
830 830
 			return new Manager(
831 831
 				$c->query(IValidator::class)
832 832
 			);
833 833
 		});
834 834
 		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
835 835
 
836
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
836
+		$this->registerService(\OC\CapabilitiesManager::class, function(Server $c) {
837 837
 			$manager = new \OC\CapabilitiesManager($c->getLogger());
838
-			$manager->registerCapability(function () use ($c) {
838
+			$manager->registerCapability(function() use ($c) {
839 839
 				return new \OC\OCS\CoreCapabilities($c->getConfig());
840 840
 			});
841
-			$manager->registerCapability(function () use ($c) {
841
+			$manager->registerCapability(function() use ($c) {
842 842
 				return $c->query(\OC\Security\Bruteforce\Capabilities::class);
843 843
 			});
844 844
 			return $manager;
@@ -893,13 +893,13 @@  discard block
 block discarded – undo
893 893
 				$cacheFactory->create('SCSS')
894 894
 			);
895 895
 		});
896
-		$this->registerService(EventDispatcher::class, function () {
896
+		$this->registerService(EventDispatcher::class, function() {
897 897
 			return new EventDispatcher();
898 898
 		});
899 899
 		$this->registerAlias('EventDispatcher', EventDispatcher::class);
900 900
 		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
901 901
 
902
-		$this->registerService('CryptoWrapper', function (Server $c) {
902
+		$this->registerService('CryptoWrapper', function(Server $c) {
903 903
 			// FIXME: Instantiiated here due to cyclic dependency
904 904
 			$request = new Request(
905 905
 				[
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
 				$request
925 925
 			);
926 926
 		});
927
-		$this->registerService('CsrfTokenManager', function (Server $c) {
927
+		$this->registerService('CsrfTokenManager', function(Server $c) {
928 928
 			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
929 929
 
930 930
 			return new CsrfTokenManager(
@@ -932,10 +932,10 @@  discard block
 block discarded – undo
932 932
 				$c->query(SessionStorage::class)
933 933
 			);
934 934
 		});
935
-		$this->registerService(SessionStorage::class, function (Server $c) {
935
+		$this->registerService(SessionStorage::class, function(Server $c) {
936 936
 			return new SessionStorage($c->getSession());
937 937
 		});
938
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
938
+		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) {
939 939
 			return new ContentSecurityPolicyManager();
940 940
 		});
941 941
 		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
@@ -991,29 +991,29 @@  discard block
 block discarded – undo
991 991
 			);
992 992
 			return $manager;
993 993
 		});
994
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
994
+		$this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) {
995 995
 			return new \OC\Files\AppData\Factory(
996 996
 				$c->getRootFolder(),
997 997
 				$c->getSystemConfig()
998 998
 			);
999 999
 		});
1000 1000
 
1001
-		$this->registerService('LockdownManager', function (Server $c) {
1001
+		$this->registerService('LockdownManager', function(Server $c) {
1002 1002
 			return new LockdownManager(function() use ($c) {
1003 1003
 				return $c->getSession();
1004 1004
 			});
1005 1005
 		});
1006 1006
 
1007
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1007
+		$this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) {
1008 1008
 			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1009 1009
 		});
1010 1010
 
1011
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1011
+		$this->registerService(ICloudIdManager::class, function(Server $c) {
1012 1012
 			return new CloudIdManager();
1013 1013
 		});
1014 1014
 
1015 1015
 		/* To trick DI since we don't extend the DIContainer here */
1016
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
1016
+		$this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) {
1017 1017
 			return new CleanPreviewsBackgroundJob(
1018 1018
 				$c->getRootFolder(),
1019 1019
 				$c->getLogger(),
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
 		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1029 1029
 		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1030 1030
 
1031
-		$this->registerService(Defaults::class, function (Server $c) {
1031
+		$this->registerService(Defaults::class, function(Server $c) {
1032 1032
 			return new Defaults(
1033 1033
 				$c->getThemingDefaults()
1034 1034
 			);
@@ -1180,7 +1180,7 @@  discard block
 block discarded – undo
1180 1180
 	 * @deprecated since 9.2.0 use IAppData
1181 1181
 	 */
1182 1182
 	public function getAppFolder() {
1183
-		$dir = '/' . \OC_App::getCurrentApp();
1183
+		$dir = '/'.\OC_App::getCurrentApp();
1184 1184
 		$root = $this->getRootFolder();
1185 1185
 		if (!$root->nodeExists($dir)) {
1186 1186
 			$folder = $root->newFolder($dir);
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/Response.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 
227 227
 	/**
228 228
 	 * By default renders no output
229
-	 * @return null
229
+	 * @return string
230 230
 	 * @since 6.0.0
231 231
 	 */
232 232
 	public function render() {
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 
260 260
 	/**
261 261
 	 * Get the currently used Content-Security-Policy
262
-	 * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if
262
+	 * @return ContentSecurityPolicy|null Used Content-Security-Policy or null if
263 263
 	 *                                    none specified.
264 264
 	 * @since 8.1.0
265 265
 	 */
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public function cacheFor($cacheSeconds) {
93 93
 
94
-		if($cacheSeconds > 0) {
95
-			$this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate');
94
+		if ($cacheSeconds > 0) {
95
+			$this->addHeader('Cache-Control', 'max-age='.$cacheSeconds.', must-revalidate');
96 96
 		} else {
97 97
 			$this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
98 98
 		}
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	 * @since 8.0.0
147 147
 	 */
148 148
 	public function invalidateCookies(array $cookieNames) {
149
-		foreach($cookieNames as $cookieName) {
149
+		foreach ($cookieNames as $cookieName) {
150 150
 			$this->invalidateCookie($cookieName);
151 151
 		}
152 152
 		return $this;
@@ -170,11 +170,11 @@  discard block
 block discarded – undo
170 170
 	 * @since 6.0.0 - return value was added in 7.0.0
171 171
 	 */
172 172
 	public function addHeader($name, $value) {
173
-		$name = trim($name);  // always remove leading and trailing whitespace
173
+		$name = trim($name); // always remove leading and trailing whitespace
174 174
 		                      // to be able to reliably check for security
175 175
 		                      // headers
176 176
 
177
-		if(is_null($value)) {
177
+		if (is_null($value)) {
178 178
 			unset($this->headers[$name]);
179 179
 		} else {
180 180
 			$this->headers[$name] = $value;
@@ -205,19 +205,19 @@  discard block
 block discarded – undo
205 205
 	public function getHeaders() {
206 206
 		$mergeWith = [];
207 207
 
208
-		if($this->lastModified) {
208
+		if ($this->lastModified) {
209 209
 			$mergeWith['Last-Modified'] =
210 210
 				$this->lastModified->format(\DateTime::RFC2822);
211 211
 		}
212 212
 
213 213
 		// Build Content-Security-Policy and use default if none has been specified
214
-		if(is_null($this->contentSecurityPolicy)) {
214
+		if (is_null($this->contentSecurityPolicy)) {
215 215
 			$this->setContentSecurityPolicy(new ContentSecurityPolicy());
216 216
 		}
217 217
 		$this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
218 218
 
219
-		if($this->ETag) {
220
-			$mergeWith['ETag'] = '"' . $this->ETag . '"';
219
+		if ($this->ETag) {
220
+			$mergeWith['ETag'] = '"'.$this->ETag.'"';
221 221
 		}
222 222
 
223 223
 		return array_merge($mergeWith, $this->headers);
Please login to merge, or discard this patch.
Indentation   +300 added lines, -300 removed lines patch added patch discarded remove patch
@@ -42,304 +42,304 @@
 block discarded – undo
42 42
  */
43 43
 class Response {
44 44
 
45
-	/**
46
-	 * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate']
47
-	 * @var array
48
-	 */
49
-	private $headers = array(
50
-		'Cache-Control' => 'no-cache, no-store, must-revalidate'
51
-	);
52
-
53
-
54
-	/**
55
-	 * Cookies that will be need to be constructed as header
56
-	 * @var array
57
-	 */
58
-	private $cookies = array();
59
-
60
-
61
-	/**
62
-	 * HTTP status code - defaults to STATUS OK
63
-	 * @var int
64
-	 */
65
-	private $status = Http::STATUS_OK;
66
-
67
-
68
-	/**
69
-	 * Last modified date
70
-	 * @var \DateTime
71
-	 */
72
-	private $lastModified;
73
-
74
-
75
-	/**
76
-	 * ETag
77
-	 * @var string
78
-	 */
79
-	private $ETag;
80
-
81
-	/** @var ContentSecurityPolicy|null Used Content-Security-Policy */
82
-	private $contentSecurityPolicy = null;
83
-
84
-	/** @var bool */
85
-	private $throttled = false;
86
-
87
-	/**
88
-	 * Caches the response
89
-	 * @param int $cacheSeconds the amount of seconds that should be cached
90
-	 * if 0 then caching will be disabled
91
-	 * @return $this
92
-	 * @since 6.0.0 - return value was added in 7.0.0
93
-	 */
94
-	public function cacheFor($cacheSeconds) {
95
-
96
-		if($cacheSeconds > 0) {
97
-			$this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate');
98
-		} else {
99
-			$this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
100
-		}
101
-
102
-		return $this;
103
-	}
104
-
105
-	/**
106
-	 * Adds a new cookie to the response
107
-	 * @param string $name The name of the cookie
108
-	 * @param string $value The value of the cookie
109
-	 * @param \DateTime|null $expireDate Date on that the cookie should expire, if set
110
-	 * 									to null cookie will be considered as session
111
-	 * 									cookie.
112
-	 * @return $this
113
-	 * @since 8.0.0
114
-	 */
115
-	public function addCookie($name, $value, \DateTime $expireDate = null) {
116
-		$this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate);
117
-		return $this;
118
-	}
119
-
120
-
121
-	/**
122
-	 * Set the specified cookies
123
-	 * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null))
124
-	 * @return $this
125
-	 * @since 8.0.0
126
-	 */
127
-	public function setCookies(array $cookies) {
128
-		$this->cookies = $cookies;
129
-		return $this;
130
-	}
131
-
132
-
133
-	/**
134
-	 * Invalidates the specified cookie
135
-	 * @param string $name
136
-	 * @return $this
137
-	 * @since 8.0.0
138
-	 */
139
-	public function invalidateCookie($name) {
140
-		$this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00'));
141
-		return $this;
142
-	}
143
-
144
-	/**
145
-	 * Invalidates the specified cookies
146
-	 * @param array $cookieNames array('foo', 'bar')
147
-	 * @return $this
148
-	 * @since 8.0.0
149
-	 */
150
-	public function invalidateCookies(array $cookieNames) {
151
-		foreach($cookieNames as $cookieName) {
152
-			$this->invalidateCookie($cookieName);
153
-		}
154
-		return $this;
155
-	}
156
-
157
-	/**
158
-	 * Returns the cookies
159
-	 * @return array
160
-	 * @since 8.0.0
161
-	 */
162
-	public function getCookies() {
163
-		return $this->cookies;
164
-	}
165
-
166
-	/**
167
-	 * Adds a new header to the response that will be called before the render
168
-	 * function
169
-	 * @param string $name The name of the HTTP header
170
-	 * @param string $value The value, null will delete it
171
-	 * @return $this
172
-	 * @since 6.0.0 - return value was added in 7.0.0
173
-	 */
174
-	public function addHeader($name, $value) {
175
-		$name = trim($name);  // always remove leading and trailing whitespace
176
-		                      // to be able to reliably check for security
177
-		                      // headers
178
-
179
-		if(is_null($value)) {
180
-			unset($this->headers[$name]);
181
-		} else {
182
-			$this->headers[$name] = $value;
183
-		}
184
-
185
-		return $this;
186
-	}
187
-
188
-
189
-	/**
190
-	 * Set the headers
191
-	 * @param array $headers value header pairs
192
-	 * @return $this
193
-	 * @since 8.0.0
194
-	 */
195
-	public function setHeaders(array $headers) {
196
-		$this->headers = $headers;
197
-
198
-		return $this;
199
-	}
200
-
201
-
202
-	/**
203
-	 * Returns the set headers
204
-	 * @return array the headers
205
-	 * @since 6.0.0
206
-	 */
207
-	public function getHeaders() {
208
-		$mergeWith = [];
209
-
210
-		if($this->lastModified) {
211
-			$mergeWith['Last-Modified'] =
212
-				$this->lastModified->format(\DateTime::RFC2822);
213
-		}
214
-
215
-		// Build Content-Security-Policy and use default if none has been specified
216
-		if(is_null($this->contentSecurityPolicy)) {
217
-			$this->setContentSecurityPolicy(new ContentSecurityPolicy());
218
-		}
219
-		$this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
220
-
221
-		if($this->ETag) {
222
-			$mergeWith['ETag'] = '"' . $this->ETag . '"';
223
-		}
224
-
225
-		return array_merge($mergeWith, $this->headers);
226
-	}
227
-
228
-
229
-	/**
230
-	 * By default renders no output
231
-	 * @return null
232
-	 * @since 6.0.0
233
-	 */
234
-	public function render() {
235
-		return null;
236
-	}
237
-
238
-
239
-	/**
240
-	 * Set response status
241
-	 * @param int $status a HTTP status code, see also the STATUS constants
242
-	 * @return Response Reference to this object
243
-	 * @since 6.0.0 - return value was added in 7.0.0
244
-	 */
245
-	public function setStatus($status) {
246
-		$this->status = $status;
247
-
248
-		return $this;
249
-	}
250
-
251
-	/**
252
-	 * Set a Content-Security-Policy
253
-	 * @param EmptyContentSecurityPolicy $csp Policy to set for the response object
254
-	 * @return $this
255
-	 * @since 8.1.0
256
-	 */
257
-	public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) {
258
-		$this->contentSecurityPolicy = $csp;
259
-		return $this;
260
-	}
261
-
262
-	/**
263
-	 * Get the currently used Content-Security-Policy
264
-	 * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if
265
-	 *                                    none specified.
266
-	 * @since 8.1.0
267
-	 */
268
-	public function getContentSecurityPolicy() {
269
-		return $this->contentSecurityPolicy;
270
-	}
271
-
272
-
273
-	/**
274
-	 * Get response status
275
-	 * @since 6.0.0
276
-	 */
277
-	public function getStatus() {
278
-		return $this->status;
279
-	}
280
-
281
-
282
-	/**
283
-	 * Get the ETag
284
-	 * @return string the etag
285
-	 * @since 6.0.0
286
-	 */
287
-	public function getETag() {
288
-		return $this->ETag;
289
-	}
290
-
291
-
292
-	/**
293
-	 * Get "last modified" date
294
-	 * @return \DateTime RFC2822 formatted last modified date
295
-	 * @since 6.0.0
296
-	 */
297
-	public function getLastModified() {
298
-		return $this->lastModified;
299
-	}
300
-
301
-
302
-	/**
303
-	 * Set the ETag
304
-	 * @param string $ETag
305
-	 * @return Response Reference to this object
306
-	 * @since 6.0.0 - return value was added in 7.0.0
307
-	 */
308
-	public function setETag($ETag) {
309
-		$this->ETag = $ETag;
310
-
311
-		return $this;
312
-	}
313
-
314
-
315
-	/**
316
-	 * Set "last modified" date
317
-	 * @param \DateTime $lastModified
318
-	 * @return Response Reference to this object
319
-	 * @since 6.0.0 - return value was added in 7.0.0
320
-	 */
321
-	public function setLastModified($lastModified) {
322
-		$this->lastModified = $lastModified;
323
-
324
-		return $this;
325
-	}
326
-
327
-	/**
328
-	 * Marks the response as to throttle. Will be throttled when the
329
-	 * @BruteForceProtection annotation is added.
330
-	 *
331
-	 * @since 12.0.0
332
-	 */
333
-	public function throttle() {
334
-		$this->throttled = true;
335
-	}
336
-
337
-	/**
338
-	 * Whether the current response is throttled.
339
-	 *
340
-	 * @since 12.0.0
341
-	 */
342
-	public function isThrottled() {
343
-		return $this->throttled;
344
-	}
45
+    /**
46
+     * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate']
47
+     * @var array
48
+     */
49
+    private $headers = array(
50
+        'Cache-Control' => 'no-cache, no-store, must-revalidate'
51
+    );
52
+
53
+
54
+    /**
55
+     * Cookies that will be need to be constructed as header
56
+     * @var array
57
+     */
58
+    private $cookies = array();
59
+
60
+
61
+    /**
62
+     * HTTP status code - defaults to STATUS OK
63
+     * @var int
64
+     */
65
+    private $status = Http::STATUS_OK;
66
+
67
+
68
+    /**
69
+     * Last modified date
70
+     * @var \DateTime
71
+     */
72
+    private $lastModified;
73
+
74
+
75
+    /**
76
+     * ETag
77
+     * @var string
78
+     */
79
+    private $ETag;
80
+
81
+    /** @var ContentSecurityPolicy|null Used Content-Security-Policy */
82
+    private $contentSecurityPolicy = null;
83
+
84
+    /** @var bool */
85
+    private $throttled = false;
86
+
87
+    /**
88
+     * Caches the response
89
+     * @param int $cacheSeconds the amount of seconds that should be cached
90
+     * if 0 then caching will be disabled
91
+     * @return $this
92
+     * @since 6.0.0 - return value was added in 7.0.0
93
+     */
94
+    public function cacheFor($cacheSeconds) {
95
+
96
+        if($cacheSeconds > 0) {
97
+            $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate');
98
+        } else {
99
+            $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
100
+        }
101
+
102
+        return $this;
103
+    }
104
+
105
+    /**
106
+     * Adds a new cookie to the response
107
+     * @param string $name The name of the cookie
108
+     * @param string $value The value of the cookie
109
+     * @param \DateTime|null $expireDate Date on that the cookie should expire, if set
110
+     * 									to null cookie will be considered as session
111
+     * 									cookie.
112
+     * @return $this
113
+     * @since 8.0.0
114
+     */
115
+    public function addCookie($name, $value, \DateTime $expireDate = null) {
116
+        $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate);
117
+        return $this;
118
+    }
119
+
120
+
121
+    /**
122
+     * Set the specified cookies
123
+     * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null))
124
+     * @return $this
125
+     * @since 8.0.0
126
+     */
127
+    public function setCookies(array $cookies) {
128
+        $this->cookies = $cookies;
129
+        return $this;
130
+    }
131
+
132
+
133
+    /**
134
+     * Invalidates the specified cookie
135
+     * @param string $name
136
+     * @return $this
137
+     * @since 8.0.0
138
+     */
139
+    public function invalidateCookie($name) {
140
+        $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00'));
141
+        return $this;
142
+    }
143
+
144
+    /**
145
+     * Invalidates the specified cookies
146
+     * @param array $cookieNames array('foo', 'bar')
147
+     * @return $this
148
+     * @since 8.0.0
149
+     */
150
+    public function invalidateCookies(array $cookieNames) {
151
+        foreach($cookieNames as $cookieName) {
152
+            $this->invalidateCookie($cookieName);
153
+        }
154
+        return $this;
155
+    }
156
+
157
+    /**
158
+     * Returns the cookies
159
+     * @return array
160
+     * @since 8.0.0
161
+     */
162
+    public function getCookies() {
163
+        return $this->cookies;
164
+    }
165
+
166
+    /**
167
+     * Adds a new header to the response that will be called before the render
168
+     * function
169
+     * @param string $name The name of the HTTP header
170
+     * @param string $value The value, null will delete it
171
+     * @return $this
172
+     * @since 6.0.0 - return value was added in 7.0.0
173
+     */
174
+    public function addHeader($name, $value) {
175
+        $name = trim($name);  // always remove leading and trailing whitespace
176
+                                // to be able to reliably check for security
177
+                                // headers
178
+
179
+        if(is_null($value)) {
180
+            unset($this->headers[$name]);
181
+        } else {
182
+            $this->headers[$name] = $value;
183
+        }
184
+
185
+        return $this;
186
+    }
187
+
188
+
189
+    /**
190
+     * Set the headers
191
+     * @param array $headers value header pairs
192
+     * @return $this
193
+     * @since 8.0.0
194
+     */
195
+    public function setHeaders(array $headers) {
196
+        $this->headers = $headers;
197
+
198
+        return $this;
199
+    }
200
+
201
+
202
+    /**
203
+     * Returns the set headers
204
+     * @return array the headers
205
+     * @since 6.0.0
206
+     */
207
+    public function getHeaders() {
208
+        $mergeWith = [];
209
+
210
+        if($this->lastModified) {
211
+            $mergeWith['Last-Modified'] =
212
+                $this->lastModified->format(\DateTime::RFC2822);
213
+        }
214
+
215
+        // Build Content-Security-Policy and use default if none has been specified
216
+        if(is_null($this->contentSecurityPolicy)) {
217
+            $this->setContentSecurityPolicy(new ContentSecurityPolicy());
218
+        }
219
+        $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
220
+
221
+        if($this->ETag) {
222
+            $mergeWith['ETag'] = '"' . $this->ETag . '"';
223
+        }
224
+
225
+        return array_merge($mergeWith, $this->headers);
226
+    }
227
+
228
+
229
+    /**
230
+     * By default renders no output
231
+     * @return null
232
+     * @since 6.0.0
233
+     */
234
+    public function render() {
235
+        return null;
236
+    }
237
+
238
+
239
+    /**
240
+     * Set response status
241
+     * @param int $status a HTTP status code, see also the STATUS constants
242
+     * @return Response Reference to this object
243
+     * @since 6.0.0 - return value was added in 7.0.0
244
+     */
245
+    public function setStatus($status) {
246
+        $this->status = $status;
247
+
248
+        return $this;
249
+    }
250
+
251
+    /**
252
+     * Set a Content-Security-Policy
253
+     * @param EmptyContentSecurityPolicy $csp Policy to set for the response object
254
+     * @return $this
255
+     * @since 8.1.0
256
+     */
257
+    public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) {
258
+        $this->contentSecurityPolicy = $csp;
259
+        return $this;
260
+    }
261
+
262
+    /**
263
+     * Get the currently used Content-Security-Policy
264
+     * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if
265
+     *                                    none specified.
266
+     * @since 8.1.0
267
+     */
268
+    public function getContentSecurityPolicy() {
269
+        return $this->contentSecurityPolicy;
270
+    }
271
+
272
+
273
+    /**
274
+     * Get response status
275
+     * @since 6.0.0
276
+     */
277
+    public function getStatus() {
278
+        return $this->status;
279
+    }
280
+
281
+
282
+    /**
283
+     * Get the ETag
284
+     * @return string the etag
285
+     * @since 6.0.0
286
+     */
287
+    public function getETag() {
288
+        return $this->ETag;
289
+    }
290
+
291
+
292
+    /**
293
+     * Get "last modified" date
294
+     * @return \DateTime RFC2822 formatted last modified date
295
+     * @since 6.0.0
296
+     */
297
+    public function getLastModified() {
298
+        return $this->lastModified;
299
+    }
300
+
301
+
302
+    /**
303
+     * Set the ETag
304
+     * @param string $ETag
305
+     * @return Response Reference to this object
306
+     * @since 6.0.0 - return value was added in 7.0.0
307
+     */
308
+    public function setETag($ETag) {
309
+        $this->ETag = $ETag;
310
+
311
+        return $this;
312
+    }
313
+
314
+
315
+    /**
316
+     * Set "last modified" date
317
+     * @param \DateTime $lastModified
318
+     * @return Response Reference to this object
319
+     * @since 6.0.0 - return value was added in 7.0.0
320
+     */
321
+    public function setLastModified($lastModified) {
322
+        $this->lastModified = $lastModified;
323
+
324
+        return $this;
325
+    }
326
+
327
+    /**
328
+     * Marks the response as to throttle. Will be throttled when the
329
+     * @BruteForceProtection annotation is added.
330
+     *
331
+     * @since 12.0.0
332
+     */
333
+    public function throttle() {
334
+        $this->throttled = true;
335
+    }
336
+
337
+    /**
338
+     * Whether the current response is throttled.
339
+     *
340
+     * @since 12.0.0
341
+     */
342
+    public function isThrottled() {
343
+        return $this->throttled;
344
+    }
345 345
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Publishing/PublishPlugin.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@
 block discarded – undo
134 134
 	 * @param RequestInterface $request
135 135
 	 * @param ResponseInterface $response
136 136
 	 *
137
-	 * @return void|bool
137
+	 * @return null|false
138 138
 	 */
139 139
 	public function httpPost(RequestInterface $request, ResponseInterface $response) {
140 140
 		$path = $request->getPath();
Please login to merge, or discard this patch.
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -34,194 +34,194 @@
 block discarded – undo
34 34
 use OCP\IConfig;
35 35
 
36 36
 class PublishPlugin extends ServerPlugin {
37
-	const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
38
-
39
-	/**
40
-	 * Reference to SabreDAV server object.
41
-	 *
42
-	 * @var \Sabre\DAV\Server
43
-	 */
44
-	protected $server;
45
-
46
-	/**
47
-	 * Config instance to get instance secret.
48
-	 *
49
-	 * @var IConfig
50
-	 */
51
-	protected $config;
52
-
53
-	/**
54
-	 * URL Generator for absolute URLs.
55
-	 *
56
-	 * @var IURLGenerator
57
-	 */
58
-	protected $urlGenerator;
59
-
60
-	/**
61
-	 * PublishPlugin constructor.
62
-	 *
63
-	 * @param IConfig $config
64
-	 * @param IURLGenerator $urlGenerator
65
-	 */
66
-	public function __construct(IConfig $config, IURLGenerator $urlGenerator) {
67
-		$this->config = $config;
68
-		$this->urlGenerator = $urlGenerator;
69
-	}
70
-
71
-	/**
72
-	 * This method should return a list of server-features.
73
-	 *
74
-	 * This is for example 'versioning' and is added to the DAV: header
75
-	 * in an OPTIONS response.
76
-	 *
77
-	 * @return string[]
78
-	 */
79
-	public function getFeatures() {
80
-		// May have to be changed to be detected
81
-		return ['oc-calendar-publishing', 'calendarserver-sharing'];
82
-	}
83
-
84
-	/**
85
-	 * Returns a plugin name.
86
-	 *
87
-	 * Using this name other plugins will be able to access other plugins
88
-	 * using Sabre\DAV\Server::getPlugin
89
-	 *
90
-	 * @return string
91
-	 */
92
-	public function getPluginName()	{
93
-		return 'oc-calendar-publishing';
94
-	}
95
-
96
-	/**
97
-	 * This initializes the plugin.
98
-	 *
99
-	 * This function is called by Sabre\DAV\Server, after
100
-	 * addPlugin is called.
101
-	 *
102
-	 * This method should set up the required event subscriptions.
103
-	 *
104
-	 * @param Server $server
105
-	 */
106
-	public function initialize(Server $server) {
107
-		$this->server = $server;
108
-
109
-		$this->server->on('method:POST', [$this, 'httpPost']);
110
-		$this->server->on('propFind',    [$this, 'propFind']);
111
-	}
112
-
113
-	public function propFind(PropFind $propFind, INode $node) {
114
-		if ($node instanceof Calendar) {
115
-			$propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) {
116
-				if ($node->getPublishStatus()) {
117
-					// We return the publish-url only if the calendar is published.
118
-					$token = $node->getPublishStatus();
119
-					$publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token;
120
-
121
-					return new Publisher($publishUrl, true);
122
-				}
123
-			});
124
-
125
-			$propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) {
126
-				return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription());
127
-			});
128
-		}
129
-	}
130
-
131
-	/**
132
-	 * We intercept this to handle POST requests on calendars.
133
-	 *
134
-	 * @param RequestInterface $request
135
-	 * @param ResponseInterface $response
136
-	 *
137
-	 * @return void|bool
138
-	 */
139
-	public function httpPost(RequestInterface $request, ResponseInterface $response) {
140
-		$path = $request->getPath();
141
-
142
-		// Only handling xml
143
-		$contentType = $request->getHeader('Content-Type');
144
-		if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
145
-			return;
146
-		}
147
-
148
-		// Making sure the node exists
149
-		try {
150
-			$node = $this->server->tree->getNodeForPath($path);
151
-		} catch (NotFound $e) {
152
-			return;
153
-		}
154
-
155
-		$requestBody = $request->getBodyAsString();
156
-
157
-		// If this request handler could not deal with this POST request, it
158
-		// will return 'null' and other plugins get a chance to handle the
159
-		// request.
160
-		//
161
-		// However, we already requested the full body. This is a problem,
162
-		// because a body can only be read once. This is why we preemptively
163
-		// re-populated the request body with the existing data.
164
-		$request->setBody($requestBody);
165
-
166
-		$this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
167
-
168
-		switch ($documentType) {
169
-
170
-			case '{'.self::NS_CALENDARSERVER.'}publish-calendar' :
171
-
172
-			// We can only deal with IShareableCalendar objects
173
-			if (!$node instanceof Calendar) {
174
-				return;
175
-			}
176
-			$this->server->transactionType = 'post-publish-calendar';
177
-
178
-			// Getting ACL info
179
-			$acl = $this->server->getPlugin('acl');
180
-
181
-			// If there's no ACL support, we allow everything
182
-			if ($acl) {
183
-				$acl->checkPrivileges($path, '{DAV:}write');
184
-			}
185
-
186
-			$node->setPublishStatus(true);
187
-
188
-			// iCloud sends back the 202, so we will too.
189
-			$response->setStatus(202);
190
-
191
-			// Adding this because sending a response body may cause issues,
192
-			// and I wanted some type of indicator the response was handled.
193
-			$response->setHeader('X-Sabre-Status', 'everything-went-well');
194
-
195
-			// Breaking the event chain
196
-			return false;
197
-
198
-			case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' :
199
-
200
-			// We can only deal with IShareableCalendar objects
201
-			if (!$node instanceof Calendar) {
202
-				return;
203
-			}
204
-			$this->server->transactionType = 'post-unpublish-calendar';
205
-
206
-			// Getting ACL info
207
-			$acl = $this->server->getPlugin('acl');
208
-
209
-			// If there's no ACL support, we allow everything
210
-			if ($acl) {
211
-				$acl->checkPrivileges($path, '{DAV:}write');
212
-			}
213
-
214
-			$node->setPublishStatus(false);
215
-
216
-			$response->setStatus(200);
217
-
218
-			// Adding this because sending a response body may cause issues,
219
-			// and I wanted some type of indicator the response was handled.
220
-			$response->setHeader('X-Sabre-Status', 'everything-went-well');
221
-
222
-			// Breaking the event chain
223
-			return false;
37
+    const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
38
+
39
+    /**
40
+     * Reference to SabreDAV server object.
41
+     *
42
+     * @var \Sabre\DAV\Server
43
+     */
44
+    protected $server;
45
+
46
+    /**
47
+     * Config instance to get instance secret.
48
+     *
49
+     * @var IConfig
50
+     */
51
+    protected $config;
52
+
53
+    /**
54
+     * URL Generator for absolute URLs.
55
+     *
56
+     * @var IURLGenerator
57
+     */
58
+    protected $urlGenerator;
59
+
60
+    /**
61
+     * PublishPlugin constructor.
62
+     *
63
+     * @param IConfig $config
64
+     * @param IURLGenerator $urlGenerator
65
+     */
66
+    public function __construct(IConfig $config, IURLGenerator $urlGenerator) {
67
+        $this->config = $config;
68
+        $this->urlGenerator = $urlGenerator;
69
+    }
70
+
71
+    /**
72
+     * This method should return a list of server-features.
73
+     *
74
+     * This is for example 'versioning' and is added to the DAV: header
75
+     * in an OPTIONS response.
76
+     *
77
+     * @return string[]
78
+     */
79
+    public function getFeatures() {
80
+        // May have to be changed to be detected
81
+        return ['oc-calendar-publishing', 'calendarserver-sharing'];
82
+    }
83
+
84
+    /**
85
+     * Returns a plugin name.
86
+     *
87
+     * Using this name other plugins will be able to access other plugins
88
+     * using Sabre\DAV\Server::getPlugin
89
+     *
90
+     * @return string
91
+     */
92
+    public function getPluginName()	{
93
+        return 'oc-calendar-publishing';
94
+    }
95
+
96
+    /**
97
+     * This initializes the plugin.
98
+     *
99
+     * This function is called by Sabre\DAV\Server, after
100
+     * addPlugin is called.
101
+     *
102
+     * This method should set up the required event subscriptions.
103
+     *
104
+     * @param Server $server
105
+     */
106
+    public function initialize(Server $server) {
107
+        $this->server = $server;
108
+
109
+        $this->server->on('method:POST', [$this, 'httpPost']);
110
+        $this->server->on('propFind',    [$this, 'propFind']);
111
+    }
112
+
113
+    public function propFind(PropFind $propFind, INode $node) {
114
+        if ($node instanceof Calendar) {
115
+            $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) {
116
+                if ($node->getPublishStatus()) {
117
+                    // We return the publish-url only if the calendar is published.
118
+                    $token = $node->getPublishStatus();
119
+                    $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token;
120
+
121
+                    return new Publisher($publishUrl, true);
122
+                }
123
+            });
124
+
125
+            $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) {
126
+                return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription());
127
+            });
128
+        }
129
+    }
130
+
131
+    /**
132
+     * We intercept this to handle POST requests on calendars.
133
+     *
134
+     * @param RequestInterface $request
135
+     * @param ResponseInterface $response
136
+     *
137
+     * @return void|bool
138
+     */
139
+    public function httpPost(RequestInterface $request, ResponseInterface $response) {
140
+        $path = $request->getPath();
141
+
142
+        // Only handling xml
143
+        $contentType = $request->getHeader('Content-Type');
144
+        if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
145
+            return;
146
+        }
147
+
148
+        // Making sure the node exists
149
+        try {
150
+            $node = $this->server->tree->getNodeForPath($path);
151
+        } catch (NotFound $e) {
152
+            return;
153
+        }
154
+
155
+        $requestBody = $request->getBodyAsString();
156
+
157
+        // If this request handler could not deal with this POST request, it
158
+        // will return 'null' and other plugins get a chance to handle the
159
+        // request.
160
+        //
161
+        // However, we already requested the full body. This is a problem,
162
+        // because a body can only be read once. This is why we preemptively
163
+        // re-populated the request body with the existing data.
164
+        $request->setBody($requestBody);
165
+
166
+        $this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
167
+
168
+        switch ($documentType) {
169
+
170
+            case '{'.self::NS_CALENDARSERVER.'}publish-calendar' :
171
+
172
+            // We can only deal with IShareableCalendar objects
173
+            if (!$node instanceof Calendar) {
174
+                return;
175
+            }
176
+            $this->server->transactionType = 'post-publish-calendar';
177
+
178
+            // Getting ACL info
179
+            $acl = $this->server->getPlugin('acl');
180
+
181
+            // If there's no ACL support, we allow everything
182
+            if ($acl) {
183
+                $acl->checkPrivileges($path, '{DAV:}write');
184
+            }
185
+
186
+            $node->setPublishStatus(true);
187
+
188
+            // iCloud sends back the 202, so we will too.
189
+            $response->setStatus(202);
190
+
191
+            // Adding this because sending a response body may cause issues,
192
+            // and I wanted some type of indicator the response was handled.
193
+            $response->setHeader('X-Sabre-Status', 'everything-went-well');
194
+
195
+            // Breaking the event chain
196
+            return false;
197
+
198
+            case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' :
199
+
200
+            // We can only deal with IShareableCalendar objects
201
+            if (!$node instanceof Calendar) {
202
+                return;
203
+            }
204
+            $this->server->transactionType = 'post-unpublish-calendar';
205
+
206
+            // Getting ACL info
207
+            $acl = $this->server->getPlugin('acl');
208
+
209
+            // If there's no ACL support, we allow everything
210
+            if ($acl) {
211
+                $acl->checkPrivileges($path, '{DAV:}write');
212
+            }
213
+
214
+            $node->setPublishStatus(false);
215
+
216
+            $response->setStatus(200);
217
+
218
+            // Adding this because sending a response body may cause issues,
219
+            // and I wanted some type of indicator the response was handled.
220
+            $response->setHeader('X-Sabre-Status', 'everything-went-well');
221
+
222
+            // Breaking the event chain
223
+            return false;
224 224
 
225
-		}
226
-	}
225
+        }
226
+    }
227 227
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	 *
90 90
 	 * @return string
91 91
 	 */
92
-	public function getPluginName()	{
92
+	public function getPluginName() {
93 93
 		return 'oc-calendar-publishing';
94 94
 	}
95 95
 
@@ -107,12 +107,12 @@  discard block
 block discarded – undo
107 107
 		$this->server = $server;
108 108
 
109 109
 		$this->server->on('method:POST', [$this, 'httpPost']);
110
-		$this->server->on('propFind',    [$this, 'propFind']);
110
+		$this->server->on('propFind', [$this, 'propFind']);
111 111
 	}
112 112
 
113 113
 	public function propFind(PropFind $propFind, INode $node) {
114 114
 		if ($node instanceof Calendar) {
115
-			$propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) {
115
+			$propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function() use ($node) {
116 116
 				if ($node->getPublishStatus()) {
117 117
 					// We return the publish-url only if the calendar is published.
118 118
 					$token = $node->getPublishStatus();
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/AddressBookRoot.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
 
31 31
 	/**
32 32
 	 * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend
33
-	 * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend
33
+	 * @param CardDavBackend $carddavBackend
34 34
 	 * @param string $principalPrefix
35 35
 	 */
36 36
 	public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') {
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -25,46 +25,46 @@
 block discarded – undo
25 25
 
26 26
 class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot {
27 27
 
28
-	/** @var IL10N */
29
-	protected $l10n;
28
+    /** @var IL10N */
29
+    protected $l10n;
30 30
 
31
-	/**
32
-	 * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend
33
-	 * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend
34
-	 * @param string $principalPrefix
35
-	 */
36
-	public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') {
37
-		parent::__construct($principalBackend, $carddavBackend, $principalPrefix);
38
-		$this->l10n = \OC::$server->getL10N('dav');
39
-	}
31
+    /**
32
+     * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend
33
+     * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend
34
+     * @param string $principalPrefix
35
+     */
36
+    public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') {
37
+        parent::__construct($principalBackend, $carddavBackend, $principalPrefix);
38
+        $this->l10n = \OC::$server->getL10N('dav');
39
+    }
40 40
 
41
-	/**
42
-	 * This method returns a node for a principal.
43
-	 *
44
-	 * The passed array contains principal information, and is guaranteed to
45
-	 * at least contain a uri item. Other properties may or may not be
46
-	 * supplied by the authentication backend.
47
-	 *
48
-	 * @param array $principal
49
-	 * @return \Sabre\DAV\INode
50
-	 */
51
-	function getChildForPrincipal(array $principal) {
41
+    /**
42
+     * This method returns a node for a principal.
43
+     *
44
+     * The passed array contains principal information, and is guaranteed to
45
+     * at least contain a uri item. Other properties may or may not be
46
+     * supplied by the authentication backend.
47
+     *
48
+     * @param array $principal
49
+     * @return \Sabre\DAV\INode
50
+     */
51
+    function getChildForPrincipal(array $principal) {
52 52
 
53
-		return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->l10n);
53
+        return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->l10n);
54 54
 
55
-	}
55
+    }
56 56
 
57
-	function getName() {
57
+    function getName() {
58 58
 
59
-		if ($this->principalPrefix === 'principals') {
60
-			return parent::getName();
61
-		}
62
-		// Grabbing all the components of the principal path.
63
-		$parts = explode('/', $this->principalPrefix);
59
+        if ($this->principalPrefix === 'principals') {
60
+            return parent::getName();
61
+        }
62
+        // Grabbing all the components of the principal path.
63
+        $parts = explode('/', $this->principalPrefix);
64 64
 
65
-		// We are only interested in the second part.
66
-		return $parts[1];
65
+        // We are only interested in the second part.
66
+        return $parts[1];
67 67
 
68
-	}
68
+    }
69 69
 
70 70
 }
Please login to merge, or discard this patch.