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