Completed
Pull Request — master (#4887)
by Julius
47:52 queued 26:52
created
apps/theming/lib/Util.php 4 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	/**
72 72
 	 * get color for on-page elements:
73 73
 	 * theme color by default, grey if theme color is to bright
74
-	 * @param $color
74
+	 * @param string $color
75 75
 	 * @return string
76 76
 	 */
77 77
 	public function elementColor($color) {
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 
115 115
 	/**
116 116
 	 * @param $app string app name
117
-	 * @return string|ISimpleFile path to app icon / file of logo
117
+	 * @return string path to app icon / file of logo
118 118
 	 */
119 119
 	public function getAppIcon($app) {
120 120
 		$app = str_replace(array('\0', '/', '\\', '..'), '', $app);
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
 	/**
191 191
 	 * replace default color with a custom one
192 192
 	 *
193
-	 * @param $svg string content of a svg file
194
-	 * @param $color string color to match
193
+	 * @param string $svg string content of a svg file
194
+	 * @param string $color string color to match
195 195
 	 * @return string
196 196
 	 */
197 197
 	public function colorizeSvg($svg, $color) {
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,6 @@
 block discarded – undo
29 29
 use OCP\Files\NotFoundException;
30 30
 use OCP\Files\SimpleFS\ISimpleFile;
31 31
 use OCP\IConfig;
32
-use OCP\Files\IRootFolder;
33 32
 
34 33
 class Util {
35 34
 
Please login to merge, or discard this patch.
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -33,170 +33,170 @@
 block discarded – undo
33 33
 
34 34
 class Util {
35 35
 
36
-	/** @var IConfig */
37
-	private $config;
38
-
39
-	/** @var IAppManager */
40
-	private $appManager;
41
-
42
-	/** @var IAppData */
43
-	private $appData;
44
-
45
-	/**
46
-	 * Util constructor.
47
-	 *
48
-	 * @param IConfig $config
49
-	 * @param IAppManager $appManager
50
-	 * @param IAppData $appData
51
-	 */
52
-	public function __construct(IConfig $config, IAppManager $appManager, IAppData $appData) {
53
-		$this->config = $config;
54
-		$this->appManager = $appManager;
55
-		$this->appData = $appData;
56
-	}
57
-
58
-	/**
59
-	 * @param string $color rgb color value
60
-	 * @return bool
61
-	 */
62
-	public function invertTextColor($color) {
63
-		$l = $this->calculateLuminance($color);
64
-		if($l>0.5) {
65
-			return true;
66
-		} else {
67
-			return false;
68
-		}
69
-	}
70
-
71
-	/**
72
-	 * get color for on-page elements:
73
-	 * theme color by default, grey if theme color is to bright
74
-	 * @param $color
75
-	 * @return string
76
-	 */
77
-	public function elementColor($color) {
78
-		$l = $this->calculateLuminance($color);
79
-		if($l>0.8) {
80
-			return '#555555';
81
-		} else {
82
-			return $color;
83
-		}
84
-	}
85
-
86
-	/**
87
-	 * @param string $color rgb color value
88
-	 * @return float
89
-	 */
90
-	public function calculateLuminance($color) {
91
-		$hex = preg_replace("/[^0-9A-Fa-f]/", '', $color);
92
-		if (strlen($hex) === 3) {
93
-			$hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2};
94
-		}
95
-		if (strlen($hex) !== 6) {
96
-			return 0;
97
-		}
98
-		$r = hexdec(substr($hex, 0, 2));
99
-		$g = hexdec(substr($hex, 2, 2));
100
-		$b = hexdec(substr($hex, 4, 2));
101
-		return (0.299 * $r + 0.587 * $g + 0.114 * $b)/255;
102
-	}
103
-
104
-	/**
105
-	 * @param $color
106
-	 * @return string base64 encoded radio button svg
107
-	 */
108
-	public function generateRadioButton($color) {
109
-		$radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' .
110
-			'<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>';
111
-		return base64_encode($radioButtonIcon);
112
-	}
113
-
114
-
115
-	/**
116
-	 * @param $app string app name
117
-	 * @return string|ISimpleFile path to app icon / file of logo
118
-	 */
119
-	public function getAppIcon($app) {
120
-		$app = str_replace(array('\0', '/', '\\', '..'), '', $app);
121
-		try {
122
-			$appPath = $this->appManager->getAppPath($app);
123
-			$icon = $appPath . '/img/' . $app . '.svg';
124
-			if (file_exists($icon)) {
125
-				return $icon;
126
-			}
127
-			$icon = $appPath . '/img/app.svg';
128
-			if (file_exists($icon)) {
129
-				return $icon;
130
-			}
131
-		} catch (AppPathNotFoundException $e) {}
132
-
133
-		if ($this->config->getAppValue('theming', 'logoMime', '') !== '') {
134
-			$logoFile = null;
135
-			try {
136
-				$folder = $this->appData->getFolder('images');
137
-				if ($folder !== null) {
138
-					return $folder->getFile('logo');
139
-				}
140
-			} catch (NotFoundException $e) {}
141
-		}
142
-		return \OC::$SERVERROOT . '/core/img/logo.svg';
143
-	}
144
-
145
-	/**
146
-	 * @param $app string app name
147
-	 * @param $image string relative path to image in app folder
148
-	 * @return string|false absolute path to image
149
-	 */
150
-	public function getAppImage($app, $image) {
151
-		$app = str_replace(array('\0', '/', '\\', '..'), '', $app);
152
-		$image = str_replace(array('\0', '\\', '..'), '', $image);
153
-		if ($app === "core") {
154
-			$icon = \OC::$SERVERROOT . '/core/img/' . $image;
155
-			if (file_exists($icon)) {
156
-				return $icon;
157
-			}
158
-		}
159
-
160
-		try {
161
-			$appPath = $this->appManager->getAppPath($app);
162
-		} catch (AppPathNotFoundException $e) {
163
-			return false;
164
-		}
165
-
166
-		$icon = $appPath . '/img/' . $image;
167
-		if (file_exists($icon)) {
168
-			return $icon;
169
-		}
170
-		$icon = $appPath . '/img/' . $image . '.svg';
171
-		if (file_exists($icon)) {
172
-			return $icon;
173
-		}
174
-		$icon = $appPath . '/img/' . $image . '.png';
175
-		if (file_exists($icon)) {
176
-			return $icon;
177
-		}
178
-		$icon = $appPath . '/img/' . $image . '.gif';
179
-		if (file_exists($icon)) {
180
-			return $icon;
181
-		}
182
-		$icon = $appPath . '/img/' . $image . '.jpg';
183
-		if (file_exists($icon)) {
184
-			return $icon;
185
-		}
186
-
187
-		return false;
188
-	}
189
-
190
-	/**
191
-	 * replace default color with a custom one
192
-	 *
193
-	 * @param $svg string content of a svg file
194
-	 * @param $color string color to match
195
-	 * @return string
196
-	 */
197
-	public function colorizeSvg($svg, $color) {
198
-		$svg = preg_replace('/#0082c9/i', $color, $svg);
199
-		return $svg;
200
-	}
36
+    /** @var IConfig */
37
+    private $config;
38
+
39
+    /** @var IAppManager */
40
+    private $appManager;
41
+
42
+    /** @var IAppData */
43
+    private $appData;
44
+
45
+    /**
46
+     * Util constructor.
47
+     *
48
+     * @param IConfig $config
49
+     * @param IAppManager $appManager
50
+     * @param IAppData $appData
51
+     */
52
+    public function __construct(IConfig $config, IAppManager $appManager, IAppData $appData) {
53
+        $this->config = $config;
54
+        $this->appManager = $appManager;
55
+        $this->appData = $appData;
56
+    }
57
+
58
+    /**
59
+     * @param string $color rgb color value
60
+     * @return bool
61
+     */
62
+    public function invertTextColor($color) {
63
+        $l = $this->calculateLuminance($color);
64
+        if($l>0.5) {
65
+            return true;
66
+        } else {
67
+            return false;
68
+        }
69
+    }
70
+
71
+    /**
72
+     * get color for on-page elements:
73
+     * theme color by default, grey if theme color is to bright
74
+     * @param $color
75
+     * @return string
76
+     */
77
+    public function elementColor($color) {
78
+        $l = $this->calculateLuminance($color);
79
+        if($l>0.8) {
80
+            return '#555555';
81
+        } else {
82
+            return $color;
83
+        }
84
+    }
85
+
86
+    /**
87
+     * @param string $color rgb color value
88
+     * @return float
89
+     */
90
+    public function calculateLuminance($color) {
91
+        $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color);
92
+        if (strlen($hex) === 3) {
93
+            $hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2};
94
+        }
95
+        if (strlen($hex) !== 6) {
96
+            return 0;
97
+        }
98
+        $r = hexdec(substr($hex, 0, 2));
99
+        $g = hexdec(substr($hex, 2, 2));
100
+        $b = hexdec(substr($hex, 4, 2));
101
+        return (0.299 * $r + 0.587 * $g + 0.114 * $b)/255;
102
+    }
103
+
104
+    /**
105
+     * @param $color
106
+     * @return string base64 encoded radio button svg
107
+     */
108
+    public function generateRadioButton($color) {
109
+        $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' .
110
+            '<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>';
111
+        return base64_encode($radioButtonIcon);
112
+    }
113
+
114
+
115
+    /**
116
+     * @param $app string app name
117
+     * @return string|ISimpleFile path to app icon / file of logo
118
+     */
119
+    public function getAppIcon($app) {
120
+        $app = str_replace(array('\0', '/', '\\', '..'), '', $app);
121
+        try {
122
+            $appPath = $this->appManager->getAppPath($app);
123
+            $icon = $appPath . '/img/' . $app . '.svg';
124
+            if (file_exists($icon)) {
125
+                return $icon;
126
+            }
127
+            $icon = $appPath . '/img/app.svg';
128
+            if (file_exists($icon)) {
129
+                return $icon;
130
+            }
131
+        } catch (AppPathNotFoundException $e) {}
132
+
133
+        if ($this->config->getAppValue('theming', 'logoMime', '') !== '') {
134
+            $logoFile = null;
135
+            try {
136
+                $folder = $this->appData->getFolder('images');
137
+                if ($folder !== null) {
138
+                    return $folder->getFile('logo');
139
+                }
140
+            } catch (NotFoundException $e) {}
141
+        }
142
+        return \OC::$SERVERROOT . '/core/img/logo.svg';
143
+    }
144
+
145
+    /**
146
+     * @param $app string app name
147
+     * @param $image string relative path to image in app folder
148
+     * @return string|false absolute path to image
149
+     */
150
+    public function getAppImage($app, $image) {
151
+        $app = str_replace(array('\0', '/', '\\', '..'), '', $app);
152
+        $image = str_replace(array('\0', '\\', '..'), '', $image);
153
+        if ($app === "core") {
154
+            $icon = \OC::$SERVERROOT . '/core/img/' . $image;
155
+            if (file_exists($icon)) {
156
+                return $icon;
157
+            }
158
+        }
159
+
160
+        try {
161
+            $appPath = $this->appManager->getAppPath($app);
162
+        } catch (AppPathNotFoundException $e) {
163
+            return false;
164
+        }
165
+
166
+        $icon = $appPath . '/img/' . $image;
167
+        if (file_exists($icon)) {
168
+            return $icon;
169
+        }
170
+        $icon = $appPath . '/img/' . $image . '.svg';
171
+        if (file_exists($icon)) {
172
+            return $icon;
173
+        }
174
+        $icon = $appPath . '/img/' . $image . '.png';
175
+        if (file_exists($icon)) {
176
+            return $icon;
177
+        }
178
+        $icon = $appPath . '/img/' . $image . '.gif';
179
+        if (file_exists($icon)) {
180
+            return $icon;
181
+        }
182
+        $icon = $appPath . '/img/' . $image . '.jpg';
183
+        if (file_exists($icon)) {
184
+            return $icon;
185
+        }
186
+
187
+        return false;
188
+    }
189
+
190
+    /**
191
+     * replace default color with a custom one
192
+     *
193
+     * @param $svg string content of a svg file
194
+     * @param $color string color to match
195
+     * @return string
196
+     */
197
+    public function colorizeSvg($svg, $color) {
198
+        $svg = preg_replace('/#0082c9/i', $color, $svg);
199
+        return $svg;
200
+    }
201 201
 
202 202
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	public function invertTextColor($color) {
63 63
 		$l = $this->calculateLuminance($color);
64
-		if($l>0.5) {
64
+		if ($l > 0.5) {
65 65
 			return true;
66 66
 		} else {
67 67
 			return false;
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	 */
77 77
 	public function elementColor($color) {
78 78
 		$l = $this->calculateLuminance($color);
79
-		if($l>0.8) {
79
+		if ($l > 0.8) {
80 80
 			return '#555555';
81 81
 		} else {
82 82
 			return $color;
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	public function calculateLuminance($color) {
91 91
 		$hex = preg_replace("/[^0-9A-Fa-f]/", '', $color);
92 92
 		if (strlen($hex) === 3) {
93
-			$hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2};
93
+			$hex = $hex{0}.$hex{0}.$hex{1}.$hex{1}.$hex{2}.$hex{2};
94 94
 		}
95 95
 		if (strlen($hex) !== 6) {
96 96
 			return 0;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		$r = hexdec(substr($hex, 0, 2));
99 99
 		$g = hexdec(substr($hex, 2, 2));
100 100
 		$b = hexdec(substr($hex, 4, 2));
101
-		return (0.299 * $r + 0.587 * $g + 0.114 * $b)/255;
101
+		return (0.299 * $r + 0.587 * $g + 0.114 * $b) / 255;
102 102
 	}
103 103
 
104 104
 	/**
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @return string base64 encoded radio button svg
107 107
 	 */
108 108
 	public function generateRadioButton($color) {
109
-		$radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' .
109
+		$radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">'.
110 110
 			'<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>';
111 111
 		return base64_encode($radioButtonIcon);
112 112
 	}
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
 		$app = str_replace(array('\0', '/', '\\', '..'), '', $app);
121 121
 		try {
122 122
 			$appPath = $this->appManager->getAppPath($app);
123
-			$icon = $appPath . '/img/' . $app . '.svg';
123
+			$icon = $appPath.'/img/'.$app.'.svg';
124 124
 			if (file_exists($icon)) {
125 125
 				return $icon;
126 126
 			}
127
-			$icon = $appPath . '/img/app.svg';
127
+			$icon = $appPath.'/img/app.svg';
128 128
 			if (file_exists($icon)) {
129 129
 				return $icon;
130 130
 			}
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 				}
140 140
 			} catch (NotFoundException $e) {}
141 141
 		}
142
-		return \OC::$SERVERROOT . '/core/img/logo.svg';
142
+		return \OC::$SERVERROOT.'/core/img/logo.svg';
143 143
 	}
144 144
 
145 145
 	/**
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 		$app = str_replace(array('\0', '/', '\\', '..'), '', $app);
152 152
 		$image = str_replace(array('\0', '\\', '..'), '', $image);
153 153
 		if ($app === "core") {
154
-			$icon = \OC::$SERVERROOT . '/core/img/' . $image;
154
+			$icon = \OC::$SERVERROOT.'/core/img/'.$image;
155 155
 			if (file_exists($icon)) {
156 156
 				return $icon;
157 157
 			}
@@ -163,23 +163,23 @@  discard block
 block discarded – undo
163 163
 			return false;
164 164
 		}
165 165
 
166
-		$icon = $appPath . '/img/' . $image;
166
+		$icon = $appPath.'/img/'.$image;
167 167
 		if (file_exists($icon)) {
168 168
 			return $icon;
169 169
 		}
170
-		$icon = $appPath . '/img/' . $image . '.svg';
170
+		$icon = $appPath.'/img/'.$image.'.svg';
171 171
 		if (file_exists($icon)) {
172 172
 			return $icon;
173 173
 		}
174
-		$icon = $appPath . '/img/' . $image . '.png';
174
+		$icon = $appPath.'/img/'.$image.'.png';
175 175
 		if (file_exists($icon)) {
176 176
 			return $icon;
177 177
 		}
178
-		$icon = $appPath . '/img/' . $image . '.gif';
178
+		$icon = $appPath.'/img/'.$image.'.gif';
179 179
 		if (file_exists($icon)) {
180 180
 			return $icon;
181 181
 		}
182
-		$icon = $appPath . '/img/' . $image . '.jpg';
182
+		$icon = $appPath.'/img/'.$image.'.jpg';
183 183
 		if (file_exists($icon)) {
184 184
 			return $icon;
185 185
 		}
Please login to merge, or discard this patch.
lib/private/Server.php 1 patch
Indentation   +1629 added lines, -1629 removed lines patch added patch discarded remove patch
@@ -126,1638 +126,1638 @@
 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', 'logout', function () {
365
-				\OC_Hook::emit('OC_User', 'logout', array());
366
-			});
367
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
368
-				/** @var $user \OC\User\User */
369
-				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
370
-			});
371
-			return $userSession;
372
-		});
373
-		$this->registerAlias('UserSession', \OCP\IUserSession::class);
374
-
375
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
376
-			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
377
-		});
378
-
379
-		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
380
-		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
381
-
382
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
383
-			return new \OC\AllConfig(
384
-				$c->getSystemConfig()
385
-			);
386
-		});
387
-		$this->registerAlias('AllConfig', \OC\AllConfig::class);
388
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
389
-
390
-		$this->registerService('SystemConfig', function ($c) use ($config) {
391
-			return new \OC\SystemConfig($config);
392
-		});
393
-
394
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
395
-			return new \OC\AppConfig($c->getDatabaseConnection());
396
-		});
397
-		$this->registerAlias('AppConfig', \OC\AppConfig::class);
398
-		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
399
-
400
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
401
-			return new \OC\L10N\Factory(
402
-				$c->getConfig(),
403
-				$c->getRequest(),
404
-				$c->getUserSession(),
405
-				\OC::$SERVERROOT
406
-			);
407
-		});
408
-		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
409
-
410
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
411
-			$config = $c->getConfig();
412
-			$cacheFactory = $c->getMemCacheFactory();
413
-			return new \OC\URLGenerator(
414
-				$config,
415
-				$cacheFactory
416
-			);
417
-		});
418
-		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
419
-
420
-		$this->registerService('AppHelper', function ($c) {
421
-			return new \OC\AppHelper();
422
-		});
423
-		$this->registerAlias('AppFetcher', AppFetcher::class);
424
-		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
425
-
426
-		$this->registerService(\OCP\ICache::class, function ($c) {
427
-			return new Cache\File();
428
-		});
429
-		$this->registerAlias('UserCache', \OCP\ICache::class);
430
-
431
-		$this->registerService(Factory::class, function (Server $c) {
432
-			$config = $c->getConfig();
433
-
434
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
435
-				$v = \OC_App::getAppVersions();
436
-				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
437
-				$version = implode(',', $v);
438
-				$instanceId = \OC_Util::getInstanceId();
439
-				$path = \OC::$SERVERROOT;
440
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
441
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
442
-					$config->getSystemValue('memcache.local', null),
443
-					$config->getSystemValue('memcache.distributed', null),
444
-					$config->getSystemValue('memcache.locking', null)
445
-				);
446
-			}
447
-
448
-			return new \OC\Memcache\Factory('', $c->getLogger(),
449
-				'\\OC\\Memcache\\ArrayCache',
450
-				'\\OC\\Memcache\\ArrayCache',
451
-				'\\OC\\Memcache\\ArrayCache'
452
-			);
453
-		});
454
-		$this->registerAlias('MemCacheFactory', Factory::class);
455
-		$this->registerAlias(ICacheFactory::class, Factory::class);
456
-
457
-		$this->registerService('RedisFactory', function (Server $c) {
458
-			$systemConfig = $c->getSystemConfig();
459
-			return new RedisFactory($systemConfig);
460
-		});
461
-
462
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
463
-			return new \OC\Activity\Manager(
464
-				$c->getRequest(),
465
-				$c->getUserSession(),
466
-				$c->getConfig(),
467
-				$c->query(IValidator::class)
468
-			);
469
-		});
470
-		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
471
-
472
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
473
-			return new \OC\Activity\EventMerger(
474
-				$c->getL10N('lib')
475
-			);
476
-		});
477
-		$this->registerAlias(IValidator::class, Validator::class);
478
-
479
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
480
-			return new AvatarManager(
481
-				$c->getUserManager(),
482
-				$c->getAppDataDir('avatar'),
483
-				$c->getL10N('lib'),
484
-				$c->getLogger(),
485
-				$c->getConfig()
486
-			);
487
-		});
488
-		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
489
-
490
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
491
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
492
-			$logger = Log::getLogClass($logType);
493
-			call_user_func(array($logger, 'init'));
494
-
495
-			return new Log($logger);
496
-		});
497
-		$this->registerAlias('Logger', \OCP\ILogger::class);
498
-
499
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
500
-			$config = $c->getConfig();
501
-			return new \OC\BackgroundJob\JobList(
502
-				$c->getDatabaseConnection(),
503
-				$config,
504
-				new TimeFactory()
505
-			);
506
-		});
507
-		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
508
-
509
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
510
-			$cacheFactory = $c->getMemCacheFactory();
511
-			$logger = $c->getLogger();
512
-			if ($cacheFactory->isAvailable()) {
513
-				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
514
-			} else {
515
-				$router = new \OC\Route\Router($logger);
516
-			}
517
-			return $router;
518
-		});
519
-		$this->registerAlias('Router', \OCP\Route\IRouter::class);
520
-
521
-		$this->registerService(\OCP\ISearch::class, function ($c) {
522
-			return new Search();
523
-		});
524
-		$this->registerAlias('Search', \OCP\ISearch::class);
525
-
526
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) {
527
-			return new \OC\Security\RateLimiting\Limiter(
528
-				$this->getUserSession(),
529
-				$this->getRequest(),
530
-				new \OC\AppFramework\Utility\TimeFactory(),
531
-				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
532
-			);
533
-		});
534
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
535
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
536
-				$this->getMemCacheFactory(),
537
-				new \OC\AppFramework\Utility\TimeFactory()
538
-			);
539
-		});
540
-
541
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
542
-			return new SecureRandom();
543
-		});
544
-		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
545
-
546
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
547
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
548
-		});
549
-		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
550
-
551
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
552
-			return new Hasher($c->getConfig());
553
-		});
554
-		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
555
-
556
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
557
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
558
-		});
559
-		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
560
-
561
-		$this->registerService(IDBConnection::class, function (Server $c) {
562
-			$systemConfig = $c->getSystemConfig();
563
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
564
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
565
-			if (!$factory->isValidType($type)) {
566
-				throw new \OC\DatabaseException('Invalid database type');
567
-			}
568
-			$connectionParams = $factory->createConnectionParams();
569
-			$connection = $factory->getConnection($type, $connectionParams);
570
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
571
-			return $connection;
572
-		});
573
-		$this->registerAlias('DatabaseConnection', IDBConnection::class);
574
-
575
-		$this->registerService('HTTPHelper', function (Server $c) {
576
-			$config = $c->getConfig();
577
-			return new HTTPHelper(
578
-				$config,
579
-				$c->getHTTPClientService()
580
-			);
581
-		});
582
-
583
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
584
-			$user = \OC_User::getUser();
585
-			$uid = $user ? $user : null;
586
-			return new ClientService(
587
-				$c->getConfig(),
588
-				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
589
-			);
590
-		});
591
-		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
592
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
593
-			$eventLogger = new EventLogger();
594
-			if ($c->getSystemConfig()->getValue('debug', false)) {
595
-				// In debug mode, module is being activated by default
596
-				$eventLogger->activate();
597
-			}
598
-			return $eventLogger;
599
-		});
600
-		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
601
-
602
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
603
-			$queryLogger = new QueryLogger();
604
-			if ($c->getSystemConfig()->getValue('debug', false)) {
605
-				// In debug mode, module is being activated by default
606
-				$queryLogger->activate();
607
-			}
608
-			return $queryLogger;
609
-		});
610
-		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
611
-
612
-		$this->registerService(TempManager::class, function (Server $c) {
613
-			return new TempManager(
614
-				$c->getLogger(),
615
-				$c->getConfig()
616
-			);
617
-		});
618
-		$this->registerAlias('TempManager', TempManager::class);
619
-		$this->registerAlias(ITempManager::class, TempManager::class);
620
-
621
-		$this->registerService(AppManager::class, function (Server $c) {
622
-			return new \OC\App\AppManager(
623
-				$c->getUserSession(),
624
-				$c->getAppConfig(),
625
-				$c->getGroupManager(),
626
-				$c->getMemCacheFactory(),
627
-				$c->getEventDispatcher()
628
-			);
629
-		});
630
-		$this->registerAlias('AppManager', AppManager::class);
631
-		$this->registerAlias(IAppManager::class, AppManager::class);
632
-
633
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
634
-			return new DateTimeZone(
635
-				$c->getConfig(),
636
-				$c->getSession()
637
-			);
638
-		});
639
-		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
640
-
641
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
642
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
643
-
644
-			return new DateTimeFormatter(
645
-				$c->getDateTimeZone()->getTimeZone(),
646
-				$c->getL10N('lib', $language)
647
-			);
648
-		});
649
-		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
650
-
651
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
652
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
653
-			$listener = new UserMountCacheListener($mountCache);
654
-			$listener->listen($c->getUserManager());
655
-			return $mountCache;
656
-		});
657
-		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
658
-
659
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
660
-			$loader = \OC\Files\Filesystem::getLoader();
661
-			$mountCache = $c->query('UserMountCache');
662
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
663
-
664
-			// builtin providers
665
-
666
-			$config = $c->getConfig();
667
-			$manager->registerProvider(new CacheMountProvider($config));
668
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
669
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
670
-
671
-			return $manager;
672
-		});
673
-		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
674
-
675
-		$this->registerService('IniWrapper', function ($c) {
676
-			return new IniGetWrapper();
677
-		});
678
-		$this->registerService('AsyncCommandBus', function (Server $c) {
679
-			$jobList = $c->getJobList();
680
-			return new AsyncBus($jobList);
681
-		});
682
-		$this->registerService('TrustedDomainHelper', function ($c) {
683
-			return new TrustedDomainHelper($this->getConfig());
684
-		});
685
-		$this->registerService('Throttler', function(Server $c) {
686
-			return new Throttler(
687
-				$c->getDatabaseConnection(),
688
-				new TimeFactory(),
689
-				$c->getLogger(),
690
-				$c->getConfig()
691
-			);
692
-		});
693
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
694
-			// IConfig and IAppManager requires a working database. This code
695
-			// might however be called when ownCloud is not yet setup.
696
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
697
-				$config = $c->getConfig();
698
-				$appManager = $c->getAppManager();
699
-			} else {
700
-				$config = null;
701
-				$appManager = null;
702
-			}
703
-
704
-			return new Checker(
705
-					new EnvironmentHelper(),
706
-					new FileAccessHelper(),
707
-					new AppLocator(),
708
-					$config,
709
-					$c->getMemCacheFactory(),
710
-					$appManager,
711
-					$c->getTempManager()
712
-			);
713
-		});
714
-		$this->registerService(\OCP\IRequest::class, function ($c) {
715
-			if (isset($this['urlParams'])) {
716
-				$urlParams = $this['urlParams'];
717
-			} else {
718
-				$urlParams = [];
719
-			}
720
-
721
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
722
-				&& in_array('fakeinput', stream_get_wrappers())
723
-			) {
724
-				$stream = 'fakeinput://data';
725
-			} else {
726
-				$stream = 'php://input';
727
-			}
728
-
729
-			return new Request(
730
-				[
731
-					'get' => $_GET,
732
-					'post' => $_POST,
733
-					'files' => $_FILES,
734
-					'server' => $_SERVER,
735
-					'env' => $_ENV,
736
-					'cookies' => $_COOKIE,
737
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
738
-						? $_SERVER['REQUEST_METHOD']
739
-						: null,
740
-					'urlParams' => $urlParams,
741
-				],
742
-				$this->getSecureRandom(),
743
-				$this->getConfig(),
744
-				$this->getCsrfTokenManager(),
745
-				$stream
746
-			);
747
-		});
748
-		$this->registerAlias('Request', \OCP\IRequest::class);
749
-
750
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
751
-			return new Mailer(
752
-				$c->getConfig(),
753
-				$c->getLogger(),
754
-				$c->query(Defaults::class),
755
-				$c->getURLGenerator(),
756
-				$c->getL10N('lib')
757
-			);
758
-		});
759
-		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
760
-
761
-		$this->registerService('LDAPProvider', function(Server $c) {
762
-			$config = $c->getConfig();
763
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
764
-			if(is_null($factoryClass)) {
765
-				throw new \Exception('ldapProviderFactory not set');
766
-			}
767
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
768
-			$factory = new $factoryClass($this);
769
-			return $factory->getLDAPProvider();
770
-		});
771
-		$this->registerService('LockingProvider', function (Server $c) {
772
-			$ini = $c->getIniWrapper();
773
-			$config = $c->getConfig();
774
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
775
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
776
-				/** @var \OC\Memcache\Factory $memcacheFactory */
777
-				$memcacheFactory = $c->getMemCacheFactory();
778
-				$memcache = $memcacheFactory->createLocking('lock');
779
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
780
-					return new MemcacheLockingProvider($memcache, $ttl);
781
-				}
782
-				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
783
-			}
784
-			return new NoopLockingProvider();
785
-		});
786
-
787
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
788
-			return new \OC\Files\Mount\Manager();
789
-		});
790
-		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
791
-
792
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
793
-			return new \OC\Files\Type\Detection(
794
-				$c->getURLGenerator(),
795
-				\OC::$configDir,
796
-				\OC::$SERVERROOT . '/resources/config/'
797
-			);
798
-		});
799
-		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
800
-
801
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
802
-			return new \OC\Files\Type\Loader(
803
-				$c->getDatabaseConnection()
804
-			);
805
-		});
806
-		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
807
-		$this->registerService(BundleFetcher::class, function () {
808
-			return new BundleFetcher($this->getL10N('lib'));
809
-		});
810
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
811
-			return new Manager(
812
-				$c->query(IValidator::class)
813
-			);
814
-		});
815
-		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
816
-
817
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
818
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
819
-			$manager->registerCapability(function () use ($c) {
820
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
821
-			});
822
-			return $manager;
823
-		});
824
-		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
825
-
826
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
827
-			$config = $c->getConfig();
828
-			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
829
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
830
-			$factory = new $factoryClass($this);
831
-			return $factory->getManager();
832
-		});
833
-		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
834
-
835
-		$this->registerService('ThemingDefaults', function(Server $c) {
836
-			/*
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', 'logout', function () {
365
+                \OC_Hook::emit('OC_User', 'logout', array());
366
+            });
367
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
368
+                /** @var $user \OC\User\User */
369
+                \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
370
+            });
371
+            return $userSession;
372
+        });
373
+        $this->registerAlias('UserSession', \OCP\IUserSession::class);
374
+
375
+        $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
376
+            return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
377
+        });
378
+
379
+        $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
380
+        $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
381
+
382
+        $this->registerService(\OC\AllConfig::class, function (Server $c) {
383
+            return new \OC\AllConfig(
384
+                $c->getSystemConfig()
385
+            );
386
+        });
387
+        $this->registerAlias('AllConfig', \OC\AllConfig::class);
388
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
389
+
390
+        $this->registerService('SystemConfig', function ($c) use ($config) {
391
+            return new \OC\SystemConfig($config);
392
+        });
393
+
394
+        $this->registerService(\OC\AppConfig::class, function (Server $c) {
395
+            return new \OC\AppConfig($c->getDatabaseConnection());
396
+        });
397
+        $this->registerAlias('AppConfig', \OC\AppConfig::class);
398
+        $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
399
+
400
+        $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
401
+            return new \OC\L10N\Factory(
402
+                $c->getConfig(),
403
+                $c->getRequest(),
404
+                $c->getUserSession(),
405
+                \OC::$SERVERROOT
406
+            );
407
+        });
408
+        $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
409
+
410
+        $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
411
+            $config = $c->getConfig();
412
+            $cacheFactory = $c->getMemCacheFactory();
413
+            return new \OC\URLGenerator(
414
+                $config,
415
+                $cacheFactory
416
+            );
417
+        });
418
+        $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
419
+
420
+        $this->registerService('AppHelper', function ($c) {
421
+            return new \OC\AppHelper();
422
+        });
423
+        $this->registerAlias('AppFetcher', AppFetcher::class);
424
+        $this->registerAlias('CategoryFetcher', CategoryFetcher::class);
425
+
426
+        $this->registerService(\OCP\ICache::class, function ($c) {
427
+            return new Cache\File();
428
+        });
429
+        $this->registerAlias('UserCache', \OCP\ICache::class);
430
+
431
+        $this->registerService(Factory::class, function (Server $c) {
432
+            $config = $c->getConfig();
433
+
434
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
435
+                $v = \OC_App::getAppVersions();
436
+                $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
437
+                $version = implode(',', $v);
438
+                $instanceId = \OC_Util::getInstanceId();
439
+                $path = \OC::$SERVERROOT;
440
+                $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
441
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
442
+                    $config->getSystemValue('memcache.local', null),
443
+                    $config->getSystemValue('memcache.distributed', null),
444
+                    $config->getSystemValue('memcache.locking', null)
445
+                );
446
+            }
447
+
448
+            return new \OC\Memcache\Factory('', $c->getLogger(),
449
+                '\\OC\\Memcache\\ArrayCache',
450
+                '\\OC\\Memcache\\ArrayCache',
451
+                '\\OC\\Memcache\\ArrayCache'
452
+            );
453
+        });
454
+        $this->registerAlias('MemCacheFactory', Factory::class);
455
+        $this->registerAlias(ICacheFactory::class, Factory::class);
456
+
457
+        $this->registerService('RedisFactory', function (Server $c) {
458
+            $systemConfig = $c->getSystemConfig();
459
+            return new RedisFactory($systemConfig);
460
+        });
461
+
462
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
463
+            return new \OC\Activity\Manager(
464
+                $c->getRequest(),
465
+                $c->getUserSession(),
466
+                $c->getConfig(),
467
+                $c->query(IValidator::class)
468
+            );
469
+        });
470
+        $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
471
+
472
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
473
+            return new \OC\Activity\EventMerger(
474
+                $c->getL10N('lib')
475
+            );
476
+        });
477
+        $this->registerAlias(IValidator::class, Validator::class);
478
+
479
+        $this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
480
+            return new AvatarManager(
481
+                $c->getUserManager(),
482
+                $c->getAppDataDir('avatar'),
483
+                $c->getL10N('lib'),
484
+                $c->getLogger(),
485
+                $c->getConfig()
486
+            );
487
+        });
488
+        $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
489
+
490
+        $this->registerService(\OCP\ILogger::class, function (Server $c) {
491
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
492
+            $logger = Log::getLogClass($logType);
493
+            call_user_func(array($logger, 'init'));
494
+
495
+            return new Log($logger);
496
+        });
497
+        $this->registerAlias('Logger', \OCP\ILogger::class);
498
+
499
+        $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
500
+            $config = $c->getConfig();
501
+            return new \OC\BackgroundJob\JobList(
502
+                $c->getDatabaseConnection(),
503
+                $config,
504
+                new TimeFactory()
505
+            );
506
+        });
507
+        $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
508
+
509
+        $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
510
+            $cacheFactory = $c->getMemCacheFactory();
511
+            $logger = $c->getLogger();
512
+            if ($cacheFactory->isAvailable()) {
513
+                $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
514
+            } else {
515
+                $router = new \OC\Route\Router($logger);
516
+            }
517
+            return $router;
518
+        });
519
+        $this->registerAlias('Router', \OCP\Route\IRouter::class);
520
+
521
+        $this->registerService(\OCP\ISearch::class, function ($c) {
522
+            return new Search();
523
+        });
524
+        $this->registerAlias('Search', \OCP\ISearch::class);
525
+
526
+        $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) {
527
+            return new \OC\Security\RateLimiting\Limiter(
528
+                $this->getUserSession(),
529
+                $this->getRequest(),
530
+                new \OC\AppFramework\Utility\TimeFactory(),
531
+                $c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
532
+            );
533
+        });
534
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
535
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
536
+                $this->getMemCacheFactory(),
537
+                new \OC\AppFramework\Utility\TimeFactory()
538
+            );
539
+        });
540
+
541
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
542
+            return new SecureRandom();
543
+        });
544
+        $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
545
+
546
+        $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
547
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
548
+        });
549
+        $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
550
+
551
+        $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
552
+            return new Hasher($c->getConfig());
553
+        });
554
+        $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
555
+
556
+        $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
557
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
558
+        });
559
+        $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
560
+
561
+        $this->registerService(IDBConnection::class, function (Server $c) {
562
+            $systemConfig = $c->getSystemConfig();
563
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
564
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
565
+            if (!$factory->isValidType($type)) {
566
+                throw new \OC\DatabaseException('Invalid database type');
567
+            }
568
+            $connectionParams = $factory->createConnectionParams();
569
+            $connection = $factory->getConnection($type, $connectionParams);
570
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
571
+            return $connection;
572
+        });
573
+        $this->registerAlias('DatabaseConnection', IDBConnection::class);
574
+
575
+        $this->registerService('HTTPHelper', function (Server $c) {
576
+            $config = $c->getConfig();
577
+            return new HTTPHelper(
578
+                $config,
579
+                $c->getHTTPClientService()
580
+            );
581
+        });
582
+
583
+        $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
584
+            $user = \OC_User::getUser();
585
+            $uid = $user ? $user : null;
586
+            return new ClientService(
587
+                $c->getConfig(),
588
+                new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
589
+            );
590
+        });
591
+        $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
592
+        $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
593
+            $eventLogger = new EventLogger();
594
+            if ($c->getSystemConfig()->getValue('debug', false)) {
595
+                // In debug mode, module is being activated by default
596
+                $eventLogger->activate();
597
+            }
598
+            return $eventLogger;
599
+        });
600
+        $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
601
+
602
+        $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
603
+            $queryLogger = new QueryLogger();
604
+            if ($c->getSystemConfig()->getValue('debug', false)) {
605
+                // In debug mode, module is being activated by default
606
+                $queryLogger->activate();
607
+            }
608
+            return $queryLogger;
609
+        });
610
+        $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
611
+
612
+        $this->registerService(TempManager::class, function (Server $c) {
613
+            return new TempManager(
614
+                $c->getLogger(),
615
+                $c->getConfig()
616
+            );
617
+        });
618
+        $this->registerAlias('TempManager', TempManager::class);
619
+        $this->registerAlias(ITempManager::class, TempManager::class);
620
+
621
+        $this->registerService(AppManager::class, function (Server $c) {
622
+            return new \OC\App\AppManager(
623
+                $c->getUserSession(),
624
+                $c->getAppConfig(),
625
+                $c->getGroupManager(),
626
+                $c->getMemCacheFactory(),
627
+                $c->getEventDispatcher()
628
+            );
629
+        });
630
+        $this->registerAlias('AppManager', AppManager::class);
631
+        $this->registerAlias(IAppManager::class, AppManager::class);
632
+
633
+        $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
634
+            return new DateTimeZone(
635
+                $c->getConfig(),
636
+                $c->getSession()
637
+            );
638
+        });
639
+        $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
640
+
641
+        $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
642
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
643
+
644
+            return new DateTimeFormatter(
645
+                $c->getDateTimeZone()->getTimeZone(),
646
+                $c->getL10N('lib', $language)
647
+            );
648
+        });
649
+        $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
650
+
651
+        $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
652
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
653
+            $listener = new UserMountCacheListener($mountCache);
654
+            $listener->listen($c->getUserManager());
655
+            return $mountCache;
656
+        });
657
+        $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
658
+
659
+        $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
660
+            $loader = \OC\Files\Filesystem::getLoader();
661
+            $mountCache = $c->query('UserMountCache');
662
+            $manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
663
+
664
+            // builtin providers
665
+
666
+            $config = $c->getConfig();
667
+            $manager->registerProvider(new CacheMountProvider($config));
668
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
669
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
670
+
671
+            return $manager;
672
+        });
673
+        $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
674
+
675
+        $this->registerService('IniWrapper', function ($c) {
676
+            return new IniGetWrapper();
677
+        });
678
+        $this->registerService('AsyncCommandBus', function (Server $c) {
679
+            $jobList = $c->getJobList();
680
+            return new AsyncBus($jobList);
681
+        });
682
+        $this->registerService('TrustedDomainHelper', function ($c) {
683
+            return new TrustedDomainHelper($this->getConfig());
684
+        });
685
+        $this->registerService('Throttler', function(Server $c) {
686
+            return new Throttler(
687
+                $c->getDatabaseConnection(),
688
+                new TimeFactory(),
689
+                $c->getLogger(),
690
+                $c->getConfig()
691
+            );
692
+        });
693
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
694
+            // IConfig and IAppManager requires a working database. This code
695
+            // might however be called when ownCloud is not yet setup.
696
+            if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
697
+                $config = $c->getConfig();
698
+                $appManager = $c->getAppManager();
699
+            } else {
700
+                $config = null;
701
+                $appManager = null;
702
+            }
703
+
704
+            return new Checker(
705
+                    new EnvironmentHelper(),
706
+                    new FileAccessHelper(),
707
+                    new AppLocator(),
708
+                    $config,
709
+                    $c->getMemCacheFactory(),
710
+                    $appManager,
711
+                    $c->getTempManager()
712
+            );
713
+        });
714
+        $this->registerService(\OCP\IRequest::class, function ($c) {
715
+            if (isset($this['urlParams'])) {
716
+                $urlParams = $this['urlParams'];
717
+            } else {
718
+                $urlParams = [];
719
+            }
720
+
721
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
722
+                && in_array('fakeinput', stream_get_wrappers())
723
+            ) {
724
+                $stream = 'fakeinput://data';
725
+            } else {
726
+                $stream = 'php://input';
727
+            }
728
+
729
+            return new Request(
730
+                [
731
+                    'get' => $_GET,
732
+                    'post' => $_POST,
733
+                    'files' => $_FILES,
734
+                    'server' => $_SERVER,
735
+                    'env' => $_ENV,
736
+                    'cookies' => $_COOKIE,
737
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
738
+                        ? $_SERVER['REQUEST_METHOD']
739
+                        : null,
740
+                    'urlParams' => $urlParams,
741
+                ],
742
+                $this->getSecureRandom(),
743
+                $this->getConfig(),
744
+                $this->getCsrfTokenManager(),
745
+                $stream
746
+            );
747
+        });
748
+        $this->registerAlias('Request', \OCP\IRequest::class);
749
+
750
+        $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
751
+            return new Mailer(
752
+                $c->getConfig(),
753
+                $c->getLogger(),
754
+                $c->query(Defaults::class),
755
+                $c->getURLGenerator(),
756
+                $c->getL10N('lib')
757
+            );
758
+        });
759
+        $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
760
+
761
+        $this->registerService('LDAPProvider', function(Server $c) {
762
+            $config = $c->getConfig();
763
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
764
+            if(is_null($factoryClass)) {
765
+                throw new \Exception('ldapProviderFactory not set');
766
+            }
767
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
768
+            $factory = new $factoryClass($this);
769
+            return $factory->getLDAPProvider();
770
+        });
771
+        $this->registerService('LockingProvider', function (Server $c) {
772
+            $ini = $c->getIniWrapper();
773
+            $config = $c->getConfig();
774
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
775
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
776
+                /** @var \OC\Memcache\Factory $memcacheFactory */
777
+                $memcacheFactory = $c->getMemCacheFactory();
778
+                $memcache = $memcacheFactory->createLocking('lock');
779
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
780
+                    return new MemcacheLockingProvider($memcache, $ttl);
781
+                }
782
+                return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
783
+            }
784
+            return new NoopLockingProvider();
785
+        });
786
+
787
+        $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
788
+            return new \OC\Files\Mount\Manager();
789
+        });
790
+        $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
791
+
792
+        $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
793
+            return new \OC\Files\Type\Detection(
794
+                $c->getURLGenerator(),
795
+                \OC::$configDir,
796
+                \OC::$SERVERROOT . '/resources/config/'
797
+            );
798
+        });
799
+        $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
800
+
801
+        $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
802
+            return new \OC\Files\Type\Loader(
803
+                $c->getDatabaseConnection()
804
+            );
805
+        });
806
+        $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
807
+        $this->registerService(BundleFetcher::class, function () {
808
+            return new BundleFetcher($this->getL10N('lib'));
809
+        });
810
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
811
+            return new Manager(
812
+                $c->query(IValidator::class)
813
+            );
814
+        });
815
+        $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
816
+
817
+        $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
818
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
819
+            $manager->registerCapability(function () use ($c) {
820
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
821
+            });
822
+            return $manager;
823
+        });
824
+        $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
825
+
826
+        $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
827
+            $config = $c->getConfig();
828
+            $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
829
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
830
+            $factory = new $factoryClass($this);
831
+            return $factory->getManager();
832
+        });
833
+        $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
834
+
835
+        $this->registerService('ThemingDefaults', function(Server $c) {
836
+            /*
837 837
 			 * Dark magic for autoloader.
838 838
 			 * If we do a class_exists it will try to load the class which will
839 839
 			 * make composer cache the result. Resulting in errors when enabling
840 840
 			 * the theming app.
841 841
 			 */
842
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
843
-			if (isset($prefixes['OCA\\Theming\\'])) {
844
-				$classExists = true;
845
-			} else {
846
-				$classExists = false;
847
-			}
848
-
849
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
850
-				return new ThemingDefaults(
851
-					$c->getConfig(),
852
-					$c->getL10N('theming'),
853
-					$c->getURLGenerator(),
854
-					$c->getAppDataDir('theming'),
855
-					$c->getMemCacheFactory(),
856
-					new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming'))
857
-				);
858
-			}
859
-			return new \OC_Defaults();
860
-		});
861
-		$this->registerService(SCSSCacher::class, function(Server $c) {
862
-			/** @var Factory $cacheFactory */
863
-			$cacheFactory = $c->query(Factory::class);
864
-			return new SCSSCacher(
865
-				$c->getLogger(),
866
-				$c->query(\OC\Files\AppData\Factory::class),
867
-				$c->getURLGenerator(),
868
-				$c->getConfig(),
869
-				$c->getThemingDefaults(),
870
-				\OC::$SERVERROOT,
871
-				$cacheFactory->create('SCSS')
872
-			);
873
-		});
874
-		$this->registerService(EventDispatcher::class, function () {
875
-			return new EventDispatcher();
876
-		});
877
-		$this->registerAlias('EventDispatcher', EventDispatcher::class);
878
-		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
879
-
880
-		$this->registerService('CryptoWrapper', function (Server $c) {
881
-			// FIXME: Instantiiated here due to cyclic dependency
882
-			$request = new Request(
883
-				[
884
-					'get' => $_GET,
885
-					'post' => $_POST,
886
-					'files' => $_FILES,
887
-					'server' => $_SERVER,
888
-					'env' => $_ENV,
889
-					'cookies' => $_COOKIE,
890
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
891
-						? $_SERVER['REQUEST_METHOD']
892
-						: null,
893
-				],
894
-				$c->getSecureRandom(),
895
-				$c->getConfig()
896
-			);
897
-
898
-			return new CryptoWrapper(
899
-				$c->getConfig(),
900
-				$c->getCrypto(),
901
-				$c->getSecureRandom(),
902
-				$request
903
-			);
904
-		});
905
-		$this->registerService('CsrfTokenManager', function (Server $c) {
906
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
907
-
908
-			return new CsrfTokenManager(
909
-				$tokenGenerator,
910
-				$c->query(SessionStorage::class)
911
-			);
912
-		});
913
-		$this->registerService(SessionStorage::class, function (Server $c) {
914
-			return new SessionStorage($c->getSession());
915
-		});
916
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
917
-			return new ContentSecurityPolicyManager();
918
-		});
919
-		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
920
-
921
-		$this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
922
-			return new ContentSecurityPolicyNonceManager(
923
-				$c->getCsrfTokenManager(),
924
-				$c->getRequest()
925
-			);
926
-		});
927
-
928
-		$this->registerService(\OCP\Share\IManager::class, function(Server $c) {
929
-			$config = $c->getConfig();
930
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
931
-			/** @var \OCP\Share\IProviderFactory $factory */
932
-			$factory = new $factoryClass($this);
933
-
934
-			$manager = new \OC\Share20\Manager(
935
-				$c->getLogger(),
936
-				$c->getConfig(),
937
-				$c->getSecureRandom(),
938
-				$c->getHasher(),
939
-				$c->getMountManager(),
940
-				$c->getGroupManager(),
941
-				$c->getL10N('core'),
942
-				$factory,
943
-				$c->getUserManager(),
944
-				$c->getLazyRootFolder(),
945
-				$c->getEventDispatcher()
946
-			);
947
-
948
-			return $manager;
949
-		});
950
-		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
951
-
952
-		$this->registerService('SettingsManager', function(Server $c) {
953
-			$manager = new \OC\Settings\Manager(
954
-				$c->getLogger(),
955
-				$c->getDatabaseConnection(),
956
-				$c->getL10N('lib'),
957
-				$c->getConfig(),
958
-				$c->getEncryptionManager(),
959
-				$c->getUserManager(),
960
-				$c->getLockingProvider(),
961
-				$c->getRequest(),
962
-				new \OC\Settings\Mapper($c->getDatabaseConnection()),
963
-				$c->getURLGenerator()
964
-			);
965
-			return $manager;
966
-		});
967
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
968
-			return new \OC\Files\AppData\Factory(
969
-				$c->getRootFolder(),
970
-				$c->getSystemConfig()
971
-			);
972
-		});
973
-
974
-		$this->registerService('LockdownManager', function (Server $c) {
975
-			return new LockdownManager(function() use ($c) {
976
-				return $c->getSession();
977
-			});
978
-		});
979
-
980
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
981
-			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
982
-		});
983
-
984
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
985
-			return new CloudIdManager();
986
-		});
987
-
988
-		/* To trick DI since we don't extend the DIContainer here */
989
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
990
-			return new CleanPreviewsBackgroundJob(
991
-				$c->getRootFolder(),
992
-				$c->getLogger(),
993
-				$c->getJobList(),
994
-				new TimeFactory()
995
-			);
996
-		});
997
-
998
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
999
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1000
-
1001
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1002
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1003
-
1004
-		$this->registerService(Defaults::class, function (Server $c) {
1005
-			return new Defaults(
1006
-				$c->getThemingDefaults()
1007
-			);
1008
-		});
1009
-		$this->registerAlias('Defaults', \OCP\Defaults::class);
1010
-
1011
-		$this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
1012
-			return $c->query(\OCP\IUserSession::class)->getSession();
1013
-		});
1014
-
1015
-		$this->registerService(IShareHelper::class, function(Server $c) {
1016
-			return new ShareHelper(
1017
-				$c->query(\OCP\Share\IManager::class)
1018
-			);
1019
-		});
1020
-	}
1021
-
1022
-	/**
1023
-	 * @return \OCP\Contacts\IManager
1024
-	 */
1025
-	public function getContactsManager() {
1026
-		return $this->query('ContactsManager');
1027
-	}
1028
-
1029
-	/**
1030
-	 * @return \OC\Encryption\Manager
1031
-	 */
1032
-	public function getEncryptionManager() {
1033
-		return $this->query('EncryptionManager');
1034
-	}
1035
-
1036
-	/**
1037
-	 * @return \OC\Encryption\File
1038
-	 */
1039
-	public function getEncryptionFilesHelper() {
1040
-		return $this->query('EncryptionFileHelper');
1041
-	}
1042
-
1043
-	/**
1044
-	 * @return \OCP\Encryption\Keys\IStorage
1045
-	 */
1046
-	public function getEncryptionKeyStorage() {
1047
-		return $this->query('EncryptionKeyStorage');
1048
-	}
1049
-
1050
-	/**
1051
-	 * The current request object holding all information about the request
1052
-	 * currently being processed is returned from this method.
1053
-	 * In case the current execution was not initiated by a web request null is returned
1054
-	 *
1055
-	 * @return \OCP\IRequest
1056
-	 */
1057
-	public function getRequest() {
1058
-		return $this->query('Request');
1059
-	}
1060
-
1061
-	/**
1062
-	 * Returns the preview manager which can create preview images for a given file
1063
-	 *
1064
-	 * @return \OCP\IPreview
1065
-	 */
1066
-	public function getPreviewManager() {
1067
-		return $this->query('PreviewManager');
1068
-	}
1069
-
1070
-	/**
1071
-	 * Returns the tag manager which can get and set tags for different object types
1072
-	 *
1073
-	 * @see \OCP\ITagManager::load()
1074
-	 * @return \OCP\ITagManager
1075
-	 */
1076
-	public function getTagManager() {
1077
-		return $this->query('TagManager');
1078
-	}
1079
-
1080
-	/**
1081
-	 * Returns the system-tag manager
1082
-	 *
1083
-	 * @return \OCP\SystemTag\ISystemTagManager
1084
-	 *
1085
-	 * @since 9.0.0
1086
-	 */
1087
-	public function getSystemTagManager() {
1088
-		return $this->query('SystemTagManager');
1089
-	}
1090
-
1091
-	/**
1092
-	 * Returns the system-tag object mapper
1093
-	 *
1094
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1095
-	 *
1096
-	 * @since 9.0.0
1097
-	 */
1098
-	public function getSystemTagObjectMapper() {
1099
-		return $this->query('SystemTagObjectMapper');
1100
-	}
1101
-
1102
-	/**
1103
-	 * Returns the avatar manager, used for avatar functionality
1104
-	 *
1105
-	 * @return \OCP\IAvatarManager
1106
-	 */
1107
-	public function getAvatarManager() {
1108
-		return $this->query('AvatarManager');
1109
-	}
1110
-
1111
-	/**
1112
-	 * Returns the root folder of ownCloud's data directory
1113
-	 *
1114
-	 * @return \OCP\Files\IRootFolder
1115
-	 */
1116
-	public function getRootFolder() {
1117
-		return $this->query('LazyRootFolder');
1118
-	}
1119
-
1120
-	/**
1121
-	 * Returns the root folder of ownCloud's data directory
1122
-	 * This is the lazy variant so this gets only initialized once it
1123
-	 * is actually used.
1124
-	 *
1125
-	 * @return \OCP\Files\IRootFolder
1126
-	 */
1127
-	public function getLazyRootFolder() {
1128
-		return $this->query('LazyRootFolder');
1129
-	}
1130
-
1131
-	/**
1132
-	 * Returns a view to ownCloud's files folder
1133
-	 *
1134
-	 * @param string $userId user ID
1135
-	 * @return \OCP\Files\Folder|null
1136
-	 */
1137
-	public function getUserFolder($userId = null) {
1138
-		if ($userId === null) {
1139
-			$user = $this->getUserSession()->getUser();
1140
-			if (!$user) {
1141
-				return null;
1142
-			}
1143
-			$userId = $user->getUID();
1144
-		}
1145
-		$root = $this->getRootFolder();
1146
-		return $root->getUserFolder($userId);
1147
-	}
1148
-
1149
-	/**
1150
-	 * Returns an app-specific view in ownClouds data directory
1151
-	 *
1152
-	 * @return \OCP\Files\Folder
1153
-	 * @deprecated since 9.2.0 use IAppData
1154
-	 */
1155
-	public function getAppFolder() {
1156
-		$dir = '/' . \OC_App::getCurrentApp();
1157
-		$root = $this->getRootFolder();
1158
-		if (!$root->nodeExists($dir)) {
1159
-			$folder = $root->newFolder($dir);
1160
-		} else {
1161
-			$folder = $root->get($dir);
1162
-		}
1163
-		return $folder;
1164
-	}
1165
-
1166
-	/**
1167
-	 * @return \OC\User\Manager
1168
-	 */
1169
-	public function getUserManager() {
1170
-		return $this->query('UserManager');
1171
-	}
1172
-
1173
-	/**
1174
-	 * @return \OC\Group\Manager
1175
-	 */
1176
-	public function getGroupManager() {
1177
-		return $this->query('GroupManager');
1178
-	}
1179
-
1180
-	/**
1181
-	 * @return \OC\User\Session
1182
-	 */
1183
-	public function getUserSession() {
1184
-		return $this->query('UserSession');
1185
-	}
1186
-
1187
-	/**
1188
-	 * @return \OCP\ISession
1189
-	 */
1190
-	public function getSession() {
1191
-		return $this->query('UserSession')->getSession();
1192
-	}
1193
-
1194
-	/**
1195
-	 * @param \OCP\ISession $session
1196
-	 */
1197
-	public function setSession(\OCP\ISession $session) {
1198
-		$this->query(SessionStorage::class)->setSession($session);
1199
-		$this->query('UserSession')->setSession($session);
1200
-		$this->query(Store::class)->setSession($session);
1201
-	}
1202
-
1203
-	/**
1204
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1205
-	 */
1206
-	public function getTwoFactorAuthManager() {
1207
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1208
-	}
1209
-
1210
-	/**
1211
-	 * @return \OC\NavigationManager
1212
-	 */
1213
-	public function getNavigationManager() {
1214
-		return $this->query('NavigationManager');
1215
-	}
1216
-
1217
-	/**
1218
-	 * @return \OCP\IConfig
1219
-	 */
1220
-	public function getConfig() {
1221
-		return $this->query('AllConfig');
1222
-	}
1223
-
1224
-	/**
1225
-	 * @internal For internal use only
1226
-	 * @return \OC\SystemConfig
1227
-	 */
1228
-	public function getSystemConfig() {
1229
-		return $this->query('SystemConfig');
1230
-	}
1231
-
1232
-	/**
1233
-	 * Returns the app config manager
1234
-	 *
1235
-	 * @return \OCP\IAppConfig
1236
-	 */
1237
-	public function getAppConfig() {
1238
-		return $this->query('AppConfig');
1239
-	}
1240
-
1241
-	/**
1242
-	 * @return \OCP\L10N\IFactory
1243
-	 */
1244
-	public function getL10NFactory() {
1245
-		return $this->query('L10NFactory');
1246
-	}
1247
-
1248
-	/**
1249
-	 * get an L10N instance
1250
-	 *
1251
-	 * @param string $app appid
1252
-	 * @param string $lang
1253
-	 * @return IL10N
1254
-	 */
1255
-	public function getL10N($app, $lang = null) {
1256
-		return $this->getL10NFactory()->get($app, $lang);
1257
-	}
1258
-
1259
-	/**
1260
-	 * @return \OCP\IURLGenerator
1261
-	 */
1262
-	public function getURLGenerator() {
1263
-		return $this->query('URLGenerator');
1264
-	}
1265
-
1266
-	/**
1267
-	 * @return \OCP\IHelper
1268
-	 */
1269
-	public function getHelper() {
1270
-		return $this->query('AppHelper');
1271
-	}
1272
-
1273
-	/**
1274
-	 * @return AppFetcher
1275
-	 */
1276
-	public function getAppFetcher() {
1277
-		return $this->query(AppFetcher::class);
1278
-	}
1279
-
1280
-	/**
1281
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1282
-	 * getMemCacheFactory() instead.
1283
-	 *
1284
-	 * @return \OCP\ICache
1285
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1286
-	 */
1287
-	public function getCache() {
1288
-		return $this->query('UserCache');
1289
-	}
1290
-
1291
-	/**
1292
-	 * Returns an \OCP\CacheFactory instance
1293
-	 *
1294
-	 * @return \OCP\ICacheFactory
1295
-	 */
1296
-	public function getMemCacheFactory() {
1297
-		return $this->query('MemCacheFactory');
1298
-	}
1299
-
1300
-	/**
1301
-	 * Returns an \OC\RedisFactory instance
1302
-	 *
1303
-	 * @return \OC\RedisFactory
1304
-	 */
1305
-	public function getGetRedisFactory() {
1306
-		return $this->query('RedisFactory');
1307
-	}
1308
-
1309
-
1310
-	/**
1311
-	 * Returns the current session
1312
-	 *
1313
-	 * @return \OCP\IDBConnection
1314
-	 */
1315
-	public function getDatabaseConnection() {
1316
-		return $this->query('DatabaseConnection');
1317
-	}
1318
-
1319
-	/**
1320
-	 * Returns the activity manager
1321
-	 *
1322
-	 * @return \OCP\Activity\IManager
1323
-	 */
1324
-	public function getActivityManager() {
1325
-		return $this->query('ActivityManager');
1326
-	}
1327
-
1328
-	/**
1329
-	 * Returns an job list for controlling background jobs
1330
-	 *
1331
-	 * @return \OCP\BackgroundJob\IJobList
1332
-	 */
1333
-	public function getJobList() {
1334
-		return $this->query('JobList');
1335
-	}
1336
-
1337
-	/**
1338
-	 * Returns a logger instance
1339
-	 *
1340
-	 * @return \OCP\ILogger
1341
-	 */
1342
-	public function getLogger() {
1343
-		return $this->query('Logger');
1344
-	}
1345
-
1346
-	/**
1347
-	 * Returns a router for generating and matching urls
1348
-	 *
1349
-	 * @return \OCP\Route\IRouter
1350
-	 */
1351
-	public function getRouter() {
1352
-		return $this->query('Router');
1353
-	}
1354
-
1355
-	/**
1356
-	 * Returns a search instance
1357
-	 *
1358
-	 * @return \OCP\ISearch
1359
-	 */
1360
-	public function getSearch() {
1361
-		return $this->query('Search');
1362
-	}
1363
-
1364
-	/**
1365
-	 * Returns a SecureRandom instance
1366
-	 *
1367
-	 * @return \OCP\Security\ISecureRandom
1368
-	 */
1369
-	public function getSecureRandom() {
1370
-		return $this->query('SecureRandom');
1371
-	}
1372
-
1373
-	/**
1374
-	 * Returns a Crypto instance
1375
-	 *
1376
-	 * @return \OCP\Security\ICrypto
1377
-	 */
1378
-	public function getCrypto() {
1379
-		return $this->query('Crypto');
1380
-	}
1381
-
1382
-	/**
1383
-	 * Returns a Hasher instance
1384
-	 *
1385
-	 * @return \OCP\Security\IHasher
1386
-	 */
1387
-	public function getHasher() {
1388
-		return $this->query('Hasher');
1389
-	}
1390
-
1391
-	/**
1392
-	 * Returns a CredentialsManager instance
1393
-	 *
1394
-	 * @return \OCP\Security\ICredentialsManager
1395
-	 */
1396
-	public function getCredentialsManager() {
1397
-		return $this->query('CredentialsManager');
1398
-	}
1399
-
1400
-	/**
1401
-	 * Returns an instance of the HTTP helper class
1402
-	 *
1403
-	 * @deprecated Use getHTTPClientService()
1404
-	 * @return \OC\HTTPHelper
1405
-	 */
1406
-	public function getHTTPHelper() {
1407
-		return $this->query('HTTPHelper');
1408
-	}
1409
-
1410
-	/**
1411
-	 * Get the certificate manager for the user
1412
-	 *
1413
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1414
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1415
-	 */
1416
-	public function getCertificateManager($userId = '') {
1417
-		if ($userId === '') {
1418
-			$userSession = $this->getUserSession();
1419
-			$user = $userSession->getUser();
1420
-			if (is_null($user)) {
1421
-				return null;
1422
-			}
1423
-			$userId = $user->getUID();
1424
-		}
1425
-		return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
1426
-	}
1427
-
1428
-	/**
1429
-	 * Returns an instance of the HTTP client service
1430
-	 *
1431
-	 * @return \OCP\Http\Client\IClientService
1432
-	 */
1433
-	public function getHTTPClientService() {
1434
-		return $this->query('HttpClientService');
1435
-	}
1436
-
1437
-	/**
1438
-	 * Create a new event source
1439
-	 *
1440
-	 * @return \OCP\IEventSource
1441
-	 */
1442
-	public function createEventSource() {
1443
-		return new \OC_EventSource();
1444
-	}
1445
-
1446
-	/**
1447
-	 * Get the active event logger
1448
-	 *
1449
-	 * The returned logger only logs data when debug mode is enabled
1450
-	 *
1451
-	 * @return \OCP\Diagnostics\IEventLogger
1452
-	 */
1453
-	public function getEventLogger() {
1454
-		return $this->query('EventLogger');
1455
-	}
1456
-
1457
-	/**
1458
-	 * Get the active query logger
1459
-	 *
1460
-	 * The returned logger only logs data when debug mode is enabled
1461
-	 *
1462
-	 * @return \OCP\Diagnostics\IQueryLogger
1463
-	 */
1464
-	public function getQueryLogger() {
1465
-		return $this->query('QueryLogger');
1466
-	}
1467
-
1468
-	/**
1469
-	 * Get the manager for temporary files and folders
1470
-	 *
1471
-	 * @return \OCP\ITempManager
1472
-	 */
1473
-	public function getTempManager() {
1474
-		return $this->query('TempManager');
1475
-	}
1476
-
1477
-	/**
1478
-	 * Get the app manager
1479
-	 *
1480
-	 * @return \OCP\App\IAppManager
1481
-	 */
1482
-	public function getAppManager() {
1483
-		return $this->query('AppManager');
1484
-	}
1485
-
1486
-	/**
1487
-	 * Creates a new mailer
1488
-	 *
1489
-	 * @return \OCP\Mail\IMailer
1490
-	 */
1491
-	public function getMailer() {
1492
-		return $this->query('Mailer');
1493
-	}
1494
-
1495
-	/**
1496
-	 * Get the webroot
1497
-	 *
1498
-	 * @return string
1499
-	 */
1500
-	public function getWebRoot() {
1501
-		return $this->webRoot;
1502
-	}
1503
-
1504
-	/**
1505
-	 * @return \OC\OCSClient
1506
-	 */
1507
-	public function getOcsClient() {
1508
-		return $this->query('OcsClient');
1509
-	}
1510
-
1511
-	/**
1512
-	 * @return \OCP\IDateTimeZone
1513
-	 */
1514
-	public function getDateTimeZone() {
1515
-		return $this->query('DateTimeZone');
1516
-	}
1517
-
1518
-	/**
1519
-	 * @return \OCP\IDateTimeFormatter
1520
-	 */
1521
-	public function getDateTimeFormatter() {
1522
-		return $this->query('DateTimeFormatter');
1523
-	}
1524
-
1525
-	/**
1526
-	 * @return \OCP\Files\Config\IMountProviderCollection
1527
-	 */
1528
-	public function getMountProviderCollection() {
1529
-		return $this->query('MountConfigManager');
1530
-	}
1531
-
1532
-	/**
1533
-	 * Get the IniWrapper
1534
-	 *
1535
-	 * @return IniGetWrapper
1536
-	 */
1537
-	public function getIniWrapper() {
1538
-		return $this->query('IniWrapper');
1539
-	}
1540
-
1541
-	/**
1542
-	 * @return \OCP\Command\IBus
1543
-	 */
1544
-	public function getCommandBus() {
1545
-		return $this->query('AsyncCommandBus');
1546
-	}
1547
-
1548
-	/**
1549
-	 * Get the trusted domain helper
1550
-	 *
1551
-	 * @return TrustedDomainHelper
1552
-	 */
1553
-	public function getTrustedDomainHelper() {
1554
-		return $this->query('TrustedDomainHelper');
1555
-	}
1556
-
1557
-	/**
1558
-	 * Get the locking provider
1559
-	 *
1560
-	 * @return \OCP\Lock\ILockingProvider
1561
-	 * @since 8.1.0
1562
-	 */
1563
-	public function getLockingProvider() {
1564
-		return $this->query('LockingProvider');
1565
-	}
1566
-
1567
-	/**
1568
-	 * @return \OCP\Files\Mount\IMountManager
1569
-	 **/
1570
-	function getMountManager() {
1571
-		return $this->query('MountManager');
1572
-	}
1573
-
1574
-	/** @return \OCP\Files\Config\IUserMountCache */
1575
-	function getUserMountCache() {
1576
-		return $this->query('UserMountCache');
1577
-	}
1578
-
1579
-	/**
1580
-	 * Get the MimeTypeDetector
1581
-	 *
1582
-	 * @return \OCP\Files\IMimeTypeDetector
1583
-	 */
1584
-	public function getMimeTypeDetector() {
1585
-		return $this->query('MimeTypeDetector');
1586
-	}
1587
-
1588
-	/**
1589
-	 * Get the MimeTypeLoader
1590
-	 *
1591
-	 * @return \OCP\Files\IMimeTypeLoader
1592
-	 */
1593
-	public function getMimeTypeLoader() {
1594
-		return $this->query('MimeTypeLoader');
1595
-	}
1596
-
1597
-	/**
1598
-	 * Get the manager of all the capabilities
1599
-	 *
1600
-	 * @return \OC\CapabilitiesManager
1601
-	 */
1602
-	public function getCapabilitiesManager() {
1603
-		return $this->query('CapabilitiesManager');
1604
-	}
1605
-
1606
-	/**
1607
-	 * Get the EventDispatcher
1608
-	 *
1609
-	 * @return EventDispatcherInterface
1610
-	 * @since 8.2.0
1611
-	 */
1612
-	public function getEventDispatcher() {
1613
-		return $this->query('EventDispatcher');
1614
-	}
1615
-
1616
-	/**
1617
-	 * Get the Notification Manager
1618
-	 *
1619
-	 * @return \OCP\Notification\IManager
1620
-	 * @since 8.2.0
1621
-	 */
1622
-	public function getNotificationManager() {
1623
-		return $this->query('NotificationManager');
1624
-	}
1625
-
1626
-	/**
1627
-	 * @return \OCP\Comments\ICommentsManager
1628
-	 */
1629
-	public function getCommentsManager() {
1630
-		return $this->query('CommentsManager');
1631
-	}
1632
-
1633
-	/**
1634
-	 * @return \OCA\Theming\ThemingDefaults
1635
-	 */
1636
-	public function getThemingDefaults() {
1637
-		return $this->query('ThemingDefaults');
1638
-	}
1639
-
1640
-	/**
1641
-	 * @return \OC\IntegrityCheck\Checker
1642
-	 */
1643
-	public function getIntegrityCodeChecker() {
1644
-		return $this->query('IntegrityCodeChecker');
1645
-	}
1646
-
1647
-	/**
1648
-	 * @return \OC\Session\CryptoWrapper
1649
-	 */
1650
-	public function getSessionCryptoWrapper() {
1651
-		return $this->query('CryptoWrapper');
1652
-	}
1653
-
1654
-	/**
1655
-	 * @return CsrfTokenManager
1656
-	 */
1657
-	public function getCsrfTokenManager() {
1658
-		return $this->query('CsrfTokenManager');
1659
-	}
1660
-
1661
-	/**
1662
-	 * @return Throttler
1663
-	 */
1664
-	public function getBruteForceThrottler() {
1665
-		return $this->query('Throttler');
1666
-	}
1667
-
1668
-	/**
1669
-	 * @return IContentSecurityPolicyManager
1670
-	 */
1671
-	public function getContentSecurityPolicyManager() {
1672
-		return $this->query('ContentSecurityPolicyManager');
1673
-	}
1674
-
1675
-	/**
1676
-	 * @return ContentSecurityPolicyNonceManager
1677
-	 */
1678
-	public function getContentSecurityPolicyNonceManager() {
1679
-		return $this->query('ContentSecurityPolicyNonceManager');
1680
-	}
1681
-
1682
-	/**
1683
-	 * Not a public API as of 8.2, wait for 9.0
1684
-	 *
1685
-	 * @return \OCA\Files_External\Service\BackendService
1686
-	 */
1687
-	public function getStoragesBackendService() {
1688
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1689
-	}
1690
-
1691
-	/**
1692
-	 * Not a public API as of 8.2, wait for 9.0
1693
-	 *
1694
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1695
-	 */
1696
-	public function getGlobalStoragesService() {
1697
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1698
-	}
1699
-
1700
-	/**
1701
-	 * Not a public API as of 8.2, wait for 9.0
1702
-	 *
1703
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1704
-	 */
1705
-	public function getUserGlobalStoragesService() {
1706
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1707
-	}
1708
-
1709
-	/**
1710
-	 * Not a public API as of 8.2, wait for 9.0
1711
-	 *
1712
-	 * @return \OCA\Files_External\Service\UserStoragesService
1713
-	 */
1714
-	public function getUserStoragesService() {
1715
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1716
-	}
1717
-
1718
-	/**
1719
-	 * @return \OCP\Share\IManager
1720
-	 */
1721
-	public function getShareManager() {
1722
-		return $this->query('ShareManager');
1723
-	}
1724
-
1725
-	/**
1726
-	 * Returns the LDAP Provider
1727
-	 *
1728
-	 * @return \OCP\LDAP\ILDAPProvider
1729
-	 */
1730
-	public function getLDAPProvider() {
1731
-		return $this->query('LDAPProvider');
1732
-	}
1733
-
1734
-	/**
1735
-	 * @return \OCP\Settings\IManager
1736
-	 */
1737
-	public function getSettingsManager() {
1738
-		return $this->query('SettingsManager');
1739
-	}
1740
-
1741
-	/**
1742
-	 * @return \OCP\Files\IAppData
1743
-	 */
1744
-	public function getAppDataDir($app) {
1745
-		/** @var \OC\Files\AppData\Factory $factory */
1746
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
1747
-		return $factory->get($app);
1748
-	}
1749
-
1750
-	/**
1751
-	 * @return \OCP\Lockdown\ILockdownManager
1752
-	 */
1753
-	public function getLockdownManager() {
1754
-		return $this->query('LockdownManager');
1755
-	}
1756
-
1757
-	/**
1758
-	 * @return \OCP\Federation\ICloudIdManager
1759
-	 */
1760
-	public function getCloudIdManager() {
1761
-		return $this->query(ICloudIdManager::class);
1762
-	}
842
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
843
+            if (isset($prefixes['OCA\\Theming\\'])) {
844
+                $classExists = true;
845
+            } else {
846
+                $classExists = false;
847
+            }
848
+
849
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
850
+                return new ThemingDefaults(
851
+                    $c->getConfig(),
852
+                    $c->getL10N('theming'),
853
+                    $c->getURLGenerator(),
854
+                    $c->getAppDataDir('theming'),
855
+                    $c->getMemCacheFactory(),
856
+                    new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming'))
857
+                );
858
+            }
859
+            return new \OC_Defaults();
860
+        });
861
+        $this->registerService(SCSSCacher::class, function(Server $c) {
862
+            /** @var Factory $cacheFactory */
863
+            $cacheFactory = $c->query(Factory::class);
864
+            return new SCSSCacher(
865
+                $c->getLogger(),
866
+                $c->query(\OC\Files\AppData\Factory::class),
867
+                $c->getURLGenerator(),
868
+                $c->getConfig(),
869
+                $c->getThemingDefaults(),
870
+                \OC::$SERVERROOT,
871
+                $cacheFactory->create('SCSS')
872
+            );
873
+        });
874
+        $this->registerService(EventDispatcher::class, function () {
875
+            return new EventDispatcher();
876
+        });
877
+        $this->registerAlias('EventDispatcher', EventDispatcher::class);
878
+        $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
879
+
880
+        $this->registerService('CryptoWrapper', function (Server $c) {
881
+            // FIXME: Instantiiated here due to cyclic dependency
882
+            $request = new Request(
883
+                [
884
+                    'get' => $_GET,
885
+                    'post' => $_POST,
886
+                    'files' => $_FILES,
887
+                    'server' => $_SERVER,
888
+                    'env' => $_ENV,
889
+                    'cookies' => $_COOKIE,
890
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
891
+                        ? $_SERVER['REQUEST_METHOD']
892
+                        : null,
893
+                ],
894
+                $c->getSecureRandom(),
895
+                $c->getConfig()
896
+            );
897
+
898
+            return new CryptoWrapper(
899
+                $c->getConfig(),
900
+                $c->getCrypto(),
901
+                $c->getSecureRandom(),
902
+                $request
903
+            );
904
+        });
905
+        $this->registerService('CsrfTokenManager', function (Server $c) {
906
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
907
+
908
+            return new CsrfTokenManager(
909
+                $tokenGenerator,
910
+                $c->query(SessionStorage::class)
911
+            );
912
+        });
913
+        $this->registerService(SessionStorage::class, function (Server $c) {
914
+            return new SessionStorage($c->getSession());
915
+        });
916
+        $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
917
+            return new ContentSecurityPolicyManager();
918
+        });
919
+        $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
920
+
921
+        $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
922
+            return new ContentSecurityPolicyNonceManager(
923
+                $c->getCsrfTokenManager(),
924
+                $c->getRequest()
925
+            );
926
+        });
927
+
928
+        $this->registerService(\OCP\Share\IManager::class, function(Server $c) {
929
+            $config = $c->getConfig();
930
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
931
+            /** @var \OCP\Share\IProviderFactory $factory */
932
+            $factory = new $factoryClass($this);
933
+
934
+            $manager = new \OC\Share20\Manager(
935
+                $c->getLogger(),
936
+                $c->getConfig(),
937
+                $c->getSecureRandom(),
938
+                $c->getHasher(),
939
+                $c->getMountManager(),
940
+                $c->getGroupManager(),
941
+                $c->getL10N('core'),
942
+                $factory,
943
+                $c->getUserManager(),
944
+                $c->getLazyRootFolder(),
945
+                $c->getEventDispatcher()
946
+            );
947
+
948
+            return $manager;
949
+        });
950
+        $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
951
+
952
+        $this->registerService('SettingsManager', function(Server $c) {
953
+            $manager = new \OC\Settings\Manager(
954
+                $c->getLogger(),
955
+                $c->getDatabaseConnection(),
956
+                $c->getL10N('lib'),
957
+                $c->getConfig(),
958
+                $c->getEncryptionManager(),
959
+                $c->getUserManager(),
960
+                $c->getLockingProvider(),
961
+                $c->getRequest(),
962
+                new \OC\Settings\Mapper($c->getDatabaseConnection()),
963
+                $c->getURLGenerator()
964
+            );
965
+            return $manager;
966
+        });
967
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
968
+            return new \OC\Files\AppData\Factory(
969
+                $c->getRootFolder(),
970
+                $c->getSystemConfig()
971
+            );
972
+        });
973
+
974
+        $this->registerService('LockdownManager', function (Server $c) {
975
+            return new LockdownManager(function() use ($c) {
976
+                return $c->getSession();
977
+            });
978
+        });
979
+
980
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
981
+            return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
982
+        });
983
+
984
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
985
+            return new CloudIdManager();
986
+        });
987
+
988
+        /* To trick DI since we don't extend the DIContainer here */
989
+        $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
990
+            return new CleanPreviewsBackgroundJob(
991
+                $c->getRootFolder(),
992
+                $c->getLogger(),
993
+                $c->getJobList(),
994
+                new TimeFactory()
995
+            );
996
+        });
997
+
998
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
999
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1000
+
1001
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1002
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1003
+
1004
+        $this->registerService(Defaults::class, function (Server $c) {
1005
+            return new Defaults(
1006
+                $c->getThemingDefaults()
1007
+            );
1008
+        });
1009
+        $this->registerAlias('Defaults', \OCP\Defaults::class);
1010
+
1011
+        $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
1012
+            return $c->query(\OCP\IUserSession::class)->getSession();
1013
+        });
1014
+
1015
+        $this->registerService(IShareHelper::class, function(Server $c) {
1016
+            return new ShareHelper(
1017
+                $c->query(\OCP\Share\IManager::class)
1018
+            );
1019
+        });
1020
+    }
1021
+
1022
+    /**
1023
+     * @return \OCP\Contacts\IManager
1024
+     */
1025
+    public function getContactsManager() {
1026
+        return $this->query('ContactsManager');
1027
+    }
1028
+
1029
+    /**
1030
+     * @return \OC\Encryption\Manager
1031
+     */
1032
+    public function getEncryptionManager() {
1033
+        return $this->query('EncryptionManager');
1034
+    }
1035
+
1036
+    /**
1037
+     * @return \OC\Encryption\File
1038
+     */
1039
+    public function getEncryptionFilesHelper() {
1040
+        return $this->query('EncryptionFileHelper');
1041
+    }
1042
+
1043
+    /**
1044
+     * @return \OCP\Encryption\Keys\IStorage
1045
+     */
1046
+    public function getEncryptionKeyStorage() {
1047
+        return $this->query('EncryptionKeyStorage');
1048
+    }
1049
+
1050
+    /**
1051
+     * The current request object holding all information about the request
1052
+     * currently being processed is returned from this method.
1053
+     * In case the current execution was not initiated by a web request null is returned
1054
+     *
1055
+     * @return \OCP\IRequest
1056
+     */
1057
+    public function getRequest() {
1058
+        return $this->query('Request');
1059
+    }
1060
+
1061
+    /**
1062
+     * Returns the preview manager which can create preview images for a given file
1063
+     *
1064
+     * @return \OCP\IPreview
1065
+     */
1066
+    public function getPreviewManager() {
1067
+        return $this->query('PreviewManager');
1068
+    }
1069
+
1070
+    /**
1071
+     * Returns the tag manager which can get and set tags for different object types
1072
+     *
1073
+     * @see \OCP\ITagManager::load()
1074
+     * @return \OCP\ITagManager
1075
+     */
1076
+    public function getTagManager() {
1077
+        return $this->query('TagManager');
1078
+    }
1079
+
1080
+    /**
1081
+     * Returns the system-tag manager
1082
+     *
1083
+     * @return \OCP\SystemTag\ISystemTagManager
1084
+     *
1085
+     * @since 9.0.0
1086
+     */
1087
+    public function getSystemTagManager() {
1088
+        return $this->query('SystemTagManager');
1089
+    }
1090
+
1091
+    /**
1092
+     * Returns the system-tag object mapper
1093
+     *
1094
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
1095
+     *
1096
+     * @since 9.0.0
1097
+     */
1098
+    public function getSystemTagObjectMapper() {
1099
+        return $this->query('SystemTagObjectMapper');
1100
+    }
1101
+
1102
+    /**
1103
+     * Returns the avatar manager, used for avatar functionality
1104
+     *
1105
+     * @return \OCP\IAvatarManager
1106
+     */
1107
+    public function getAvatarManager() {
1108
+        return $this->query('AvatarManager');
1109
+    }
1110
+
1111
+    /**
1112
+     * Returns the root folder of ownCloud's data directory
1113
+     *
1114
+     * @return \OCP\Files\IRootFolder
1115
+     */
1116
+    public function getRootFolder() {
1117
+        return $this->query('LazyRootFolder');
1118
+    }
1119
+
1120
+    /**
1121
+     * Returns the root folder of ownCloud's data directory
1122
+     * This is the lazy variant so this gets only initialized once it
1123
+     * is actually used.
1124
+     *
1125
+     * @return \OCP\Files\IRootFolder
1126
+     */
1127
+    public function getLazyRootFolder() {
1128
+        return $this->query('LazyRootFolder');
1129
+    }
1130
+
1131
+    /**
1132
+     * Returns a view to ownCloud's files folder
1133
+     *
1134
+     * @param string $userId user ID
1135
+     * @return \OCP\Files\Folder|null
1136
+     */
1137
+    public function getUserFolder($userId = null) {
1138
+        if ($userId === null) {
1139
+            $user = $this->getUserSession()->getUser();
1140
+            if (!$user) {
1141
+                return null;
1142
+            }
1143
+            $userId = $user->getUID();
1144
+        }
1145
+        $root = $this->getRootFolder();
1146
+        return $root->getUserFolder($userId);
1147
+    }
1148
+
1149
+    /**
1150
+     * Returns an app-specific view in ownClouds data directory
1151
+     *
1152
+     * @return \OCP\Files\Folder
1153
+     * @deprecated since 9.2.0 use IAppData
1154
+     */
1155
+    public function getAppFolder() {
1156
+        $dir = '/' . \OC_App::getCurrentApp();
1157
+        $root = $this->getRootFolder();
1158
+        if (!$root->nodeExists($dir)) {
1159
+            $folder = $root->newFolder($dir);
1160
+        } else {
1161
+            $folder = $root->get($dir);
1162
+        }
1163
+        return $folder;
1164
+    }
1165
+
1166
+    /**
1167
+     * @return \OC\User\Manager
1168
+     */
1169
+    public function getUserManager() {
1170
+        return $this->query('UserManager');
1171
+    }
1172
+
1173
+    /**
1174
+     * @return \OC\Group\Manager
1175
+     */
1176
+    public function getGroupManager() {
1177
+        return $this->query('GroupManager');
1178
+    }
1179
+
1180
+    /**
1181
+     * @return \OC\User\Session
1182
+     */
1183
+    public function getUserSession() {
1184
+        return $this->query('UserSession');
1185
+    }
1186
+
1187
+    /**
1188
+     * @return \OCP\ISession
1189
+     */
1190
+    public function getSession() {
1191
+        return $this->query('UserSession')->getSession();
1192
+    }
1193
+
1194
+    /**
1195
+     * @param \OCP\ISession $session
1196
+     */
1197
+    public function setSession(\OCP\ISession $session) {
1198
+        $this->query(SessionStorage::class)->setSession($session);
1199
+        $this->query('UserSession')->setSession($session);
1200
+        $this->query(Store::class)->setSession($session);
1201
+    }
1202
+
1203
+    /**
1204
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1205
+     */
1206
+    public function getTwoFactorAuthManager() {
1207
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1208
+    }
1209
+
1210
+    /**
1211
+     * @return \OC\NavigationManager
1212
+     */
1213
+    public function getNavigationManager() {
1214
+        return $this->query('NavigationManager');
1215
+    }
1216
+
1217
+    /**
1218
+     * @return \OCP\IConfig
1219
+     */
1220
+    public function getConfig() {
1221
+        return $this->query('AllConfig');
1222
+    }
1223
+
1224
+    /**
1225
+     * @internal For internal use only
1226
+     * @return \OC\SystemConfig
1227
+     */
1228
+    public function getSystemConfig() {
1229
+        return $this->query('SystemConfig');
1230
+    }
1231
+
1232
+    /**
1233
+     * Returns the app config manager
1234
+     *
1235
+     * @return \OCP\IAppConfig
1236
+     */
1237
+    public function getAppConfig() {
1238
+        return $this->query('AppConfig');
1239
+    }
1240
+
1241
+    /**
1242
+     * @return \OCP\L10N\IFactory
1243
+     */
1244
+    public function getL10NFactory() {
1245
+        return $this->query('L10NFactory');
1246
+    }
1247
+
1248
+    /**
1249
+     * get an L10N instance
1250
+     *
1251
+     * @param string $app appid
1252
+     * @param string $lang
1253
+     * @return IL10N
1254
+     */
1255
+    public function getL10N($app, $lang = null) {
1256
+        return $this->getL10NFactory()->get($app, $lang);
1257
+    }
1258
+
1259
+    /**
1260
+     * @return \OCP\IURLGenerator
1261
+     */
1262
+    public function getURLGenerator() {
1263
+        return $this->query('URLGenerator');
1264
+    }
1265
+
1266
+    /**
1267
+     * @return \OCP\IHelper
1268
+     */
1269
+    public function getHelper() {
1270
+        return $this->query('AppHelper');
1271
+    }
1272
+
1273
+    /**
1274
+     * @return AppFetcher
1275
+     */
1276
+    public function getAppFetcher() {
1277
+        return $this->query(AppFetcher::class);
1278
+    }
1279
+
1280
+    /**
1281
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1282
+     * getMemCacheFactory() instead.
1283
+     *
1284
+     * @return \OCP\ICache
1285
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1286
+     */
1287
+    public function getCache() {
1288
+        return $this->query('UserCache');
1289
+    }
1290
+
1291
+    /**
1292
+     * Returns an \OCP\CacheFactory instance
1293
+     *
1294
+     * @return \OCP\ICacheFactory
1295
+     */
1296
+    public function getMemCacheFactory() {
1297
+        return $this->query('MemCacheFactory');
1298
+    }
1299
+
1300
+    /**
1301
+     * Returns an \OC\RedisFactory instance
1302
+     *
1303
+     * @return \OC\RedisFactory
1304
+     */
1305
+    public function getGetRedisFactory() {
1306
+        return $this->query('RedisFactory');
1307
+    }
1308
+
1309
+
1310
+    /**
1311
+     * Returns the current session
1312
+     *
1313
+     * @return \OCP\IDBConnection
1314
+     */
1315
+    public function getDatabaseConnection() {
1316
+        return $this->query('DatabaseConnection');
1317
+    }
1318
+
1319
+    /**
1320
+     * Returns the activity manager
1321
+     *
1322
+     * @return \OCP\Activity\IManager
1323
+     */
1324
+    public function getActivityManager() {
1325
+        return $this->query('ActivityManager');
1326
+    }
1327
+
1328
+    /**
1329
+     * Returns an job list for controlling background jobs
1330
+     *
1331
+     * @return \OCP\BackgroundJob\IJobList
1332
+     */
1333
+    public function getJobList() {
1334
+        return $this->query('JobList');
1335
+    }
1336
+
1337
+    /**
1338
+     * Returns a logger instance
1339
+     *
1340
+     * @return \OCP\ILogger
1341
+     */
1342
+    public function getLogger() {
1343
+        return $this->query('Logger');
1344
+    }
1345
+
1346
+    /**
1347
+     * Returns a router for generating and matching urls
1348
+     *
1349
+     * @return \OCP\Route\IRouter
1350
+     */
1351
+    public function getRouter() {
1352
+        return $this->query('Router');
1353
+    }
1354
+
1355
+    /**
1356
+     * Returns a search instance
1357
+     *
1358
+     * @return \OCP\ISearch
1359
+     */
1360
+    public function getSearch() {
1361
+        return $this->query('Search');
1362
+    }
1363
+
1364
+    /**
1365
+     * Returns a SecureRandom instance
1366
+     *
1367
+     * @return \OCP\Security\ISecureRandom
1368
+     */
1369
+    public function getSecureRandom() {
1370
+        return $this->query('SecureRandom');
1371
+    }
1372
+
1373
+    /**
1374
+     * Returns a Crypto instance
1375
+     *
1376
+     * @return \OCP\Security\ICrypto
1377
+     */
1378
+    public function getCrypto() {
1379
+        return $this->query('Crypto');
1380
+    }
1381
+
1382
+    /**
1383
+     * Returns a Hasher instance
1384
+     *
1385
+     * @return \OCP\Security\IHasher
1386
+     */
1387
+    public function getHasher() {
1388
+        return $this->query('Hasher');
1389
+    }
1390
+
1391
+    /**
1392
+     * Returns a CredentialsManager instance
1393
+     *
1394
+     * @return \OCP\Security\ICredentialsManager
1395
+     */
1396
+    public function getCredentialsManager() {
1397
+        return $this->query('CredentialsManager');
1398
+    }
1399
+
1400
+    /**
1401
+     * Returns an instance of the HTTP helper class
1402
+     *
1403
+     * @deprecated Use getHTTPClientService()
1404
+     * @return \OC\HTTPHelper
1405
+     */
1406
+    public function getHTTPHelper() {
1407
+        return $this->query('HTTPHelper');
1408
+    }
1409
+
1410
+    /**
1411
+     * Get the certificate manager for the user
1412
+     *
1413
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1414
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1415
+     */
1416
+    public function getCertificateManager($userId = '') {
1417
+        if ($userId === '') {
1418
+            $userSession = $this->getUserSession();
1419
+            $user = $userSession->getUser();
1420
+            if (is_null($user)) {
1421
+                return null;
1422
+            }
1423
+            $userId = $user->getUID();
1424
+        }
1425
+        return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
1426
+    }
1427
+
1428
+    /**
1429
+     * Returns an instance of the HTTP client service
1430
+     *
1431
+     * @return \OCP\Http\Client\IClientService
1432
+     */
1433
+    public function getHTTPClientService() {
1434
+        return $this->query('HttpClientService');
1435
+    }
1436
+
1437
+    /**
1438
+     * Create a new event source
1439
+     *
1440
+     * @return \OCP\IEventSource
1441
+     */
1442
+    public function createEventSource() {
1443
+        return new \OC_EventSource();
1444
+    }
1445
+
1446
+    /**
1447
+     * Get the active event logger
1448
+     *
1449
+     * The returned logger only logs data when debug mode is enabled
1450
+     *
1451
+     * @return \OCP\Diagnostics\IEventLogger
1452
+     */
1453
+    public function getEventLogger() {
1454
+        return $this->query('EventLogger');
1455
+    }
1456
+
1457
+    /**
1458
+     * Get the active query logger
1459
+     *
1460
+     * The returned logger only logs data when debug mode is enabled
1461
+     *
1462
+     * @return \OCP\Diagnostics\IQueryLogger
1463
+     */
1464
+    public function getQueryLogger() {
1465
+        return $this->query('QueryLogger');
1466
+    }
1467
+
1468
+    /**
1469
+     * Get the manager for temporary files and folders
1470
+     *
1471
+     * @return \OCP\ITempManager
1472
+     */
1473
+    public function getTempManager() {
1474
+        return $this->query('TempManager');
1475
+    }
1476
+
1477
+    /**
1478
+     * Get the app manager
1479
+     *
1480
+     * @return \OCP\App\IAppManager
1481
+     */
1482
+    public function getAppManager() {
1483
+        return $this->query('AppManager');
1484
+    }
1485
+
1486
+    /**
1487
+     * Creates a new mailer
1488
+     *
1489
+     * @return \OCP\Mail\IMailer
1490
+     */
1491
+    public function getMailer() {
1492
+        return $this->query('Mailer');
1493
+    }
1494
+
1495
+    /**
1496
+     * Get the webroot
1497
+     *
1498
+     * @return string
1499
+     */
1500
+    public function getWebRoot() {
1501
+        return $this->webRoot;
1502
+    }
1503
+
1504
+    /**
1505
+     * @return \OC\OCSClient
1506
+     */
1507
+    public function getOcsClient() {
1508
+        return $this->query('OcsClient');
1509
+    }
1510
+
1511
+    /**
1512
+     * @return \OCP\IDateTimeZone
1513
+     */
1514
+    public function getDateTimeZone() {
1515
+        return $this->query('DateTimeZone');
1516
+    }
1517
+
1518
+    /**
1519
+     * @return \OCP\IDateTimeFormatter
1520
+     */
1521
+    public function getDateTimeFormatter() {
1522
+        return $this->query('DateTimeFormatter');
1523
+    }
1524
+
1525
+    /**
1526
+     * @return \OCP\Files\Config\IMountProviderCollection
1527
+     */
1528
+    public function getMountProviderCollection() {
1529
+        return $this->query('MountConfigManager');
1530
+    }
1531
+
1532
+    /**
1533
+     * Get the IniWrapper
1534
+     *
1535
+     * @return IniGetWrapper
1536
+     */
1537
+    public function getIniWrapper() {
1538
+        return $this->query('IniWrapper');
1539
+    }
1540
+
1541
+    /**
1542
+     * @return \OCP\Command\IBus
1543
+     */
1544
+    public function getCommandBus() {
1545
+        return $this->query('AsyncCommandBus');
1546
+    }
1547
+
1548
+    /**
1549
+     * Get the trusted domain helper
1550
+     *
1551
+     * @return TrustedDomainHelper
1552
+     */
1553
+    public function getTrustedDomainHelper() {
1554
+        return $this->query('TrustedDomainHelper');
1555
+    }
1556
+
1557
+    /**
1558
+     * Get the locking provider
1559
+     *
1560
+     * @return \OCP\Lock\ILockingProvider
1561
+     * @since 8.1.0
1562
+     */
1563
+    public function getLockingProvider() {
1564
+        return $this->query('LockingProvider');
1565
+    }
1566
+
1567
+    /**
1568
+     * @return \OCP\Files\Mount\IMountManager
1569
+     **/
1570
+    function getMountManager() {
1571
+        return $this->query('MountManager');
1572
+    }
1573
+
1574
+    /** @return \OCP\Files\Config\IUserMountCache */
1575
+    function getUserMountCache() {
1576
+        return $this->query('UserMountCache');
1577
+    }
1578
+
1579
+    /**
1580
+     * Get the MimeTypeDetector
1581
+     *
1582
+     * @return \OCP\Files\IMimeTypeDetector
1583
+     */
1584
+    public function getMimeTypeDetector() {
1585
+        return $this->query('MimeTypeDetector');
1586
+    }
1587
+
1588
+    /**
1589
+     * Get the MimeTypeLoader
1590
+     *
1591
+     * @return \OCP\Files\IMimeTypeLoader
1592
+     */
1593
+    public function getMimeTypeLoader() {
1594
+        return $this->query('MimeTypeLoader');
1595
+    }
1596
+
1597
+    /**
1598
+     * Get the manager of all the capabilities
1599
+     *
1600
+     * @return \OC\CapabilitiesManager
1601
+     */
1602
+    public function getCapabilitiesManager() {
1603
+        return $this->query('CapabilitiesManager');
1604
+    }
1605
+
1606
+    /**
1607
+     * Get the EventDispatcher
1608
+     *
1609
+     * @return EventDispatcherInterface
1610
+     * @since 8.2.0
1611
+     */
1612
+    public function getEventDispatcher() {
1613
+        return $this->query('EventDispatcher');
1614
+    }
1615
+
1616
+    /**
1617
+     * Get the Notification Manager
1618
+     *
1619
+     * @return \OCP\Notification\IManager
1620
+     * @since 8.2.0
1621
+     */
1622
+    public function getNotificationManager() {
1623
+        return $this->query('NotificationManager');
1624
+    }
1625
+
1626
+    /**
1627
+     * @return \OCP\Comments\ICommentsManager
1628
+     */
1629
+    public function getCommentsManager() {
1630
+        return $this->query('CommentsManager');
1631
+    }
1632
+
1633
+    /**
1634
+     * @return \OCA\Theming\ThemingDefaults
1635
+     */
1636
+    public function getThemingDefaults() {
1637
+        return $this->query('ThemingDefaults');
1638
+    }
1639
+
1640
+    /**
1641
+     * @return \OC\IntegrityCheck\Checker
1642
+     */
1643
+    public function getIntegrityCodeChecker() {
1644
+        return $this->query('IntegrityCodeChecker');
1645
+    }
1646
+
1647
+    /**
1648
+     * @return \OC\Session\CryptoWrapper
1649
+     */
1650
+    public function getSessionCryptoWrapper() {
1651
+        return $this->query('CryptoWrapper');
1652
+    }
1653
+
1654
+    /**
1655
+     * @return CsrfTokenManager
1656
+     */
1657
+    public function getCsrfTokenManager() {
1658
+        return $this->query('CsrfTokenManager');
1659
+    }
1660
+
1661
+    /**
1662
+     * @return Throttler
1663
+     */
1664
+    public function getBruteForceThrottler() {
1665
+        return $this->query('Throttler');
1666
+    }
1667
+
1668
+    /**
1669
+     * @return IContentSecurityPolicyManager
1670
+     */
1671
+    public function getContentSecurityPolicyManager() {
1672
+        return $this->query('ContentSecurityPolicyManager');
1673
+    }
1674
+
1675
+    /**
1676
+     * @return ContentSecurityPolicyNonceManager
1677
+     */
1678
+    public function getContentSecurityPolicyNonceManager() {
1679
+        return $this->query('ContentSecurityPolicyNonceManager');
1680
+    }
1681
+
1682
+    /**
1683
+     * Not a public API as of 8.2, wait for 9.0
1684
+     *
1685
+     * @return \OCA\Files_External\Service\BackendService
1686
+     */
1687
+    public function getStoragesBackendService() {
1688
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1689
+    }
1690
+
1691
+    /**
1692
+     * Not a public API as of 8.2, wait for 9.0
1693
+     *
1694
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1695
+     */
1696
+    public function getGlobalStoragesService() {
1697
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1698
+    }
1699
+
1700
+    /**
1701
+     * Not a public API as of 8.2, wait for 9.0
1702
+     *
1703
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1704
+     */
1705
+    public function getUserGlobalStoragesService() {
1706
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1707
+    }
1708
+
1709
+    /**
1710
+     * Not a public API as of 8.2, wait for 9.0
1711
+     *
1712
+     * @return \OCA\Files_External\Service\UserStoragesService
1713
+     */
1714
+    public function getUserStoragesService() {
1715
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1716
+    }
1717
+
1718
+    /**
1719
+     * @return \OCP\Share\IManager
1720
+     */
1721
+    public function getShareManager() {
1722
+        return $this->query('ShareManager');
1723
+    }
1724
+
1725
+    /**
1726
+     * Returns the LDAP Provider
1727
+     *
1728
+     * @return \OCP\LDAP\ILDAPProvider
1729
+     */
1730
+    public function getLDAPProvider() {
1731
+        return $this->query('LDAPProvider');
1732
+    }
1733
+
1734
+    /**
1735
+     * @return \OCP\Settings\IManager
1736
+     */
1737
+    public function getSettingsManager() {
1738
+        return $this->query('SettingsManager');
1739
+    }
1740
+
1741
+    /**
1742
+     * @return \OCP\Files\IAppData
1743
+     */
1744
+    public function getAppDataDir($app) {
1745
+        /** @var \OC\Files\AppData\Factory $factory */
1746
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
1747
+        return $factory->get($app);
1748
+    }
1749
+
1750
+    /**
1751
+     * @return \OCP\Lockdown\ILockdownManager
1752
+     */
1753
+    public function getLockdownManager() {
1754
+        return $this->query('LockdownManager');
1755
+    }
1756
+
1757
+    /**
1758
+     * @return \OCP\Federation\ICloudIdManager
1759
+     */
1760
+    public function getCloudIdManager() {
1761
+        return $this->query(ICloudIdManager::class);
1762
+    }
1763 1763
 }
Please login to merge, or discard this patch.
apps/theming/lib/IconBuilder.php 2 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -29,165 +29,165 @@
 block discarded – undo
29 29
 use OCP\Files\SimpleFS\ISimpleFile;
30 30
 
31 31
 class IconBuilder {
32
-	/** @var ThemingDefaults */
33
-	private $themingDefaults;
34
-	/** @var Util */
35
-	private $util;
36
-
37
-	/**
38
-	 * IconBuilder constructor.
39
-	 *
40
-	 * @param ThemingDefaults $themingDefaults
41
-	 * @param Util $util
42
-	 */
43
-	public function __construct(
44
-		ThemingDefaults $themingDefaults,
45
-		Util $util
46
-	) {
47
-		$this->themingDefaults = $themingDefaults;
48
-		$this->util = $util;
49
-	}
50
-
51
-	/**
52
-	 * @param $app string app name
53
-	 * @return string|false image blob
54
-	 */
55
-	public function getFavicon($app) {
56
-		$icon = $this->renderAppIcon($app, 32);
57
-		if($icon === false) {
58
-			return false;
59
-		}
60
-		$icon->setImageFormat("png24");
61
-		$data = $icon->getImageBlob();
62
-		$icon->destroy();
63
-		return $data;
64
-	}
65
-
66
-	/**
67
-	 * @param $app string app name
68
-	 * @return string|false image blob
69
-	 */
70
-	public function getTouchIcon($app) {
71
-		$icon = $this->renderAppIcon($app, 512);
72
-		if($icon === false) {
73
-			return false;
74
-		}
75
-		$icon->setImageFormat("png24");
76
-		$data = $icon->getImageBlob();
77
-		$icon->destroy();
78
-		return $data;
79
-	}
80
-
81
-	/**
82
-	 * Render app icon on themed background color
83
-	 * fallback to logo
84
-	 *
85
-	 * @param $app string app name
86
-	 * @param $size int size of the icon in px
87
-	 * @return Imagick|false
88
-	 */
89
-	public function renderAppIcon($app, $size) {
90
-		$appIcon = $this->util->getAppIcon($app);
91
-		if($appIcon === false) {
92
-			return false;
93
-		}
94
-		if ($appIcon instanceof ISimpleFile) {
95
-			$appIconContent = $appIcon->getContent();
96
-			$mime = $appIcon->getMimeType();
97
-		} else {
98
-			$appIconContent = file_get_contents($appIcon);
99
-			$mime = mime_content_type($appIcon);
100
-		}
101
-
102
-		if($appIconContent === false || $appIconContent === "") {
103
-			return false;
104
-		}
105
-
106
-		$color = $this->themingDefaults->getColorPrimary();
107
-
108
-		// generate background image with rounded corners
109
-		$background = '<?xml version="1.0" encoding="UTF-8"?>' .
110
-			'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">' .
111
-			'<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' .
112
-			'</svg>';
113
-		// resize svg magic as this seems broken in Imagemagick
114
-		if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") {
115
-			if(substr($appIconContent, 0, 5) !== "<?xml") {
116
-				$svg = "<?xml version=\"1.0\"?>".$appIconContent;
117
-			} else {
118
-				$svg = $appIconContent;
119
-			}
120
-			$tmp = new Imagick();
121
-			$tmp->readImageBlob($svg);
122
-			$x = $tmp->getImageWidth();
123
-			$y = $tmp->getImageHeight();
124
-			$res = $tmp->getImageResolution();
125
-			$tmp->destroy();
126
-
127
-			if($x>$y) {
128
-				$max = $x;
129
-			} else {
130
-				$max = $y;
131
-			}
132
-
133
-			// convert svg to resized image
134
-			$appIconFile = new Imagick();
135
-			$resX = (int)(512 * $res['x'] / $max * 2.53);
136
-			$resY = (int)(512 * $res['y'] / $max * 2.53);
137
-			$appIconFile->setResolution($resX, $resY);
138
-			$appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
139
-			$appIconFile->readImageBlob($svg);
140
-			$appIconFile->scaleImage(512, 512, true);
141
-		} else {
142
-			$appIconFile = new Imagick();
143
-			$appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
144
-			$appIconFile->readImageBlob($appIconContent);
145
-			$appIconFile->scaleImage(512, 512, true);
146
-		}
147
-		// offset for icon positioning
148
-		$border_w = (int)($appIconFile->getImageWidth() * 0.05);
149
-		$border_h = (int)($appIconFile->getImageHeight() * 0.05);
150
-		$innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2);
151
-		$innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2);
152
-		$appIconFile->adaptiveResizeImage($innerWidth, $innerHeight);
153
-		// center icon
154
-		$offset_w = 512 / 2 - $innerWidth / 2;
155
-		$offset_h = 512 / 2 - $innerHeight / 2;
156
-
157
-		$appIconFile->setImageFormat("png24");
158
-
159
-		$finalIconFile = new Imagick();
160
-		$finalIconFile->setBackgroundColor(new ImagickPixel('transparent'));
161
-		$finalIconFile->readImageBlob($background);
162
-		$finalIconFile->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
163
-		$finalIconFile->setImageArtifact('compose:args', "1,0,-0.5,0.5");
164
-		$finalIconFile->compositeImage($appIconFile, Imagick::COMPOSITE_ATOP, $offset_w, $offset_h);
165
-		$finalIconFile->setImageFormat('png24');
166
-		if (defined("Imagick::INTERPOLATE_BICUBIC") === true) {
167
-			$filter = Imagick::INTERPOLATE_BICUBIC;
168
-		} else {
169
-			$filter = Imagick::FILTER_LANCZOS;
170
-		}
171
-		$finalIconFile->resizeImage($size, $size, $filter, 1, false);
172
-
173
-		$appIconFile->destroy();
174
-		return $finalIconFile;
175
-	}
176
-
177
-	public function colorSvg($app, $image) {
178
-		try {
179
-			$imageFile = $this->util->getAppImage($app, $image);
180
-		} catch (AppPathNotFoundException $e) {
181
-			return false;
182
-		}
183
-		$svg = file_get_contents($imageFile);
184
-		if ($svg !== false && $svg !== "") {
185
-			$color = $this->util->elementColor($this->themingDefaults->getColorPrimary());
186
-			$svg = $this->util->colorizeSvg($svg, $color);
187
-			return $svg;
188
-		} else {
189
-			return false;
190
-		}
191
-	}
32
+    /** @var ThemingDefaults */
33
+    private $themingDefaults;
34
+    /** @var Util */
35
+    private $util;
36
+
37
+    /**
38
+     * IconBuilder constructor.
39
+     *
40
+     * @param ThemingDefaults $themingDefaults
41
+     * @param Util $util
42
+     */
43
+    public function __construct(
44
+        ThemingDefaults $themingDefaults,
45
+        Util $util
46
+    ) {
47
+        $this->themingDefaults = $themingDefaults;
48
+        $this->util = $util;
49
+    }
50
+
51
+    /**
52
+     * @param $app string app name
53
+     * @return string|false image blob
54
+     */
55
+    public function getFavicon($app) {
56
+        $icon = $this->renderAppIcon($app, 32);
57
+        if($icon === false) {
58
+            return false;
59
+        }
60
+        $icon->setImageFormat("png24");
61
+        $data = $icon->getImageBlob();
62
+        $icon->destroy();
63
+        return $data;
64
+    }
65
+
66
+    /**
67
+     * @param $app string app name
68
+     * @return string|false image blob
69
+     */
70
+    public function getTouchIcon($app) {
71
+        $icon = $this->renderAppIcon($app, 512);
72
+        if($icon === false) {
73
+            return false;
74
+        }
75
+        $icon->setImageFormat("png24");
76
+        $data = $icon->getImageBlob();
77
+        $icon->destroy();
78
+        return $data;
79
+    }
80
+
81
+    /**
82
+     * Render app icon on themed background color
83
+     * fallback to logo
84
+     *
85
+     * @param $app string app name
86
+     * @param $size int size of the icon in px
87
+     * @return Imagick|false
88
+     */
89
+    public function renderAppIcon($app, $size) {
90
+        $appIcon = $this->util->getAppIcon($app);
91
+        if($appIcon === false) {
92
+            return false;
93
+        }
94
+        if ($appIcon instanceof ISimpleFile) {
95
+            $appIconContent = $appIcon->getContent();
96
+            $mime = $appIcon->getMimeType();
97
+        } else {
98
+            $appIconContent = file_get_contents($appIcon);
99
+            $mime = mime_content_type($appIcon);
100
+        }
101
+
102
+        if($appIconContent === false || $appIconContent === "") {
103
+            return false;
104
+        }
105
+
106
+        $color = $this->themingDefaults->getColorPrimary();
107
+
108
+        // generate background image with rounded corners
109
+        $background = '<?xml version="1.0" encoding="UTF-8"?>' .
110
+            '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">' .
111
+            '<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' .
112
+            '</svg>';
113
+        // resize svg magic as this seems broken in Imagemagick
114
+        if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") {
115
+            if(substr($appIconContent, 0, 5) !== "<?xml") {
116
+                $svg = "<?xml version=\"1.0\"?>".$appIconContent;
117
+            } else {
118
+                $svg = $appIconContent;
119
+            }
120
+            $tmp = new Imagick();
121
+            $tmp->readImageBlob($svg);
122
+            $x = $tmp->getImageWidth();
123
+            $y = $tmp->getImageHeight();
124
+            $res = $tmp->getImageResolution();
125
+            $tmp->destroy();
126
+
127
+            if($x>$y) {
128
+                $max = $x;
129
+            } else {
130
+                $max = $y;
131
+            }
132
+
133
+            // convert svg to resized image
134
+            $appIconFile = new Imagick();
135
+            $resX = (int)(512 * $res['x'] / $max * 2.53);
136
+            $resY = (int)(512 * $res['y'] / $max * 2.53);
137
+            $appIconFile->setResolution($resX, $resY);
138
+            $appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
139
+            $appIconFile->readImageBlob($svg);
140
+            $appIconFile->scaleImage(512, 512, true);
141
+        } else {
142
+            $appIconFile = new Imagick();
143
+            $appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
144
+            $appIconFile->readImageBlob($appIconContent);
145
+            $appIconFile->scaleImage(512, 512, true);
146
+        }
147
+        // offset for icon positioning
148
+        $border_w = (int)($appIconFile->getImageWidth() * 0.05);
149
+        $border_h = (int)($appIconFile->getImageHeight() * 0.05);
150
+        $innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2);
151
+        $innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2);
152
+        $appIconFile->adaptiveResizeImage($innerWidth, $innerHeight);
153
+        // center icon
154
+        $offset_w = 512 / 2 - $innerWidth / 2;
155
+        $offset_h = 512 / 2 - $innerHeight / 2;
156
+
157
+        $appIconFile->setImageFormat("png24");
158
+
159
+        $finalIconFile = new Imagick();
160
+        $finalIconFile->setBackgroundColor(new ImagickPixel('transparent'));
161
+        $finalIconFile->readImageBlob($background);
162
+        $finalIconFile->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
163
+        $finalIconFile->setImageArtifact('compose:args', "1,0,-0.5,0.5");
164
+        $finalIconFile->compositeImage($appIconFile, Imagick::COMPOSITE_ATOP, $offset_w, $offset_h);
165
+        $finalIconFile->setImageFormat('png24');
166
+        if (defined("Imagick::INTERPOLATE_BICUBIC") === true) {
167
+            $filter = Imagick::INTERPOLATE_BICUBIC;
168
+        } else {
169
+            $filter = Imagick::FILTER_LANCZOS;
170
+        }
171
+        $finalIconFile->resizeImage($size, $size, $filter, 1, false);
172
+
173
+        $appIconFile->destroy();
174
+        return $finalIconFile;
175
+    }
176
+
177
+    public function colorSvg($app, $image) {
178
+        try {
179
+            $imageFile = $this->util->getAppImage($app, $image);
180
+        } catch (AppPathNotFoundException $e) {
181
+            return false;
182
+        }
183
+        $svg = file_get_contents($imageFile);
184
+        if ($svg !== false && $svg !== "") {
185
+            $color = $this->util->elementColor($this->themingDefaults->getColorPrimary());
186
+            $svg = $this->util->colorizeSvg($svg, $color);
187
+            return $svg;
188
+        } else {
189
+            return false;
190
+        }
191
+    }
192 192
 
193 193
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 */
55 55
 	public function getFavicon($app) {
56 56
 		$icon = $this->renderAppIcon($app, 32);
57
-		if($icon === false) {
57
+		if ($icon === false) {
58 58
 			return false;
59 59
 		}
60 60
 		$icon->setImageFormat("png24");
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public function getTouchIcon($app) {
71 71
 		$icon = $this->renderAppIcon($app, 512);
72
-		if($icon === false) {
72
+		if ($icon === false) {
73 73
 			return false;
74 74
 		}
75 75
 		$icon->setImageFormat("png24");
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 */
89 89
 	public function renderAppIcon($app, $size) {
90 90
 		$appIcon = $this->util->getAppIcon($app);
91
-		if($appIcon === false) {
91
+		if ($appIcon === false) {
92 92
 			return false;
93 93
 		}
94 94
 		if ($appIcon instanceof ISimpleFile) {
@@ -99,20 +99,20 @@  discard block
 block discarded – undo
99 99
 			$mime = mime_content_type($appIcon);
100 100
 		}
101 101
 
102
-		if($appIconContent === false || $appIconContent === "") {
102
+		if ($appIconContent === false || $appIconContent === "") {
103 103
 			return false;
104 104
 		}
105 105
 
106 106
 		$color = $this->themingDefaults->getColorPrimary();
107 107
 
108 108
 		// generate background image with rounded corners
109
-		$background = '<?xml version="1.0" encoding="UTF-8"?>' .
110
-			'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">' .
111
-			'<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' .
109
+		$background = '<?xml version="1.0" encoding="UTF-8"?>'.
110
+			'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">'.
111
+			'<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:'.$color.';" />'.
112 112
 			'</svg>';
113 113
 		// resize svg magic as this seems broken in Imagemagick
114
-		if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") {
115
-			if(substr($appIconContent, 0, 5) !== "<?xml") {
114
+		if ($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") {
115
+			if (substr($appIconContent, 0, 5) !== "<?xml") {
116 116
 				$svg = "<?xml version=\"1.0\"?>".$appIconContent;
117 117
 			} else {
118 118
 				$svg = $appIconContent;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 			$res = $tmp->getImageResolution();
125 125
 			$tmp->destroy();
126 126
 
127
-			if($x>$y) {
127
+			if ($x > $y) {
128 128
 				$max = $x;
129 129
 			} else {
130 130
 				$max = $y;
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 
133 133
 			// convert svg to resized image
134 134
 			$appIconFile = new Imagick();
135
-			$resX = (int)(512 * $res['x'] / $max * 2.53);
136
-			$resY = (int)(512 * $res['y'] / $max * 2.53);
135
+			$resX = (int) (512 * $res['x'] / $max * 2.53);
136
+			$resY = (int) (512 * $res['y'] / $max * 2.53);
137 137
 			$appIconFile->setResolution($resX, $resY);
138 138
 			$appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
139 139
 			$appIconFile->readImageBlob($svg);
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
 			$appIconFile->scaleImage(512, 512, true);
146 146
 		}
147 147
 		// offset for icon positioning
148
-		$border_w = (int)($appIconFile->getImageWidth() * 0.05);
149
-		$border_h = (int)($appIconFile->getImageHeight() * 0.05);
150
-		$innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2);
151
-		$innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2);
148
+		$border_w = (int) ($appIconFile->getImageWidth() * 0.05);
149
+		$border_h = (int) ($appIconFile->getImageHeight() * 0.05);
150
+		$innerWidth = (int) ($appIconFile->getImageWidth() - $border_w * 2);
151
+		$innerHeight = (int) ($appIconFile->getImageHeight() - $border_h * 2);
152 152
 		$appIconFile->adaptiveResizeImage($innerWidth, $innerHeight);
153 153
 		// center icon
154 154
 		$offset_w = 512 / 2 - $innerWidth / 2;
Please login to merge, or discard this patch.