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