Completed
Pull Request — master (#8540)
by Julius
19:15
created
apps/theming/appinfo/routes.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -28,59 +28,59 @@
 block discarded – undo
28 28
  */
29 29
 
30 30
 return ['routes' => [
31
-	[
32
-		'name' => 'Theming#updateStylesheet',
33
-		'url' => '/ajax/updateStylesheet',
34
-		'verb' => 'POST'
35
-	],
36
-	[
37
-		'name' => 'Theming#undo',
38
-		'url' => '/ajax/undoChanges',
39
-		'verb' => 'POST'
40
-	],
41
-	[
42
-		'name' => 'Theming#uploadImage',
43
-		'url' => '/ajax/uploadImage',
44
-		'verb' => 'POST'
45
-	],
46
-	[
47
-		'name' => 'Theming#getStylesheet',
48
-		'url' => '/styles',
49
-		'verb' => 'GET',
50
-	],
51
-	[
52
-		'name' => 'Theming#getImage',
53
-		'url' => '/image/{key}',
54
-		'verb' => 'GET',
55
-	],
56
-	[
57
-		'name' => 'Theming#getJavascript',
58
-		'url' => '/js/theming',
59
-		'verb' => 'GET',
60
-	],
61
-	[
62
-		'name' => 'Theming#getManifest',
63
-		'url' => '/manifest/{app}',
64
-		'verb' => 'GET',
65
-		'defaults' => array('app' => 'core')
66
-	],
67
-	[
68
-		'name'	=> 'Icon#getFavicon',
69
-		'url' => '/favicon/{app}',
70
-		'verb' => 'GET',
71
-		'defaults' => array('app' => 'core'),
72
-	],
73
-	[
74
-		'name'	=> 'Icon#getTouchIcon',
75
-		'url' => '/icon/{app}',
76
-		'verb' => 'GET',
77
-		'defaults' => array('app' => 'core'),
78
-	],
79
-	[
80
-		'name'	=> 'Icon#getThemedIcon',
81
-		'url' => '/img/{app}/{image}',
82
-		'verb' => 'GET',
83
-		'requirements' => array('image' => '.+')
84
-	],
31
+    [
32
+        'name' => 'Theming#updateStylesheet',
33
+        'url' => '/ajax/updateStylesheet',
34
+        'verb' => 'POST'
35
+    ],
36
+    [
37
+        'name' => 'Theming#undo',
38
+        'url' => '/ajax/undoChanges',
39
+        'verb' => 'POST'
40
+    ],
41
+    [
42
+        'name' => 'Theming#uploadImage',
43
+        'url' => '/ajax/uploadImage',
44
+        'verb' => 'POST'
45
+    ],
46
+    [
47
+        'name' => 'Theming#getStylesheet',
48
+        'url' => '/styles',
49
+        'verb' => 'GET',
50
+    ],
51
+    [
52
+        'name' => 'Theming#getImage',
53
+        'url' => '/image/{key}',
54
+        'verb' => 'GET',
55
+    ],
56
+    [
57
+        'name' => 'Theming#getJavascript',
58
+        'url' => '/js/theming',
59
+        'verb' => 'GET',
60
+    ],
61
+    [
62
+        'name' => 'Theming#getManifest',
63
+        'url' => '/manifest/{app}',
64
+        'verb' => 'GET',
65
+        'defaults' => array('app' => 'core')
66
+    ],
67
+    [
68
+        'name'	=> 'Icon#getFavicon',
69
+        'url' => '/favicon/{app}',
70
+        'verb' => 'GET',
71
+        'defaults' => array('app' => 'core'),
72
+    ],
73
+    [
74
+        'name'	=> 'Icon#getTouchIcon',
75
+        'url' => '/icon/{app}',
76
+        'verb' => 'GET',
77
+        'defaults' => array('app' => 'core'),
78
+    ],
79
+    [
80
+        'name'	=> 'Icon#getThemedIcon',
81
+        'url' => '/img/{app}/{image}',
82
+        'verb' => 'GET',
83
+        'requirements' => array('image' => '.+')
84
+    ],
85 85
 ]];
86 86
 
Please login to merge, or discard this patch.
apps/theming/lib/Controller/IconController.php 1 patch
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -39,159 +39,159 @@
 block discarded – undo
39 39
 use OCP\IRequest;
40 40
 
41 41
 class IconController extends Controller {
42
-	/** @var ThemingDefaults */
43
-	private $themingDefaults;
44
-	/** @var ITimeFactory */
45
-	private $timeFactory;
46
-	/** @var IconBuilder */
47
-	private $iconBuilder;
48
-	/** @var ImageManager */
49
-	private $imageManager;
50
-	/** @var FileAccessHelper */
51
-	private $fileAccessHelper;
42
+    /** @var ThemingDefaults */
43
+    private $themingDefaults;
44
+    /** @var ITimeFactory */
45
+    private $timeFactory;
46
+    /** @var IconBuilder */
47
+    private $iconBuilder;
48
+    /** @var ImageManager */
49
+    private $imageManager;
50
+    /** @var FileAccessHelper */
51
+    private $fileAccessHelper;
52 52
 
53
-	/**
54
-	 * IconController constructor.
55
-	 *
56
-	 * @param string $appName
57
-	 * @param IRequest $request
58
-	 * @param ThemingDefaults $themingDefaults
59
-	 * @param ITimeFactory $timeFactory
60
-	 * @param IconBuilder $iconBuilder
61
-	 * @param ImageManager $imageManager
62
-	 * @param FileAccessHelper $fileAccessHelper
63
-	 */
64
-	public function __construct(
65
-		$appName,
66
-		IRequest $request,
67
-		ThemingDefaults $themingDefaults,
68
-		ITimeFactory $timeFactory,
69
-		IconBuilder $iconBuilder,
70
-		ImageManager $imageManager,
71
-		FileAccessHelper $fileAccessHelper
72
-	) {
73
-		parent::__construct($appName, $request);
53
+    /**
54
+     * IconController constructor.
55
+     *
56
+     * @param string $appName
57
+     * @param IRequest $request
58
+     * @param ThemingDefaults $themingDefaults
59
+     * @param ITimeFactory $timeFactory
60
+     * @param IconBuilder $iconBuilder
61
+     * @param ImageManager $imageManager
62
+     * @param FileAccessHelper $fileAccessHelper
63
+     */
64
+    public function __construct(
65
+        $appName,
66
+        IRequest $request,
67
+        ThemingDefaults $themingDefaults,
68
+        ITimeFactory $timeFactory,
69
+        IconBuilder $iconBuilder,
70
+        ImageManager $imageManager,
71
+        FileAccessHelper $fileAccessHelper
72
+    ) {
73
+        parent::__construct($appName, $request);
74 74
 
75
-		$this->themingDefaults = $themingDefaults;
76
-		$this->timeFactory = $timeFactory;
77
-		$this->iconBuilder = $iconBuilder;
78
-		$this->imageManager = $imageManager;
79
-		$this->fileAccessHelper = $fileAccessHelper;
80
-	}
75
+        $this->themingDefaults = $themingDefaults;
76
+        $this->timeFactory = $timeFactory;
77
+        $this->iconBuilder = $iconBuilder;
78
+        $this->imageManager = $imageManager;
79
+        $this->fileAccessHelper = $fileAccessHelper;
80
+    }
81 81
 
82
-	/**
83
-	 * @PublicPage
84
-	 * @NoCSRFRequired
85
-	 *
86
-	 * @param $app string app name
87
-	 * @param $image string image file name (svg required)
88
-	 * @return FileDisplayResponse|NotFoundResponse
89
-	 * @throws \Exception
90
-	 */
91
-	public function getThemedIcon(string $app, string $image): Response {
92
-		try {
93
-			$iconFile = $this->imageManager->getCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image));
94
-		} catch (NotFoundException $exception) {
95
-			$icon = $this->iconBuilder->colorSvg($app, $image);
96
-			if ($icon === false || $icon === '') {
97
-				return new NotFoundResponse();
98
-			}
99
-			$iconFile = $this->imageManager->setCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image), $icon);
100
-		}
101
-		if ($iconFile !== false) {
102
-			$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
103
-			$response->cacheFor(86400);
104
-			$expires = new \DateTime();
105
-			$expires->setTimestamp($this->timeFactory->getTime());
106
-			$expires->add(new \DateInterval('PT24H'));
107
-			$response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
108
-			$response->addHeader('Pragma', 'cache');
109
-			return $response;
110
-		}
82
+    /**
83
+     * @PublicPage
84
+     * @NoCSRFRequired
85
+     *
86
+     * @param $app string app name
87
+     * @param $image string image file name (svg required)
88
+     * @return FileDisplayResponse|NotFoundResponse
89
+     * @throws \Exception
90
+     */
91
+    public function getThemedIcon(string $app, string $image): Response {
92
+        try {
93
+            $iconFile = $this->imageManager->getCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image));
94
+        } catch (NotFoundException $exception) {
95
+            $icon = $this->iconBuilder->colorSvg($app, $image);
96
+            if ($icon === false || $icon === '') {
97
+                return new NotFoundResponse();
98
+            }
99
+            $iconFile = $this->imageManager->setCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image), $icon);
100
+        }
101
+        if ($iconFile !== false) {
102
+            $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
103
+            $response->cacheFor(86400);
104
+            $expires = new \DateTime();
105
+            $expires->setTimestamp($this->timeFactory->getTime());
106
+            $expires->add(new \DateInterval('PT24H'));
107
+            $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
108
+            $response->addHeader('Pragma', 'cache');
109
+            return $response;
110
+        }
111 111
 
112
-		return new NotFoundResponse();
113
-	}
112
+        return new NotFoundResponse();
113
+    }
114 114
 
115
-	/**
116
-	 * Return a 32x32 favicon as png
117
-	 *
118
-	 * @PublicPage
119
-	 * @NoCSRFRequired
120
-	 *
121
-	 * @param $app string app name
122
-	 * @return FileDisplayResponse|DataDisplayResponse
123
-	 * @throws \Exception
124
-	 */
125
-	public function getFavicon(string $app = 'core'): Response {
126
-		$response = null;
127
-		$iconFile = null;
128
-		try {
129
-			$iconFile = $this->imageManager->getImage('favicon');
130
-			$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
131
-		} catch (NotFoundException $e) {
132
-		}
133
-		if ($iconFile === null && $this->themingDefaults->shouldReplaceIcons()) {
134
-			try {
135
-				$iconFile = $this->imageManager->getCachedImage('favIcon-' . $app);
136
-			} catch (NotFoundException $exception) {
137
-				$icon = $this->iconBuilder->getFavicon($app);
138
-				$iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon);
139
-			}
140
-			if ($iconFile !== false) {
141
-				$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
142
-			}
143
-		}
144
-		if($response === null) {
145
-			$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png';
146
-			$response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
147
-		}
148
-		$response->cacheFor(86400);
149
-		$expires = new \DateTime();
150
-		$expires->setTimestamp($this->timeFactory->getTime());
151
-		$expires->add(new \DateInterval('PT24H'));
152
-		$response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
153
-		$response->addHeader('Pragma', 'cache');
154
-		return $response;
155
-	}
115
+    /**
116
+     * Return a 32x32 favicon as png
117
+     *
118
+     * @PublicPage
119
+     * @NoCSRFRequired
120
+     *
121
+     * @param $app string app name
122
+     * @return FileDisplayResponse|DataDisplayResponse
123
+     * @throws \Exception
124
+     */
125
+    public function getFavicon(string $app = 'core'): Response {
126
+        $response = null;
127
+        $iconFile = null;
128
+        try {
129
+            $iconFile = $this->imageManager->getImage('favicon');
130
+            $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
131
+        } catch (NotFoundException $e) {
132
+        }
133
+        if ($iconFile === null && $this->themingDefaults->shouldReplaceIcons()) {
134
+            try {
135
+                $iconFile = $this->imageManager->getCachedImage('favIcon-' . $app);
136
+            } catch (NotFoundException $exception) {
137
+                $icon = $this->iconBuilder->getFavicon($app);
138
+                $iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon);
139
+            }
140
+            if ($iconFile !== false) {
141
+                $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
142
+            }
143
+        }
144
+        if($response === null) {
145
+            $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png';
146
+            $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
147
+        }
148
+        $response->cacheFor(86400);
149
+        $expires = new \DateTime();
150
+        $expires->setTimestamp($this->timeFactory->getTime());
151
+        $expires->add(new \DateInterval('PT24H'));
152
+        $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
153
+        $response->addHeader('Pragma', 'cache');
154
+        return $response;
155
+    }
156 156
 
157
-	/**
158
-	 * Return a 512x512 icon for touch devices
159
-	 *
160
-	 * @PublicPage
161
-	 * @NoCSRFRequired
162
-	 *
163
-	 * @param $app string app name
164
-	 * @return FileDisplayResponse|NotFoundResponse
165
-	 * @throws \Exception
166
-	 */
167
-	public function getTouchIcon(string $app = 'core'): Response {
168
-		$response = null;
169
-		try {
170
-			$iconFile = $this->imageManager->getImage('favicon');
171
-			$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
172
-		} catch (NotFoundException $e) {
173
-		}
174
-		if ($this->themingDefaults->shouldReplaceIcons()) {
175
-			try {
176
-				$iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app);
177
-			} catch (NotFoundException $exception) {
178
-				$icon = $this->iconBuilder->getTouchIcon($app);
179
-				$iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon);
180
-			}
181
-			if ($iconFile !== false) {
182
-				$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']);
183
-			}
184
-		}
185
-		if($response === null) {
186
-			$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png';
187
-			$response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']);
188
-		}
189
-		$response->cacheFor(86400);
190
-		$expires = new \DateTime();
191
-		$expires->setTimestamp($this->timeFactory->getTime());
192
-		$expires->add(new \DateInterval('PT24H'));
193
-		$response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
194
-		$response->addHeader('Pragma', 'cache');
195
-		return $response;
196
-	}
157
+    /**
158
+     * Return a 512x512 icon for touch devices
159
+     *
160
+     * @PublicPage
161
+     * @NoCSRFRequired
162
+     *
163
+     * @param $app string app name
164
+     * @return FileDisplayResponse|NotFoundResponse
165
+     * @throws \Exception
166
+     */
167
+    public function getTouchIcon(string $app = 'core'): Response {
168
+        $response = null;
169
+        try {
170
+            $iconFile = $this->imageManager->getImage('favicon');
171
+            $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
172
+        } catch (NotFoundException $e) {
173
+        }
174
+        if ($this->themingDefaults->shouldReplaceIcons()) {
175
+            try {
176
+                $iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app);
177
+            } catch (NotFoundException $exception) {
178
+                $icon = $this->iconBuilder->getTouchIcon($app);
179
+                $iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon);
180
+            }
181
+            if ($iconFile !== false) {
182
+                $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']);
183
+            }
184
+        }
185
+        if($response === null) {
186
+            $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png';
187
+            $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']);
188
+        }
189
+        $response->cacheFor(86400);
190
+        $expires = new \DateTime();
191
+        $expires->setTimestamp($this->timeFactory->getTime());
192
+        $expires->add(new \DateInterval('PT24H'));
193
+        $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
194
+        $response->addHeader('Pragma', 'cache');
195
+        return $response;
196
+    }
197 197
 }
Please login to merge, or discard this patch.
apps/theming/lib/ImageManager.php 1 patch
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -37,149 +37,149 @@
 block discarded – undo
37 37
  */
38 38
 class ImageManager {
39 39
 
40
-	/** @var IConfig */
41
-	private $config;
42
-	/** @var IAppData */
43
-	private $appData;
44
-
45
-	/** @var array */
46
-	private $supportedImageKeys = ['background', 'logo', 'logoheader', 'favicon'];
47
-
48
-	/**
49
-	 * ImageManager constructor.
50
-	 *
51
-	 * @param IConfig $config
52
-	 * @param IAppData $appData
53
-	 * @param IURLGenerator $urlGenerator
54
-	 */
55
-	public function __construct(IConfig $config,
56
-								IAppData $appData,
57
-								IURLGenerator $urlGenerator
58
-	) {
59
-		$this->config = $config;
60
-		$this->appData = $appData;
61
-		$this->urlGenerator = $urlGenerator;
62
-	}
63
-
64
-	public function getImageUrl(string $key): string {
65
-		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
66
-		try {
67
-			$this->getImage($key);
68
-			return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => $key ]) . '?v=' . $cacheBusterCounter;
69
-		} catch (NotFoundException $e) {
70
-		}
71
-
72
-		switch ($key) {
73
-			case 'logo':
74
-			case 'logoheader':
75
-			case 'favicon':
76
-				return $this->urlGenerator->imagePath('core', 'logo.png') . '?v=' . $cacheBusterCounter;
77
-			case 'background':
78
-				return $this->urlGenerator->imagePath('core', 'background.png') . '?v=' . $cacheBusterCounter;
79
-		}
80
-	}
81
-
82
-	public function getImageUrlAbsolute(string $key): string {
83
-		return $this->urlGenerator->getAbsoluteURL($this->getImageUrl($key));
84
-	}
85
-
86
-	/**
87
-	 * @param $key
88
-	 * @return ISimpleFile
89
-	 * @throws NotFoundException
90
-	 */
91
-	public function getImage(string $key): ISimpleFile {
92
-		$logo = $this->config->getAppValue('theming', $key . 'Mime', false);
93
-		if ($logo === false) {
94
-			throw new NotFoundException();
95
-		}
96
-		$folder = $this->appData->getFolder('images');
97
-		return $folder->getFile($key);
98
-	}
99
-
100
-	public function getCustomImages(): array {
101
-		$images = [];
102
-		foreach ($this->supportedImageKeys as $key) {
103
-			$images[$key] = [
104
-				'mime' => $this->config->getAppValue('theming', $key . 'Mime', ''),
105
-				'url' => $this->getImageUrl($key),
106
-			];
107
-		}
108
-		return $images;
109
-	}
110
-
111
-	/**
112
-	 * Get folder for current theming files
113
-	 *
114
-	 * @return ISimpleFolder
115
-	 * @throws NotPermittedException
116
-	 */
117
-	public function getCacheFolder(): ISimpleFolder {
118
-		$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
119
-		try {
120
-			$folder = $this->appData->getFolder($cacheBusterValue);
121
-		} catch (NotFoundException $e) {
122
-			$folder = $this->appData->newFolder($cacheBusterValue);
123
-			$this->cleanup();
124
-		}
125
-		return $folder;
126
-	}
127
-
128
-	/**
129
-	 * Get a file from AppData
130
-	 *
131
-	 * @param string $filename
132
-	 * @throws NotFoundException
133
-	 * @return \OCP\Files\SimpleFS\ISimpleFile
134
-	 * @throws NotPermittedException
135
-	 */
136
-	public function getCachedImage(string $filename): ISimpleFile {
137
-		$currentFolder = $this->getCacheFolder();
138
-		return $currentFolder->getFile($filename);
139
-	}
140
-
141
-	/**
142
-	 * Store a file for theming in AppData
143
-	 *
144
-	 * @param string $filename
145
-	 * @param string $data
146
-	 * @return \OCP\Files\SimpleFS\ISimpleFile
147
-	 * @throws NotFoundException
148
-	 * @throws NotPermittedException
149
-	 */
150
-	public function setCachedImage(string $filename, string $data): ISimpleFile {
151
-		$currentFolder = $this->getCacheFolder();
152
-		if ($currentFolder->fileExists($filename)) {
153
-			$file = $currentFolder->getFile($filename);
154
-		} else {
155
-			$file = $currentFolder->newFile($filename);
156
-		}
157
-		$file->putContent($data);
158
-		return $file;
159
-	}
160
-
161
-	public function delete(string $key) {
162
-		try {
163
-			$file = $this->appData->getFolder('images')->getFile($key);
164
-			$file->delete();
165
-		} catch (NotFoundException $e) {
166
-		} catch (NotPermittedException $e) {
167
-		}
168
-	}
169
-
170
-	/**
171
-	 * remove cached files that are not required any longer
172
-	 *
173
-	 * @throws NotPermittedException
174
-	 * @throws NotFoundException
175
-	 */
176
-	public function cleanup() {
177
-		$currentFolder = $this->getCacheFolder();
178
-		$folders = $this->appData->getDirectoryListing();
179
-		foreach ($folders as $folder) {
180
-			if ($folder->getName() !== 'images' && $folder->getName() !== $currentFolder->getName()) {
181
-				$folder->delete();
182
-			}
183
-		}
184
-	}
40
+    /** @var IConfig */
41
+    private $config;
42
+    /** @var IAppData */
43
+    private $appData;
44
+
45
+    /** @var array */
46
+    private $supportedImageKeys = ['background', 'logo', 'logoheader', 'favicon'];
47
+
48
+    /**
49
+     * ImageManager constructor.
50
+     *
51
+     * @param IConfig $config
52
+     * @param IAppData $appData
53
+     * @param IURLGenerator $urlGenerator
54
+     */
55
+    public function __construct(IConfig $config,
56
+                                IAppData $appData,
57
+                                IURLGenerator $urlGenerator
58
+    ) {
59
+        $this->config = $config;
60
+        $this->appData = $appData;
61
+        $this->urlGenerator = $urlGenerator;
62
+    }
63
+
64
+    public function getImageUrl(string $key): string {
65
+        $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
66
+        try {
67
+            $this->getImage($key);
68
+            return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => $key ]) . '?v=' . $cacheBusterCounter;
69
+        } catch (NotFoundException $e) {
70
+        }
71
+
72
+        switch ($key) {
73
+            case 'logo':
74
+            case 'logoheader':
75
+            case 'favicon':
76
+                return $this->urlGenerator->imagePath('core', 'logo.png') . '?v=' . $cacheBusterCounter;
77
+            case 'background':
78
+                return $this->urlGenerator->imagePath('core', 'background.png') . '?v=' . $cacheBusterCounter;
79
+        }
80
+    }
81
+
82
+    public function getImageUrlAbsolute(string $key): string {
83
+        return $this->urlGenerator->getAbsoluteURL($this->getImageUrl($key));
84
+    }
85
+
86
+    /**
87
+     * @param $key
88
+     * @return ISimpleFile
89
+     * @throws NotFoundException
90
+     */
91
+    public function getImage(string $key): ISimpleFile {
92
+        $logo = $this->config->getAppValue('theming', $key . 'Mime', false);
93
+        if ($logo === false) {
94
+            throw new NotFoundException();
95
+        }
96
+        $folder = $this->appData->getFolder('images');
97
+        return $folder->getFile($key);
98
+    }
99
+
100
+    public function getCustomImages(): array {
101
+        $images = [];
102
+        foreach ($this->supportedImageKeys as $key) {
103
+            $images[$key] = [
104
+                'mime' => $this->config->getAppValue('theming', $key . 'Mime', ''),
105
+                'url' => $this->getImageUrl($key),
106
+            ];
107
+        }
108
+        return $images;
109
+    }
110
+
111
+    /**
112
+     * Get folder for current theming files
113
+     *
114
+     * @return ISimpleFolder
115
+     * @throws NotPermittedException
116
+     */
117
+    public function getCacheFolder(): ISimpleFolder {
118
+        $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
119
+        try {
120
+            $folder = $this->appData->getFolder($cacheBusterValue);
121
+        } catch (NotFoundException $e) {
122
+            $folder = $this->appData->newFolder($cacheBusterValue);
123
+            $this->cleanup();
124
+        }
125
+        return $folder;
126
+    }
127
+
128
+    /**
129
+     * Get a file from AppData
130
+     *
131
+     * @param string $filename
132
+     * @throws NotFoundException
133
+     * @return \OCP\Files\SimpleFS\ISimpleFile
134
+     * @throws NotPermittedException
135
+     */
136
+    public function getCachedImage(string $filename): ISimpleFile {
137
+        $currentFolder = $this->getCacheFolder();
138
+        return $currentFolder->getFile($filename);
139
+    }
140
+
141
+    /**
142
+     * Store a file for theming in AppData
143
+     *
144
+     * @param string $filename
145
+     * @param string $data
146
+     * @return \OCP\Files\SimpleFS\ISimpleFile
147
+     * @throws NotFoundException
148
+     * @throws NotPermittedException
149
+     */
150
+    public function setCachedImage(string $filename, string $data): ISimpleFile {
151
+        $currentFolder = $this->getCacheFolder();
152
+        if ($currentFolder->fileExists($filename)) {
153
+            $file = $currentFolder->getFile($filename);
154
+        } else {
155
+            $file = $currentFolder->newFile($filename);
156
+        }
157
+        $file->putContent($data);
158
+        return $file;
159
+    }
160
+
161
+    public function delete(string $key) {
162
+        try {
163
+            $file = $this->appData->getFolder('images')->getFile($key);
164
+            $file->delete();
165
+        } catch (NotFoundException $e) {
166
+        } catch (NotPermittedException $e) {
167
+        }
168
+    }
169
+
170
+    /**
171
+     * remove cached files that are not required any longer
172
+     *
173
+     * @throws NotPermittedException
174
+     * @throws NotFoundException
175
+     */
176
+    public function cleanup() {
177
+        $currentFolder = $this->getCacheFolder();
178
+        $folders = $this->appData->getDirectoryListing();
179
+        foreach ($folders as $folder) {
180
+            if ($folder->getName() !== 'images' && $folder->getName() !== $currentFolder->getName()) {
181
+                $folder->delete();
182
+            }
183
+        }
184
+    }
185 185
 }
Please login to merge, or discard this patch.
apps/theming/lib/Settings/Admin.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -38,73 +38,73 @@
 block discarded – undo
38 38
 use OCP\Settings\ISettings;
39 39
 
40 40
 class Admin implements ISettings {
41
-	/** @var IConfig */
42
-	private $config;
43
-	/** @var IL10N */
44
-	private $l;
45
-	/** @var ThemingDefaults */
46
-	private $themingDefaults;
47
-	/** @var IURLGenerator */
48
-	private $urlGenerator;
49
-	/** @var ImageManager */
50
-	private $imageManager;
41
+    /** @var IConfig */
42
+    private $config;
43
+    /** @var IL10N */
44
+    private $l;
45
+    /** @var ThemingDefaults */
46
+    private $themingDefaults;
47
+    /** @var IURLGenerator */
48
+    private $urlGenerator;
49
+    /** @var ImageManager */
50
+    private $imageManager;
51 51
 
52
-	public function __construct(IConfig $config,
53
-								IL10N $l,
54
-								ThemingDefaults $themingDefaults,
55
-								IURLGenerator $urlGenerator,
56
-								ImageManager $imageManager) {
57
-		$this->config = $config;
58
-		$this->l = $l;
59
-		$this->themingDefaults = $themingDefaults;
60
-		$this->urlGenerator = $urlGenerator;
61
-		$this->imageManager = $imageManager;
62
-	}
52
+    public function __construct(IConfig $config,
53
+                                IL10N $l,
54
+                                ThemingDefaults $themingDefaults,
55
+                                IURLGenerator $urlGenerator,
56
+                                ImageManager $imageManager) {
57
+        $this->config = $config;
58
+        $this->l = $l;
59
+        $this->themingDefaults = $themingDefaults;
60
+        $this->urlGenerator = $urlGenerator;
61
+        $this->imageManager = $imageManager;
62
+    }
63 63
 
64
-	/**
65
-	 * @return TemplateResponse
66
-	 */
67
-	public function getForm(): TemplateResponse {
68
-		$themable = true;
69
-		$errorMessage = '';
70
-		$theme = $this->config->getSystemValue('theme', '');
71
-		if ($theme !== '') {
72
-			$themable = false;
73
-			$errorMessage = $this->l->t('You are already using a custom theme. Theming app settings might be overwritten by that.');
74
-		}
64
+    /**
65
+     * @return TemplateResponse
66
+     */
67
+    public function getForm(): TemplateResponse {
68
+        $themable = true;
69
+        $errorMessage = '';
70
+        $theme = $this->config->getSystemValue('theme', '');
71
+        if ($theme !== '') {
72
+            $themable = false;
73
+            $errorMessage = $this->l->t('You are already using a custom theme. Theming app settings might be overwritten by that.');
74
+        }
75 75
 
76
-		$parameters = [
77
-			'themable'        => $themable,
78
-			'errorMessage'    => $errorMessage,
79
-			'name'            => $this->themingDefaults->getEntity(),
80
-			'url'             => $this->themingDefaults->getBaseUrl(),
81
-			'slogan'          => $this->themingDefaults->getSlogan(),
82
-			'color'           => $this->themingDefaults->getColorPrimary(),
83
-			'uploadLogoRoute' => $this->urlGenerator->linkToRoute('theming.Theming.uploadImage'),
84
-			'canThemeIcons'   => $this->themingDefaults->shouldReplaceIcons(),
85
-			'iconDocs'        => $this->urlGenerator->linkToDocs('admin-theming-icons'),
86
-			'images'		  => $this->imageManager->getCustomImages(),
87
-		];
76
+        $parameters = [
77
+            'themable'        => $themable,
78
+            'errorMessage'    => $errorMessage,
79
+            'name'            => $this->themingDefaults->getEntity(),
80
+            'url'             => $this->themingDefaults->getBaseUrl(),
81
+            'slogan'          => $this->themingDefaults->getSlogan(),
82
+            'color'           => $this->themingDefaults->getColorPrimary(),
83
+            'uploadLogoRoute' => $this->urlGenerator->linkToRoute('theming.Theming.uploadImage'),
84
+            'canThemeIcons'   => $this->themingDefaults->shouldReplaceIcons(),
85
+            'iconDocs'        => $this->urlGenerator->linkToDocs('admin-theming-icons'),
86
+            'images'		  => $this->imageManager->getCustomImages(),
87
+        ];
88 88
 
89
-		return new TemplateResponse('theming', 'settings-admin', $parameters, '');
90
-	}
89
+        return new TemplateResponse('theming', 'settings-admin', $parameters, '');
90
+    }
91 91
 
92
-	/**
93
-	 * @return string the section ID, e.g. 'sharing'
94
-	 */
95
-	public function getSection(): string {
96
-		return 'theming';
97
-	}
92
+    /**
93
+     * @return string the section ID, e.g. 'sharing'
94
+     */
95
+    public function getSection(): string {
96
+        return 'theming';
97
+    }
98 98
 
99
-	/**
100
-	 * @return int whether the form should be rather on the top or bottom of
101
-	 * the admin section. The forms are arranged in ascending order of the
102
-	 * priority values. It is required to return a value between 0 and 100.
103
-	 *
104
-	 * E.g.: 70
105
-	 */
106
-	public function getPriority(): int {
107
-		return 5;
108
-	}
99
+    /**
100
+     * @return int whether the form should be rather on the top or bottom of
101
+     * the admin section. The forms are arranged in ascending order of the
102
+     * priority values. It is required to return a value between 0 and 100.
103
+     *
104
+     * E.g.: 70
105
+     */
106
+    public function getPriority(): int {
107
+        return 5;
108
+    }
109 109
 
110 110
 }
Please login to merge, or discard this patch.
apps/theming/lib/Controller/ThemingController.php 1 patch
Indentation   +350 added lines, -350 removed lines patch added patch discarded remove patch
@@ -62,345 +62,345 @@  discard block
 block discarded – undo
62 62
  * @package OCA\Theming\Controller
63 63
  */
64 64
 class ThemingController extends Controller {
65
-	/** @var ThemingDefaults */
66
-	private $themingDefaults;
67
-	/** @var Util */
68
-	private $util;
69
-	/** @var ITimeFactory */
70
-	private $timeFactory;
71
-	/** @var IL10N */
72
-	private $l10n;
73
-	/** @var IConfig */
74
-	private $config;
75
-	/** @var ITempManager */
76
-	private $tempManager;
77
-	/** @var IAppData */
78
-	private $appData;
79
-	/** @var SCSSCacher */
80
-	private $scssCacher;
81
-	/** @var IURLGenerator */
82
-	private $urlGenerator;
83
-	/** @var IAppManager */
84
-	private $appManager;
85
-	/** @var ImageManager */
86
-	private $imageManager;
65
+    /** @var ThemingDefaults */
66
+    private $themingDefaults;
67
+    /** @var Util */
68
+    private $util;
69
+    /** @var ITimeFactory */
70
+    private $timeFactory;
71
+    /** @var IL10N */
72
+    private $l10n;
73
+    /** @var IConfig */
74
+    private $config;
75
+    /** @var ITempManager */
76
+    private $tempManager;
77
+    /** @var IAppData */
78
+    private $appData;
79
+    /** @var SCSSCacher */
80
+    private $scssCacher;
81
+    /** @var IURLGenerator */
82
+    private $urlGenerator;
83
+    /** @var IAppManager */
84
+    private $appManager;
85
+    /** @var ImageManager */
86
+    private $imageManager;
87 87
 
88
-	/**
89
-	 * ThemingController constructor.
90
-	 *
91
-	 * @param string $appName
92
-	 * @param IRequest $request
93
-	 * @param IConfig $config
94
-	 * @param ThemingDefaults $themingDefaults
95
-	 * @param Util $util
96
-	 * @param ITimeFactory $timeFactory
97
-	 * @param IL10N $l
98
-	 * @param ITempManager $tempManager
99
-	 * @param IAppData $appData
100
-	 * @param SCSSCacher $scssCacher
101
-	 * @param IURLGenerator $urlGenerator
102
-	 * @param IAppManager $appManager
103
-	 * @param ImageManager $imageManager
104
-	 */
105
-	public function __construct(
106
-		$appName,
107
-		IRequest $request,
108
-		IConfig $config,
109
-		ThemingDefaults $themingDefaults,
110
-		Util $util,
111
-		ITimeFactory $timeFactory,
112
-		IL10N $l,
113
-		ITempManager $tempManager,
114
-		IAppData $appData,
115
-		SCSSCacher $scssCacher,
116
-		IURLGenerator $urlGenerator,
117
-		IAppManager $appManager,
118
-		ImageManager $imageManager
119
-	) {
120
-		parent::__construct($appName, $request);
88
+    /**
89
+     * ThemingController constructor.
90
+     *
91
+     * @param string $appName
92
+     * @param IRequest $request
93
+     * @param IConfig $config
94
+     * @param ThemingDefaults $themingDefaults
95
+     * @param Util $util
96
+     * @param ITimeFactory $timeFactory
97
+     * @param IL10N $l
98
+     * @param ITempManager $tempManager
99
+     * @param IAppData $appData
100
+     * @param SCSSCacher $scssCacher
101
+     * @param IURLGenerator $urlGenerator
102
+     * @param IAppManager $appManager
103
+     * @param ImageManager $imageManager
104
+     */
105
+    public function __construct(
106
+        $appName,
107
+        IRequest $request,
108
+        IConfig $config,
109
+        ThemingDefaults $themingDefaults,
110
+        Util $util,
111
+        ITimeFactory $timeFactory,
112
+        IL10N $l,
113
+        ITempManager $tempManager,
114
+        IAppData $appData,
115
+        SCSSCacher $scssCacher,
116
+        IURLGenerator $urlGenerator,
117
+        IAppManager $appManager,
118
+        ImageManager $imageManager
119
+    ) {
120
+        parent::__construct($appName, $request);
121 121
 
122
-		$this->themingDefaults = $themingDefaults;
123
-		$this->util = $util;
124
-		$this->timeFactory = $timeFactory;
125
-		$this->l10n = $l;
126
-		$this->config = $config;
127
-		$this->tempManager = $tempManager;
128
-		$this->appData = $appData;
129
-		$this->scssCacher = $scssCacher;
130
-		$this->urlGenerator = $urlGenerator;
131
-		$this->appManager = $appManager;
132
-		$this->imageManager = $imageManager;
133
-	}
122
+        $this->themingDefaults = $themingDefaults;
123
+        $this->util = $util;
124
+        $this->timeFactory = $timeFactory;
125
+        $this->l10n = $l;
126
+        $this->config = $config;
127
+        $this->tempManager = $tempManager;
128
+        $this->appData = $appData;
129
+        $this->scssCacher = $scssCacher;
130
+        $this->urlGenerator = $urlGenerator;
131
+        $this->appManager = $appManager;
132
+        $this->imageManager = $imageManager;
133
+    }
134 134
 
135
-	/**
136
-	 * @param string $setting
137
-	 * @param string $value
138
-	 * @return DataResponse
139
-	 * @throws NotPermittedException
140
-	 */
141
-	public function updateStylesheet($setting, $value) {
142
-		$value = trim($value);
143
-		switch ($setting) {
144
-			case 'name':
145
-				if (strlen($value) > 250) {
146
-					return new DataResponse([
147
-						'data' => [
148
-							'message' => $this->l10n->t('The given name is too long'),
149
-						],
150
-						'status' => 'error'
151
-					]);
152
-				}
153
-				break;
154
-			case 'url':
155
-				if (strlen($value) > 500) {
156
-					return new DataResponse([
157
-						'data' => [
158
-							'message' => $this->l10n->t('The given web address is too long'),
159
-						],
160
-						'status' => 'error'
161
-					]);
162
-				}
163
-				break;
164
-			case 'slogan':
165
-				if (strlen($value) > 500) {
166
-					return new DataResponse([
167
-						'data' => [
168
-							'message' => $this->l10n->t('The given slogan is too long'),
169
-						],
170
-						'status' => 'error'
171
-					]);
172
-				}
173
-				break;
174
-			case 'color':
175
-				if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
176
-					return new DataResponse([
177
-						'data' => [
178
-							'message' => $this->l10n->t('The given color is invalid'),
179
-						],
180
-						'status' => 'error'
181
-					]);
182
-				}
183
-				break;
184
-		}
135
+    /**
136
+     * @param string $setting
137
+     * @param string $value
138
+     * @return DataResponse
139
+     * @throws NotPermittedException
140
+     */
141
+    public function updateStylesheet($setting, $value) {
142
+        $value = trim($value);
143
+        switch ($setting) {
144
+            case 'name':
145
+                if (strlen($value) > 250) {
146
+                    return new DataResponse([
147
+                        'data' => [
148
+                            'message' => $this->l10n->t('The given name is too long'),
149
+                        ],
150
+                        'status' => 'error'
151
+                    ]);
152
+                }
153
+                break;
154
+            case 'url':
155
+                if (strlen($value) > 500) {
156
+                    return new DataResponse([
157
+                        'data' => [
158
+                            'message' => $this->l10n->t('The given web address is too long'),
159
+                        ],
160
+                        'status' => 'error'
161
+                    ]);
162
+                }
163
+                break;
164
+            case 'slogan':
165
+                if (strlen($value) > 500) {
166
+                    return new DataResponse([
167
+                        'data' => [
168
+                            'message' => $this->l10n->t('The given slogan is too long'),
169
+                        ],
170
+                        'status' => 'error'
171
+                    ]);
172
+                }
173
+                break;
174
+            case 'color':
175
+                if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
176
+                    return new DataResponse([
177
+                        'data' => [
178
+                            'message' => $this->l10n->t('The given color is invalid'),
179
+                        ],
180
+                        'status' => 'error'
181
+                    ]);
182
+                }
183
+                break;
184
+        }
185 185
 
186
-		$this->themingDefaults->set($setting, $value);
186
+        $this->themingDefaults->set($setting, $value);
187 187
 
188
-		// reprocess server scss for preview
189
-		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core');
188
+        // reprocess server scss for preview
189
+        $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core');
190 190
 
191
-		return new DataResponse(
192
-			[
193
-				'data' =>
194
-					[
195
-						'message' => $this->l10n->t('Saved'),
196
-						'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss'))
197
-					],
198
-				'status' => 'success'
199
-			]
200
-		);
201
-	}
191
+        return new DataResponse(
192
+            [
193
+                'data' =>
194
+                    [
195
+                        'message' => $this->l10n->t('Saved'),
196
+                        'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss'))
197
+                    ],
198
+                'status' => 'success'
199
+            ]
200
+        );
201
+    }
202 202
 
203
-	/**
204
-	 * @return DataResponse
205
-	 * @throws NotPermittedException
206
-	 */
207
-	public function uploadImage(): DataResponse {
208
-		// logo / background
209
-		// new: favicon logo-header
210
-		//
211
-		$key = $this->request->getParam('key');
212
-		$image = $this->request->getUploadedFile('image');
213
-		$error = null;
214
-		$phpFileUploadErrors = [
215
-			UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'),
216
-			UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'),
217
-			UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'),
218
-			UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'),
219
-			UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'),
220
-			UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'),
221
-			UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'),
222
-			UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'),
223
-		];
224
-		if (empty($image)) {
225
-			$error = $this->l10n->t('No file uploaded');
226
-		}
227
-		if (!empty($image) && array_key_exists('error', $image) && $image['error'] !== UPLOAD_ERR_OK) {
228
-			$error = $phpFileUploadErrors[$image['error']];
229
-		}
203
+    /**
204
+     * @return DataResponse
205
+     * @throws NotPermittedException
206
+     */
207
+    public function uploadImage(): DataResponse {
208
+        // logo / background
209
+        // new: favicon logo-header
210
+        //
211
+        $key = $this->request->getParam('key');
212
+        $image = $this->request->getUploadedFile('image');
213
+        $error = null;
214
+        $phpFileUploadErrors = [
215
+            UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'),
216
+            UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'),
217
+            UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'),
218
+            UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'),
219
+            UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'),
220
+            UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'),
221
+            UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'),
222
+            UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'),
223
+        ];
224
+        if (empty($image)) {
225
+            $error = $this->l10n->t('No file uploaded');
226
+        }
227
+        if (!empty($image) && array_key_exists('error', $image) && $image['error'] !== UPLOAD_ERR_OK) {
228
+            $error = $phpFileUploadErrors[$image['error']];
229
+        }
230 230
 
231
-		if ($error !== null) {
232
-			return new DataResponse(
233
-				[
234
-					'data' => [
235
-						'message' => $error
236
-					],
237
-					'status' => 'failure',
238
-				],
239
-				Http::STATUS_UNPROCESSABLE_ENTITY
240
-			);
241
-		}
231
+        if ($error !== null) {
232
+            return new DataResponse(
233
+                [
234
+                    'data' => [
235
+                        'message' => $error
236
+                    ],
237
+                    'status' => 'failure',
238
+                ],
239
+                Http::STATUS_UNPROCESSABLE_ENTITY
240
+            );
241
+        }
242 242
 
243
-		$name = '';
244
-		try {
245
-			$folder = $this->appData->getFolder('images');
246
-		} catch (NotFoundException $e) {
247
-			$folder = $this->appData->newFolder('images');
248
-		}
243
+        $name = '';
244
+        try {
245
+            $folder = $this->appData->getFolder('images');
246
+        } catch (NotFoundException $e) {
247
+            $folder = $this->appData->newFolder('images');
248
+        }
249 249
 
250
-		$target = $folder->newFile($key);
251
-		$supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'text/svg'];
252
-		if (!in_array($image['type'], $supportedFormats)) {
253
-			return new DataResponse(
254
-				[
255
-					'data' => [
256
-						'message' => $this->l10n->t('Unsupported image type'),
257
-					],
258
-					'status' => 'failure',
259
-				],
260
-				Http::STATUS_UNPROCESSABLE_ENTITY
261
-			);
262
-		}
250
+        $target = $folder->newFile($key);
251
+        $supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'text/svg'];
252
+        if (!in_array($image['type'], $supportedFormats)) {
253
+            return new DataResponse(
254
+                [
255
+                    'data' => [
256
+                        'message' => $this->l10n->t('Unsupported image type'),
257
+                    ],
258
+                    'status' => 'failure',
259
+                ],
260
+                Http::STATUS_UNPROCESSABLE_ENTITY
261
+            );
262
+        }
263 263
 
264
-		$resizeKeys = ['background'];
265
-		if (in_array($key, $resizeKeys, true)) {
266
-			// Optimize the image since some people may upload images that will be
267
-			// either to big or are not progressive rendering.
268
-			$newImage = @imagecreatefromstring(file_get_contents($image['tmp_name'], 'r'));
264
+        $resizeKeys = ['background'];
265
+        if (in_array($key, $resizeKeys, true)) {
266
+            // Optimize the image since some people may upload images that will be
267
+            // either to big or are not progressive rendering.
268
+            $newImage = @imagecreatefromstring(file_get_contents($image['tmp_name'], 'r'));
269 269
 
270
-			$tmpFile = $this->tempManager->getTemporaryFile();
271
-			$newWidth = imagesx($newImage) < 4096 ? imagesx($newImage) : 4096;
272
-			$newHeight = imagesy($newImage) / (imagesx($newImage) / $newWidth);
273
-			$outputImage = imagescale($newImage, $newWidth, $newHeight);
270
+            $tmpFile = $this->tempManager->getTemporaryFile();
271
+            $newWidth = imagesx($newImage) < 4096 ? imagesx($newImage) : 4096;
272
+            $newHeight = imagesy($newImage) / (imagesx($newImage) / $newWidth);
273
+            $outputImage = imagescale($newImage, $newWidth, $newHeight);
274 274
 
275
-			imageinterlace($outputImage, 1);
276
-			imagejpeg($outputImage, $tmpFile, 75);
277
-			imagedestroy($outputImage);
275
+            imageinterlace($outputImage, 1);
276
+            imagejpeg($outputImage, $tmpFile, 75);
277
+            imagedestroy($outputImage);
278 278
 
279
-			$target->putContent(file_get_contents($tmpFile, 'r'));
280
-		} else {
281
-			$target->putContent(file_get_contents($image['tmp_name'], 'r'));
282
-		}
283
-		$name = $image['name'];
279
+            $target->putContent(file_get_contents($tmpFile, 'r'));
280
+        } else {
281
+            $target->putContent(file_get_contents($image['tmp_name'], 'r'));
282
+        }
283
+        $name = $image['name'];
284 284
 
285
-		$this->themingDefaults->set($key.'Mime', $image['type']);
285
+        $this->themingDefaults->set($key.'Mime', $image['type']);
286 286
 
287
-		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core');
287
+        $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core');
288 288
 
289
-		return new DataResponse(
290
-			[
291
-				'data' =>
292
-					[
293
-						'name' => $name,
294
-						'url' => $this->imageManager->getImageUrl($key),
295
-						'message' => $this->l10n->t('Saved'),
296
-						'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss'))
297
-					],
298
-				'status' => 'success'
299
-			]
300
-		);
301
-	}
289
+        return new DataResponse(
290
+            [
291
+                'data' =>
292
+                    [
293
+                        'name' => $name,
294
+                        'url' => $this->imageManager->getImageUrl($key),
295
+                        'message' => $this->l10n->t('Saved'),
296
+                        'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss'))
297
+                    ],
298
+                'status' => 'success'
299
+            ]
300
+        );
301
+    }
302 302
 
303
-	/**
304
-	 * Revert setting to default value
305
-	 *
306
-	 * @param string $setting setting which should be reverted
307
-	 * @return DataResponse
308
-	 * @throws NotPermittedException
309
-	 */
310
-	public function undo(string $setting): DataResponse {
311
-		$value = $this->themingDefaults->undo($setting);
312
-		// reprocess server scss for preview
313
-		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core');
303
+    /**
304
+     * Revert setting to default value
305
+     *
306
+     * @param string $setting setting which should be reverted
307
+     * @return DataResponse
308
+     * @throws NotPermittedException
309
+     */
310
+    public function undo(string $setting): DataResponse {
311
+        $value = $this->themingDefaults->undo($setting);
312
+        // reprocess server scss for preview
313
+        $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core');
314 314
 
315
-		if (strpos($setting, 'Mime') !== -1) {
316
-			$imageKey = str_replace('Mime', '', $setting);
317
-			$this->imageManager->delete($imageKey);
318
-		}
315
+        if (strpos($setting, 'Mime') !== -1) {
316
+            $imageKey = str_replace('Mime', '', $setting);
317
+            $this->imageManager->delete($imageKey);
318
+        }
319 319
 
320
-		return new DataResponse(
321
-			[
322
-				'data' =>
323
-					[
324
-						'value' => $value,
325
-						'message' => $this->l10n->t('Saved'),
326
-						'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss'))
327
-					],
328
-				'status' => 'success'
329
-			]
330
-		);
331
-	}
320
+        return new DataResponse(
321
+            [
322
+                'data' =>
323
+                    [
324
+                        'value' => $value,
325
+                        'message' => $this->l10n->t('Saved'),
326
+                        'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss'))
327
+                    ],
328
+                'status' => 'success'
329
+            ]
330
+        );
331
+    }
332 332
 
333
-	/**
334
-	 * @PublicPage
335
-	 * @NoCSRFRequired
336
-	 *
337
-	 * @param string $key
338
-	 * @return FileDisplayResponse|NotFoundResponse
339
-	 * @throws \Exception
340
-	 */
341
-	public function getImage(string $key) {
342
-		try {
343
-			$file = $this->imageManager->getImage($key);
344
-		} catch (NotFoundException $e) {
345
-			return new NotFoundResponse();
346
-		}
333
+    /**
334
+     * @PublicPage
335
+     * @NoCSRFRequired
336
+     *
337
+     * @param string $key
338
+     * @return FileDisplayResponse|NotFoundResponse
339
+     * @throws \Exception
340
+     */
341
+    public function getImage(string $key) {
342
+        try {
343
+            $file = $this->imageManager->getImage($key);
344
+        } catch (NotFoundException $e) {
345
+            return new NotFoundResponse();
346
+        }
347 347
 
348
-		$response = new FileDisplayResponse($file);
349
-		$response->cacheFor(3600);
350
-		$expires = new \DateTime();
351
-		$expires->setTimestamp($this->timeFactory->getTime());
352
-		$expires->add(new \DateInterval('PT24H'));
353
-		$response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
354
-		$response->addHeader('Pragma', 'cache');
355
-		$response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', ''));
356
-		return $response;
357
-	}
348
+        $response = new FileDisplayResponse($file);
349
+        $response->cacheFor(3600);
350
+        $expires = new \DateTime();
351
+        $expires->setTimestamp($this->timeFactory->getTime());
352
+        $expires->add(new \DateInterval('PT24H'));
353
+        $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
354
+        $response->addHeader('Pragma', 'cache');
355
+        $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', ''));
356
+        return $response;
357
+    }
358 358
 
359
-	/**
360
-	 * @NoCSRFRequired
361
-	 * @PublicPage
362
-	 *
363
-	 * @return FileDisplayResponse|NotFoundResponse
364
-	 * @throws NotPermittedException
365
-	 * @throws \Exception
366
-	 * @throws \OCP\App\AppPathNotFoundException
367
-	 */
368
-	public function getStylesheet() {
369
-		$appPath = $this->appManager->getAppPath('theming');
359
+    /**
360
+     * @NoCSRFRequired
361
+     * @PublicPage
362
+     *
363
+     * @return FileDisplayResponse|NotFoundResponse
364
+     * @throws NotPermittedException
365
+     * @throws \Exception
366
+     * @throws \OCP\App\AppPathNotFoundException
367
+     */
368
+    public function getStylesheet() {
369
+        $appPath = $this->appManager->getAppPath('theming');
370 370
 
371
-		/* SCSSCacher is required here
371
+        /* SCSSCacher is required here
372 372
 		 * We cannot rely on automatic caching done by \OC_Util::addStyle,
373 373
 		 * since we need to add the cacheBuster value to the url
374 374
 		 */
375
-		$cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming');
376
-		if(!$cssCached) {
377
-			return new NotFoundResponse();
378
-		}
375
+        $cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming');
376
+        if(!$cssCached) {
377
+            return new NotFoundResponse();
378
+        }
379 379
 
380
-		try {
381
-			$cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css');
382
-			$response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']);
383
-			$response->cacheFor(86400);
384
-			$expires = new \DateTime();
385
-			$expires->setTimestamp($this->timeFactory->getTime());
386
-			$expires->add(new \DateInterval('PT24H'));
387
-			$response->addHeader('Expires', $expires->format(\DateTime::RFC1123));
388
-			$response->addHeader('Pragma', 'cache');
389
-			return $response;
390
-		} catch (NotFoundException $e) {
391
-			return new NotFoundResponse();
392
-		}
393
-	}
380
+        try {
381
+            $cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css');
382
+            $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']);
383
+            $response->cacheFor(86400);
384
+            $expires = new \DateTime();
385
+            $expires->setTimestamp($this->timeFactory->getTime());
386
+            $expires->add(new \DateInterval('PT24H'));
387
+            $response->addHeader('Expires', $expires->format(\DateTime::RFC1123));
388
+            $response->addHeader('Pragma', 'cache');
389
+            return $response;
390
+        } catch (NotFoundException $e) {
391
+            return new NotFoundResponse();
392
+        }
393
+    }
394 394
 
395
-	/**
396
-	 * @NoCSRFRequired
397
-	 * @PublicPage
398
-	 *
399
-	 * @return DataDownloadResponse
400
-	 */
401
-	public function getJavascript() {
402
-		$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
403
-		$responseJS = '(function() {
395
+    /**
396
+     * @NoCSRFRequired
397
+     * @PublicPage
398
+     *
399
+     * @return DataDownloadResponse
400
+     */
401
+    public function getJavascript() {
402
+        $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
403
+        $responseJS = '(function() {
404 404
 	OCA.Theming = {
405 405
 		name: ' . json_encode($this->themingDefaults->getName()) . ',
406 406
 		url: ' . json_encode($this->themingDefaults->getBaseUrl()) . ',
@@ -410,45 +410,45 @@  discard block
 block discarded – undo
410 410
 		cacheBuster: ' . json_encode($cacheBusterValue) . '
411 411
 	};
412 412
 })();';
413
-		$response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript');
414
-		$response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
415
-		$response->addHeader('Pragma', 'cache');
416
-		$response->cacheFor(3600);
417
-		return $response;
418
-	}
413
+        $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript');
414
+        $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
415
+        $response->addHeader('Pragma', 'cache');
416
+        $response->cacheFor(3600);
417
+        return $response;
418
+    }
419 419
 
420
-	/**
421
-	 * @NoCSRFRequired
422
-	 * @PublicPage
423
-	 *
424
-	 * @return Http\JSONResponse
425
-	 */
426
-	public function getManifest($app) {
427
-		$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
428
-		$responseJS = [
429
-			'name' => $this->themingDefaults->getName(),
430
-			'start_url' => $this->urlGenerator->getBaseUrl(),
431
-			'icons' =>
432
-				[
433
-					[
434
-						'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon',
435
-								['app' => $app]) . '?v=' . $cacheBusterValue,
436
-						'type'=> 'image/png',
437
-						'sizes'=> '128x128'
438
-					],
439
-					[
440
-						'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon',
441
-								['app' => $app]) . '?v=' . $cacheBusterValue,
442
-						'type' => 'image/svg+xml',
443
-						'sizes' => '16x16'
444
-					]
445
-				],
446
-			'display' => 'standalone'
447
-		];
448
-		$response = new Http\JSONResponse($responseJS);
449
-		$response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
450
-		$response->addHeader('Pragma', 'cache');
451
-		$response->cacheFor(3600);
452
-		return $response;
453
-	}
420
+    /**
421
+     * @NoCSRFRequired
422
+     * @PublicPage
423
+     *
424
+     * @return Http\JSONResponse
425
+     */
426
+    public function getManifest($app) {
427
+        $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
428
+        $responseJS = [
429
+            'name' => $this->themingDefaults->getName(),
430
+            'start_url' => $this->urlGenerator->getBaseUrl(),
431
+            'icons' =>
432
+                [
433
+                    [
434
+                        'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon',
435
+                                ['app' => $app]) . '?v=' . $cacheBusterValue,
436
+                        'type'=> 'image/png',
437
+                        'sizes'=> '128x128'
438
+                    ],
439
+                    [
440
+                        'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon',
441
+                                ['app' => $app]) . '?v=' . $cacheBusterValue,
442
+                        'type' => 'image/svg+xml',
443
+                        'sizes' => '16x16'
444
+                    ]
445
+                ],
446
+            'display' => 'standalone'
447
+        ];
448
+        $response = new Http\JSONResponse($responseJS);
449
+        $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
450
+        $response->addHeader('Pragma', 'cache');
451
+        $response->cacheFor(3600);
452
+        return $response;
453
+    }
454 454
 }
Please login to merge, or discard this patch.
apps/theming/lib/ThemingDefaults.php 1 patch
Indentation   +334 added lines, -334 removed lines patch added patch discarded remove patch
@@ -44,338 +44,338 @@
 block discarded – undo
44 44
 
45 45
 class ThemingDefaults extends \OC_Defaults {
46 46
 
47
-	/** @var IConfig */
48
-	private $config;
49
-	/** @var IL10N */
50
-	private $l;
51
-	/** @var ImageManager */
52
-	private $imageManager;
53
-	/** @var IURLGenerator */
54
-	private $urlGenerator;
55
-	/** @var ICacheFactory */
56
-	private $cacheFactory;
57
-	/** @var Util */
58
-	private $util;
59
-	/** @var IAppManager */
60
-	private $appManager;
61
-	/** @var string */
62
-	private $name;
63
-	/** @var string */
64
-	private $title;
65
-	/** @var string */
66
-	private $entity;
67
-	/** @var string */
68
-	private $url;
69
-	/** @var string */
70
-	private $slogan;
71
-	/** @var string */
72
-	private $color;
73
-
74
-	/** @var string */
75
-	private $iTunesAppId;
76
-	/** @var string */
77
-	private $iOSClientUrl;
78
-	/** @var string */
79
-	private $AndroidClientUrl;
80
-
81
-	/**
82
-	 * ThemingDefaults constructor.
83
-	 *
84
-	 * @param IConfig $config
85
-	 * @param IL10N $l
86
-	 * @param ImageManager $imageManager
87
-	 * @param IURLGenerator $urlGenerator
88
-	 * @param ICacheFactory $cacheFactory
89
-	 * @param Util $util
90
-	 * @param IAppManager $appManager
91
-	 */
92
-	public function __construct(IConfig $config,
93
-								IL10N $l,
94
-								IURLGenerator $urlGenerator,
95
-								ICacheFactory $cacheFactory,
96
-								Util $util,
97
-								ImageManager $imageManager,
98
-								IAppManager $appManager
99
-	) {
100
-		parent::__construct();
101
-		$this->config = $config;
102
-		$this->l = $l;
103
-		$this->imageManager = $imageManager;
104
-		$this->urlGenerator = $urlGenerator;
105
-		$this->cacheFactory = $cacheFactory;
106
-		$this->util = $util;
107
-		$this->appManager = $appManager;
108
-
109
-		$this->name = parent::getName();
110
-		$this->title = parent::getTitle();
111
-		$this->entity = parent::getEntity();
112
-		$this->url = parent::getBaseUrl();
113
-		$this->slogan = parent::getSlogan();
114
-		$this->color = parent::getColorPrimary();
115
-		$this->iTunesAppId = parent::getiTunesAppId();
116
-		$this->iOSClientUrl = parent::getiOSClientUrl();
117
-		$this->AndroidClientUrl = parent::getAndroidClientUrl();
118
-	}
119
-
120
-	public function getName() {
121
-		return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
122
-	}
123
-
124
-	public function getHTMLName() {
125
-		return $this->config->getAppValue('theming', 'name', $this->name);
126
-	}
127
-
128
-	public function getTitle() {
129
-		return strip_tags($this->config->getAppValue('theming', 'name', $this->title));
130
-	}
131
-
132
-	public function getEntity() {
133
-		return strip_tags($this->config->getAppValue('theming', 'name', $this->entity));
134
-	}
135
-
136
-	public function getBaseUrl() {
137
-		return $this->config->getAppValue('theming', 'url', $this->url);
138
-	}
139
-
140
-	public function getSlogan() {
141
-		return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan));
142
-	}
143
-
144
-	public function getShortFooter() {
145
-		$slogan = $this->getSlogan();
146
-		$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
147
-			' rel="noreferrer noopener">' .$this->getEntity() . '</a>'.
148
-			($slogan !== '' ? ' – ' . $slogan : '');
149
-
150
-		return $footer;
151
-	}
152
-
153
-	/**
154
-	 * Color that is used for the header as well as for mail headers
155
-	 *
156
-	 * @return string
157
-	 */
158
-	public function getColorPrimary() {
159
-		return $this->config->getAppValue('theming', 'color', $this->color);
160
-	}
161
-
162
-	/**
163
-	 * Themed logo url
164
-	 *
165
-	 * @param bool $useSvg Whether to point to the SVG image or a fallback
166
-	 * @return string
167
-	 */
168
-	public function getLogo($useSvg = true): string {
169
-		$logo = $this->config->getAppValue('theming', 'logoMime', false);
170
-
171
-		$logoExists = true;
172
-		try {
173
-			$this->imageManager->getImage('logo');
174
-		} catch (\Exception $e) {
175
-			$logoExists = false;
176
-		}
177
-
178
-		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
179
-
180
-		if(!$logo || !$logoExists) {
181
-			if($useSvg) {
182
-				$logo = $this->urlGenerator->imagePath('core', 'logo.svg');
183
-			} else {
184
-				$logo = $this->urlGenerator->imagePath('core', 'logo.png');
185
-			}
186
-			return $logo . '?v=' . $cacheBusterCounter;
187
-		}
188
-
189
-		return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo' ]) . '?v=' . $cacheBusterCounter;
190
-	}
191
-
192
-	/**
193
-	 * Themed background image url
194
-	 *
195
-	 * @return string
196
-	 */
197
-	public function getBackground(): string {
198
-		return $this->imageManager->getImageUrl('background');
199
-	}
200
-
201
-	/**
202
-	 * @return string
203
-	 */
204
-	public function getiTunesAppId() {
205
-		return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId);
206
-	}
207
-
208
-	/**
209
-	 * @return string
210
-	 */
211
-	public function getiOSClientUrl() {
212
-		return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl);
213
-	}
214
-
215
-	/**
216
-	 * @return string
217
-	 */
218
-	public function getAndroidClientUrl() {
219
-		return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl);
220
-	}
221
-
222
-
223
-	/**
224
-	 * @return array scss variables to overwrite
225
-	 */
226
-	public function getScssVariables() {
227
-		$cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl());
228
-		if ($value = $cache->get('getScssVariables')) {
229
-			return $value;
230
-		}
231
-
232
-		$variables = [
233
-			'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'",
234
-			'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'",
235
-			'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'",
236
-			'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'",
237
-			'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'"
238
-		];
239
-
240
-		$variables['image-logo'] = "'".$this->imageManager->getImageUrl('logo')."'";
241
-		$variables['image-logoheader'] = "'".$this->imageManager->getImageUrl('logoheader')."'";
242
-		$variables['image-favicon'] = "'".$this->imageManager->getImageUrl('favicon')."'";
243
-		$variables['image-login-background'] = "'".$this->imageManager->getImageUrl('background')."'";
244
-		$variables['image-login-plain'] = 'false';
245
-
246
-		if ($this->config->getAppValue('theming', 'color', null) !== null) {
247
-			$variables['color-primary'] = $this->getColorPrimary();
248
-			$variables['color-primary-text'] = $this->getTextColorPrimary();
249
-			$variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary());
250
-		}
251
-
252
-		if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') {
253
-			$variables['image-login-plain'] = 'true';
254
-		}
255
-		$cache->set('getScssVariables', $variables);
256
-		return $variables;
257
-	}
258
-
259
-	/**
260
-	 * Check if the image should be replaced by the theming app
261
-	 * and return the new image location then
262
-	 *
263
-	 * @param string $app name of the app
264
-	 * @param string $image filename of the image
265
-	 * @return bool|string false if image should not replaced, otherwise the location of the image
266
-	 */
267
-	public function replaceImagePath($app, $image) {
268
-		if($app==='') {
269
-			$app = 'core';
270
-		}
271
-		$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
272
-
273
-		try {
274
-			$customFavicon = $this->imageManager->getImage('favicon');
275
-		} catch (NotFoundException $e) {
276
-			$customFavicon = null;
277
-		}
278
-
279
-		if ($image === 'favicon.ico' && ($customFavicon !== null || $this->shouldReplaceIcons())) {
280
-			return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue;
281
-		}
282
-		if ($image === 'favicon-touch.png' && ($customFavicon !== null || $this->shouldReplaceIcons())) {
283
-			return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue;
284
-		}
285
-		if ($image === 'manifest.json') {
286
-			try {
287
-				$appPath = $this->appManager->getAppPath($app);
288
-				if (file_exists($appPath . '/img/manifest.json')) {
289
-					return false;
290
-				}
291
-			} catch (AppPathNotFoundException $e) {}
292
-			return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue;
293
-		}
294
-		return false;
295
-	}
296
-
297
-	/**
298
-	 * Check if Imagemagick is enabled and if SVG is supported
299
-	 * otherwise we can't render custom icons
300
-	 *
301
-	 * @return bool
302
-	 */
303
-	public function shouldReplaceIcons() {
304
-		$cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl());
305
-		if($value = $cache->get('shouldReplaceIcons')) {
306
-			return (bool)$value;
307
-		}
308
-		$value = false;
309
-		if(extension_loaded('imagick')) {
310
-			$checkImagick = new \Imagick();
311
-			if (count($checkImagick->queryFormats('SVG')) >= 1) {
312
-				$value = true;
313
-			}
314
-			$checkImagick->clear();
315
-		}
316
-		$cache->set('shouldReplaceIcons', $value);
317
-		return $value;
318
-	}
319
-
320
-	/**
321
-	 * Increases the cache buster key
322
-	 */
323
-	private function increaseCacheBuster() {
324
-		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
325
-		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
326
-		$this->cacheFactory->createDistributed('theming-')->clear();
327
-		$this->cacheFactory->createDistributed('imagePath')->clear();
328
-
329
-	}
330
-
331
-	/**
332
-	 * Update setting in the database
333
-	 *
334
-	 * @param string $setting
335
-	 * @param string $value
336
-	 */
337
-	public function set($setting, $value) {
338
-		$this->config->setAppValue('theming', $setting, $value);
339
-		$this->increaseCacheBuster();
340
-	}
341
-
342
-	/**
343
-	 * Revert settings to the default value
344
-	 *
345
-	 * @param string $setting setting which should be reverted
346
-	 * @return string default value
347
-	 */
348
-	public function undo($setting) {
349
-		$this->config->deleteAppValue('theming', $setting);
350
-		$this->increaseCacheBuster();
351
-
352
-		switch ($setting) {
353
-			case 'name':
354
-				$returnValue = $this->getEntity();
355
-				break;
356
-			case 'url':
357
-				$returnValue = $this->getBaseUrl();
358
-				break;
359
-			case 'slogan':
360
-				$returnValue = $this->getSlogan();
361
-				break;
362
-			case 'color':
363
-				$returnValue = $this->getColorPrimary();
364
-				break;
365
-			default:
366
-				$returnValue = '';
367
-				break;
368
-		}
369
-
370
-		return $returnValue;
371
-	}
372
-
373
-	/**
374
-	 * Color of text in the header and primary buttons
375
-	 *
376
-	 * @return string
377
-	 */
378
-	public function getTextColorPrimary() {
379
-		return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff';
380
-	}
47
+    /** @var IConfig */
48
+    private $config;
49
+    /** @var IL10N */
50
+    private $l;
51
+    /** @var ImageManager */
52
+    private $imageManager;
53
+    /** @var IURLGenerator */
54
+    private $urlGenerator;
55
+    /** @var ICacheFactory */
56
+    private $cacheFactory;
57
+    /** @var Util */
58
+    private $util;
59
+    /** @var IAppManager */
60
+    private $appManager;
61
+    /** @var string */
62
+    private $name;
63
+    /** @var string */
64
+    private $title;
65
+    /** @var string */
66
+    private $entity;
67
+    /** @var string */
68
+    private $url;
69
+    /** @var string */
70
+    private $slogan;
71
+    /** @var string */
72
+    private $color;
73
+
74
+    /** @var string */
75
+    private $iTunesAppId;
76
+    /** @var string */
77
+    private $iOSClientUrl;
78
+    /** @var string */
79
+    private $AndroidClientUrl;
80
+
81
+    /**
82
+     * ThemingDefaults constructor.
83
+     *
84
+     * @param IConfig $config
85
+     * @param IL10N $l
86
+     * @param ImageManager $imageManager
87
+     * @param IURLGenerator $urlGenerator
88
+     * @param ICacheFactory $cacheFactory
89
+     * @param Util $util
90
+     * @param IAppManager $appManager
91
+     */
92
+    public function __construct(IConfig $config,
93
+                                IL10N $l,
94
+                                IURLGenerator $urlGenerator,
95
+                                ICacheFactory $cacheFactory,
96
+                                Util $util,
97
+                                ImageManager $imageManager,
98
+                                IAppManager $appManager
99
+    ) {
100
+        parent::__construct();
101
+        $this->config = $config;
102
+        $this->l = $l;
103
+        $this->imageManager = $imageManager;
104
+        $this->urlGenerator = $urlGenerator;
105
+        $this->cacheFactory = $cacheFactory;
106
+        $this->util = $util;
107
+        $this->appManager = $appManager;
108
+
109
+        $this->name = parent::getName();
110
+        $this->title = parent::getTitle();
111
+        $this->entity = parent::getEntity();
112
+        $this->url = parent::getBaseUrl();
113
+        $this->slogan = parent::getSlogan();
114
+        $this->color = parent::getColorPrimary();
115
+        $this->iTunesAppId = parent::getiTunesAppId();
116
+        $this->iOSClientUrl = parent::getiOSClientUrl();
117
+        $this->AndroidClientUrl = parent::getAndroidClientUrl();
118
+    }
119
+
120
+    public function getName() {
121
+        return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
122
+    }
123
+
124
+    public function getHTMLName() {
125
+        return $this->config->getAppValue('theming', 'name', $this->name);
126
+    }
127
+
128
+    public function getTitle() {
129
+        return strip_tags($this->config->getAppValue('theming', 'name', $this->title));
130
+    }
131
+
132
+    public function getEntity() {
133
+        return strip_tags($this->config->getAppValue('theming', 'name', $this->entity));
134
+    }
135
+
136
+    public function getBaseUrl() {
137
+        return $this->config->getAppValue('theming', 'url', $this->url);
138
+    }
139
+
140
+    public function getSlogan() {
141
+        return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan));
142
+    }
143
+
144
+    public function getShortFooter() {
145
+        $slogan = $this->getSlogan();
146
+        $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
147
+            ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'.
148
+            ($slogan !== '' ? ' – ' . $slogan : '');
149
+
150
+        return $footer;
151
+    }
152
+
153
+    /**
154
+     * Color that is used for the header as well as for mail headers
155
+     *
156
+     * @return string
157
+     */
158
+    public function getColorPrimary() {
159
+        return $this->config->getAppValue('theming', 'color', $this->color);
160
+    }
161
+
162
+    /**
163
+     * Themed logo url
164
+     *
165
+     * @param bool $useSvg Whether to point to the SVG image or a fallback
166
+     * @return string
167
+     */
168
+    public function getLogo($useSvg = true): string {
169
+        $logo = $this->config->getAppValue('theming', 'logoMime', false);
170
+
171
+        $logoExists = true;
172
+        try {
173
+            $this->imageManager->getImage('logo');
174
+        } catch (\Exception $e) {
175
+            $logoExists = false;
176
+        }
177
+
178
+        $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
179
+
180
+        if(!$logo || !$logoExists) {
181
+            if($useSvg) {
182
+                $logo = $this->urlGenerator->imagePath('core', 'logo.svg');
183
+            } else {
184
+                $logo = $this->urlGenerator->imagePath('core', 'logo.png');
185
+            }
186
+            return $logo . '?v=' . $cacheBusterCounter;
187
+        }
188
+
189
+        return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo' ]) . '?v=' . $cacheBusterCounter;
190
+    }
191
+
192
+    /**
193
+     * Themed background image url
194
+     *
195
+     * @return string
196
+     */
197
+    public function getBackground(): string {
198
+        return $this->imageManager->getImageUrl('background');
199
+    }
200
+
201
+    /**
202
+     * @return string
203
+     */
204
+    public function getiTunesAppId() {
205
+        return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId);
206
+    }
207
+
208
+    /**
209
+     * @return string
210
+     */
211
+    public function getiOSClientUrl() {
212
+        return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl);
213
+    }
214
+
215
+    /**
216
+     * @return string
217
+     */
218
+    public function getAndroidClientUrl() {
219
+        return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl);
220
+    }
221
+
222
+
223
+    /**
224
+     * @return array scss variables to overwrite
225
+     */
226
+    public function getScssVariables() {
227
+        $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl());
228
+        if ($value = $cache->get('getScssVariables')) {
229
+            return $value;
230
+        }
231
+
232
+        $variables = [
233
+            'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'",
234
+            'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'",
235
+            'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'",
236
+            'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'",
237
+            'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'"
238
+        ];
239
+
240
+        $variables['image-logo'] = "'".$this->imageManager->getImageUrl('logo')."'";
241
+        $variables['image-logoheader'] = "'".$this->imageManager->getImageUrl('logoheader')."'";
242
+        $variables['image-favicon'] = "'".$this->imageManager->getImageUrl('favicon')."'";
243
+        $variables['image-login-background'] = "'".$this->imageManager->getImageUrl('background')."'";
244
+        $variables['image-login-plain'] = 'false';
245
+
246
+        if ($this->config->getAppValue('theming', 'color', null) !== null) {
247
+            $variables['color-primary'] = $this->getColorPrimary();
248
+            $variables['color-primary-text'] = $this->getTextColorPrimary();
249
+            $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary());
250
+        }
251
+
252
+        if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') {
253
+            $variables['image-login-plain'] = 'true';
254
+        }
255
+        $cache->set('getScssVariables', $variables);
256
+        return $variables;
257
+    }
258
+
259
+    /**
260
+     * Check if the image should be replaced by the theming app
261
+     * and return the new image location then
262
+     *
263
+     * @param string $app name of the app
264
+     * @param string $image filename of the image
265
+     * @return bool|string false if image should not replaced, otherwise the location of the image
266
+     */
267
+    public function replaceImagePath($app, $image) {
268
+        if($app==='') {
269
+            $app = 'core';
270
+        }
271
+        $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
272
+
273
+        try {
274
+            $customFavicon = $this->imageManager->getImage('favicon');
275
+        } catch (NotFoundException $e) {
276
+            $customFavicon = null;
277
+        }
278
+
279
+        if ($image === 'favicon.ico' && ($customFavicon !== null || $this->shouldReplaceIcons())) {
280
+            return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue;
281
+        }
282
+        if ($image === 'favicon-touch.png' && ($customFavicon !== null || $this->shouldReplaceIcons())) {
283
+            return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue;
284
+        }
285
+        if ($image === 'manifest.json') {
286
+            try {
287
+                $appPath = $this->appManager->getAppPath($app);
288
+                if (file_exists($appPath . '/img/manifest.json')) {
289
+                    return false;
290
+                }
291
+            } catch (AppPathNotFoundException $e) {}
292
+            return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue;
293
+        }
294
+        return false;
295
+    }
296
+
297
+    /**
298
+     * Check if Imagemagick is enabled and if SVG is supported
299
+     * otherwise we can't render custom icons
300
+     *
301
+     * @return bool
302
+     */
303
+    public function shouldReplaceIcons() {
304
+        $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl());
305
+        if($value = $cache->get('shouldReplaceIcons')) {
306
+            return (bool)$value;
307
+        }
308
+        $value = false;
309
+        if(extension_loaded('imagick')) {
310
+            $checkImagick = new \Imagick();
311
+            if (count($checkImagick->queryFormats('SVG')) >= 1) {
312
+                $value = true;
313
+            }
314
+            $checkImagick->clear();
315
+        }
316
+        $cache->set('shouldReplaceIcons', $value);
317
+        return $value;
318
+    }
319
+
320
+    /**
321
+     * Increases the cache buster key
322
+     */
323
+    private function increaseCacheBuster() {
324
+        $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
325
+        $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
326
+        $this->cacheFactory->createDistributed('theming-')->clear();
327
+        $this->cacheFactory->createDistributed('imagePath')->clear();
328
+
329
+    }
330
+
331
+    /**
332
+     * Update setting in the database
333
+     *
334
+     * @param string $setting
335
+     * @param string $value
336
+     */
337
+    public function set($setting, $value) {
338
+        $this->config->setAppValue('theming', $setting, $value);
339
+        $this->increaseCacheBuster();
340
+    }
341
+
342
+    /**
343
+     * Revert settings to the default value
344
+     *
345
+     * @param string $setting setting which should be reverted
346
+     * @return string default value
347
+     */
348
+    public function undo($setting) {
349
+        $this->config->deleteAppValue('theming', $setting);
350
+        $this->increaseCacheBuster();
351
+
352
+        switch ($setting) {
353
+            case 'name':
354
+                $returnValue = $this->getEntity();
355
+                break;
356
+            case 'url':
357
+                $returnValue = $this->getBaseUrl();
358
+                break;
359
+            case 'slogan':
360
+                $returnValue = $this->getSlogan();
361
+                break;
362
+            case 'color':
363
+                $returnValue = $this->getColorPrimary();
364
+                break;
365
+            default:
366
+                $returnValue = '';
367
+                break;
368
+        }
369
+
370
+        return $returnValue;
371
+    }
372
+
373
+    /**
374
+     * Color of text in the header and primary buttons
375
+     *
376
+     * @return string
377
+     */
378
+    public function getTextColorPrimary() {
379
+        return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff';
380
+    }
381 381
 }
Please login to merge, or discard this patch.
lib/private/Server.php 1 patch
Indentation   +1807 added lines, -1807 removed lines patch added patch discarded remove patch
@@ -151,1816 +151,1816 @@
 block discarded – undo
151 151
  * TODO: hookup all manager classes
152 152
  */
153 153
 class Server extends ServerContainer implements IServerContainer {
154
-	/** @var string */
155
-	private $webRoot;
156
-
157
-	/**
158
-	 * @param string $webRoot
159
-	 * @param \OC\Config $config
160
-	 */
161
-	public function __construct($webRoot, \OC\Config $config) {
162
-		parent::__construct();
163
-		$this->webRoot = $webRoot;
164
-
165
-		$this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
166
-			return $c;
167
-		});
168
-
169
-		$this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
170
-		$this->registerAlias('CalendarManager', \OC\Calendar\Manager::class);
171
-
172
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
173
-		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
174
-
175
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
176
-
177
-
178
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
179
-			return new PreviewManager(
180
-				$c->getConfig(),
181
-				$c->getRootFolder(),
182
-				$c->getAppDataDir('preview'),
183
-				$c->getEventDispatcher(),
184
-				$c->getSession()->get('user_id')
185
-			);
186
-		});
187
-		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
188
-
189
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
190
-			return new \OC\Preview\Watcher(
191
-				$c->getAppDataDir('preview')
192
-			);
193
-		});
194
-
195
-		$this->registerService('EncryptionManager', function (Server $c) {
196
-			$view = new View();
197
-			$util = new Encryption\Util(
198
-				$view,
199
-				$c->getUserManager(),
200
-				$c->getGroupManager(),
201
-				$c->getConfig()
202
-			);
203
-			return new Encryption\Manager(
204
-				$c->getConfig(),
205
-				$c->getLogger(),
206
-				$c->getL10N('core'),
207
-				new View(),
208
-				$util,
209
-				new ArrayCache()
210
-			);
211
-		});
212
-
213
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
214
-			$util = new Encryption\Util(
215
-				new View(),
216
-				$c->getUserManager(),
217
-				$c->getGroupManager(),
218
-				$c->getConfig()
219
-			);
220
-			return new Encryption\File(
221
-				$util,
222
-				$c->getRootFolder(),
223
-				$c->getShareManager()
224
-			);
225
-		});
226
-
227
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
228
-			$view = new View();
229
-			$util = new Encryption\Util(
230
-				$view,
231
-				$c->getUserManager(),
232
-				$c->getGroupManager(),
233
-				$c->getConfig()
234
-			);
235
-
236
-			return new Encryption\Keys\Storage($view, $util);
237
-		});
238
-		$this->registerService('TagMapper', function (Server $c) {
239
-			return new TagMapper($c->getDatabaseConnection());
240
-		});
241
-
242
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
243
-			$tagMapper = $c->query('TagMapper');
244
-			return new TagManager($tagMapper, $c->getUserSession());
245
-		});
246
-		$this->registerAlias('TagManager', \OCP\ITagManager::class);
247
-
248
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
249
-			$config = $c->getConfig();
250
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
251
-			return new $factoryClass($this);
252
-		});
253
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
254
-			return $c->query('SystemTagManagerFactory')->getManager();
255
-		});
256
-		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
257
-
258
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
259
-			return $c->query('SystemTagManagerFactory')->getObjectMapper();
260
-		});
261
-		$this->registerService('RootFolder', function (Server $c) {
262
-			$manager = \OC\Files\Filesystem::getMountManager(null);
263
-			$view = new View();
264
-			$root = new Root(
265
-				$manager,
266
-				$view,
267
-				null,
268
-				$c->getUserMountCache(),
269
-				$this->getLogger(),
270
-				$this->getUserManager()
271
-			);
272
-			$connector = new HookConnector($root, $view);
273
-			$connector->viewToNode();
274
-
275
-			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
276
-			$previewConnector->connectWatcher();
277
-
278
-			return $root;
279
-		});
280
-		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
281
-
282
-		$this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
283
-			return new LazyRoot(function () use ($c) {
284
-				return $c->query('RootFolder');
285
-			});
286
-		});
287
-		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
288
-
289
-		$this->registerService(\OC\User\Manager::class, function (Server $c) {
290
-			$config = $c->getConfig();
291
-			return new \OC\User\Manager($config);
292
-		});
293
-		$this->registerAlias('UserManager', \OC\User\Manager::class);
294
-		$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
295
-
296
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
297
-			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
298
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
299
-				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
300
-			});
301
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
302
-				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
303
-			});
304
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
305
-				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
306
-			});
307
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
308
-				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
309
-			});
310
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
311
-				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
312
-			});
313
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
314
-				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
315
-				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
316
-				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
317
-			});
318
-			return $groupManager;
319
-		});
320
-		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
321
-
322
-		$this->registerService(Store::class, function (Server $c) {
323
-			$session = $c->getSession();
324
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
325
-				$tokenProvider = $c->query(IProvider::class);
326
-			} else {
327
-				$tokenProvider = null;
328
-			}
329
-			$logger = $c->getLogger();
330
-			return new Store($session, $logger, $tokenProvider);
331
-		});
332
-		$this->registerAlias(IStore::class, Store::class);
333
-		$this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
334
-			$dbConnection = $c->getDatabaseConnection();
335
-			return new Authentication\Token\DefaultTokenMapper($dbConnection);
336
-		});
337
-		$this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) {
338
-			$mapper = $c->query(Authentication\Token\DefaultTokenMapper::class);
339
-			$crypto = $c->getCrypto();
340
-			$config = $c->getConfig();
341
-			$logger = $c->getLogger();
342
-			$timeFactory = new TimeFactory();
343
-			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
344
-		});
345
-		$this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class);
346
-
347
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
348
-			$manager = $c->getUserManager();
349
-			$session = new \OC\Session\Memory('');
350
-			$timeFactory = new TimeFactory();
351
-			// Token providers might require a working database. This code
352
-			// might however be called when ownCloud is not yet setup.
353
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
354
-				$defaultTokenProvider = $c->query(IProvider::class);
355
-			} else {
356
-				$defaultTokenProvider = null;
357
-			}
358
-
359
-			$dispatcher = $c->getEventDispatcher();
360
-
361
-			$userSession = new \OC\User\Session(
362
-				$manager,
363
-				$session,
364
-				$timeFactory,
365
-				$defaultTokenProvider,
366
-				$c->getConfig(),
367
-				$c->getSecureRandom(),
368
-				$c->getLockdownManager(),
369
-				$c->getLogger()
370
-			);
371
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
372
-				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
373
-			});
374
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
375
-				/** @var $user \OC\User\User */
376
-				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
377
-			});
378
-			$userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
379
-				/** @var $user \OC\User\User */
380
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
381
-				$dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
382
-			});
383
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
384
-				/** @var $user \OC\User\User */
385
-				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
386
-			});
387
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
388
-				/** @var $user \OC\User\User */
389
-				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
390
-			});
391
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
392
-				/** @var $user \OC\User\User */
393
-				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
394
-			});
395
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
396
-				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
397
-			});
398
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
399
-				/** @var $user \OC\User\User */
400
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
401
-			});
402
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
403
-				/** @var $user \OC\User\User */
404
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
405
-			});
406
-			$userSession->listen('\OC\User', 'logout', function () {
407
-				\OC_Hook::emit('OC_User', 'logout', array());
408
-			});
409
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) {
410
-				/** @var $user \OC\User\User */
411
-				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
412
-				$dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value]));
413
-			});
414
-			return $userSession;
415
-		});
416
-		$this->registerAlias('UserSession', \OCP\IUserSession::class);
417
-
418
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
419
-			return new \OC\Authentication\TwoFactorAuth\Manager(
420
-				$c->getAppManager(),
421
-				$c->getSession(),
422
-				$c->getConfig(),
423
-				$c->getActivityManager(),
424
-				$c->getLogger(),
425
-				$c->query(IProvider::class),
426
-				$c->query(ITimeFactory::class),
427
-				$c->query(EventDispatcherInterface::class)
428
-			);
429
-		});
430
-
431
-		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
432
-		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
433
-
434
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
435
-			return new \OC\AllConfig(
436
-				$c->getSystemConfig()
437
-			);
438
-		});
439
-		$this->registerAlias('AllConfig', \OC\AllConfig::class);
440
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
441
-
442
-		$this->registerService('SystemConfig', function ($c) use ($config) {
443
-			return new \OC\SystemConfig($config);
444
-		});
445
-
446
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
447
-			return new \OC\AppConfig($c->getDatabaseConnection());
448
-		});
449
-		$this->registerAlias('AppConfig', \OC\AppConfig::class);
450
-		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
451
-
452
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
453
-			return new \OC\L10N\Factory(
454
-				$c->getConfig(),
455
-				$c->getRequest(),
456
-				$c->getUserSession(),
457
-				\OC::$SERVERROOT
458
-			);
459
-		});
460
-		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
461
-
462
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
463
-			$config = $c->getConfig();
464
-			$cacheFactory = $c->getMemCacheFactory();
465
-			$request = $c->getRequest();
466
-			return new \OC\URLGenerator(
467
-				$config,
468
-				$cacheFactory,
469
-				$request
470
-			);
471
-		});
472
-		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
473
-
474
-		$this->registerAlias('AppFetcher', AppFetcher::class);
475
-		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
476
-
477
-		$this->registerService(\OCP\ICache::class, function ($c) {
478
-			return new Cache\File();
479
-		});
480
-		$this->registerAlias('UserCache', \OCP\ICache::class);
481
-
482
-		$this->registerService(Factory::class, function (Server $c) {
483
-
484
-			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
485
-				ArrayCache::class,
486
-				ArrayCache::class,
487
-				ArrayCache::class
488
-			);
489
-			$config = $c->getConfig();
490
-			$request = $c->getRequest();
491
-			$urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
492
-
493
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
494
-				$v = \OC_App::getAppVersions();
495
-				$v['core'] = implode(',', \OC_Util::getVersion());
496
-				$version = implode(',', $v);
497
-				$instanceId = \OC_Util::getInstanceId();
498
-				$path = \OC::$SERVERROOT;
499
-				$prefix = md5($instanceId . '-' . $version . '-' . $path);
500
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
501
-					$config->getSystemValue('memcache.local', null),
502
-					$config->getSystemValue('memcache.distributed', null),
503
-					$config->getSystemValue('memcache.locking', null)
504
-				);
505
-			}
506
-			return $arrayCacheFactory;
507
-
508
-		});
509
-		$this->registerAlias('MemCacheFactory', Factory::class);
510
-		$this->registerAlias(ICacheFactory::class, Factory::class);
511
-
512
-		$this->registerService('RedisFactory', function (Server $c) {
513
-			$systemConfig = $c->getSystemConfig();
514
-			return new RedisFactory($systemConfig);
515
-		});
516
-
517
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
518
-			return new \OC\Activity\Manager(
519
-				$c->getRequest(),
520
-				$c->getUserSession(),
521
-				$c->getConfig(),
522
-				$c->query(IValidator::class)
523
-			);
524
-		});
525
-		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
526
-
527
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
528
-			return new \OC\Activity\EventMerger(
529
-				$c->getL10N('lib')
530
-			);
531
-		});
532
-		$this->registerAlias(IValidator::class, Validator::class);
533
-
534
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
535
-			return new AvatarManager(
536
-				$c->query(\OC\User\Manager::class),
537
-				$c->getAppDataDir('avatar'),
538
-				$c->getL10N('lib'),
539
-				$c->getLogger(),
540
-				$c->getConfig()
541
-			);
542
-		});
543
-		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
544
-
545
-		$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
546
-
547
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
548
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
549
-			$logger = Log::getLogClass($logType);
550
-			call_user_func(array($logger, 'init'));
551
-			$config = $this->getSystemConfig();
552
-			$registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
553
-
554
-			return new Log($logger, $config, null, $registry);
555
-		});
556
-		$this->registerAlias('Logger', \OCP\ILogger::class);
557
-
558
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
559
-			$config = $c->getConfig();
560
-			return new \OC\BackgroundJob\JobList(
561
-				$c->getDatabaseConnection(),
562
-				$config,
563
-				new TimeFactory()
564
-			);
565
-		});
566
-		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
567
-
568
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
569
-			$cacheFactory = $c->getMemCacheFactory();
570
-			$logger = $c->getLogger();
571
-			if ($cacheFactory->isLocalCacheAvailable()) {
572
-				$router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
573
-			} else {
574
-				$router = new \OC\Route\Router($logger);
575
-			}
576
-			return $router;
577
-		});
578
-		$this->registerAlias('Router', \OCP\Route\IRouter::class);
579
-
580
-		$this->registerService(\OCP\ISearch::class, function ($c) {
581
-			return new Search();
582
-		});
583
-		$this->registerAlias('Search', \OCP\ISearch::class);
584
-
585
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
586
-			return new \OC\Security\RateLimiting\Limiter(
587
-				$this->getUserSession(),
588
-				$this->getRequest(),
589
-				new \OC\AppFramework\Utility\TimeFactory(),
590
-				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
591
-			);
592
-		});
593
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
594
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
595
-				$this->getMemCacheFactory(),
596
-				new \OC\AppFramework\Utility\TimeFactory()
597
-			);
598
-		});
599
-
600
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
601
-			return new SecureRandom();
602
-		});
603
-		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
604
-
605
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
606
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
607
-		});
608
-		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
609
-
610
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
611
-			return new Hasher($c->getConfig());
612
-		});
613
-		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
614
-
615
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
616
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
617
-		});
618
-		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
619
-
620
-		$this->registerService(IDBConnection::class, function (Server $c) {
621
-			$systemConfig = $c->getSystemConfig();
622
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
623
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
624
-			if (!$factory->isValidType($type)) {
625
-				throw new \OC\DatabaseException('Invalid database type');
626
-			}
627
-			$connectionParams = $factory->createConnectionParams();
628
-			$connection = $factory->getConnection($type, $connectionParams);
629
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
630
-			return $connection;
631
-		});
632
-		$this->registerAlias('DatabaseConnection', IDBConnection::class);
633
-
634
-
635
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
636
-			$user = \OC_User::getUser();
637
-			$uid = $user ? $user : null;
638
-			return new ClientService(
639
-				$c->getConfig(),
640
-				new \OC\Security\CertificateManager(
641
-					$uid,
642
-					new View(),
643
-					$c->getConfig(),
644
-					$c->getLogger(),
645
-					$c->getSecureRandom()
646
-				)
647
-			);
648
-		});
649
-		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
650
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
651
-			$eventLogger = new EventLogger();
652
-			if ($c->getSystemConfig()->getValue('debug', false)) {
653
-				// In debug mode, module is being activated by default
654
-				$eventLogger->activate();
655
-			}
656
-			return $eventLogger;
657
-		});
658
-		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
659
-
660
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
661
-			$queryLogger = new QueryLogger();
662
-			if ($c->getSystemConfig()->getValue('debug', false)) {
663
-				// In debug mode, module is being activated by default
664
-				$queryLogger->activate();
665
-			}
666
-			return $queryLogger;
667
-		});
668
-		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
669
-
670
-		$this->registerService(TempManager::class, function (Server $c) {
671
-			return new TempManager(
672
-				$c->getLogger(),
673
-				$c->getConfig()
674
-			);
675
-		});
676
-		$this->registerAlias('TempManager', TempManager::class);
677
-		$this->registerAlias(ITempManager::class, TempManager::class);
678
-
679
-		$this->registerService(AppManager::class, function (Server $c) {
680
-			return new \OC\App\AppManager(
681
-				$c->getUserSession(),
682
-				$c->query(\OC\AppConfig::class),
683
-				$c->getGroupManager(),
684
-				$c->getMemCacheFactory(),
685
-				$c->getEventDispatcher()
686
-			);
687
-		});
688
-		$this->registerAlias('AppManager', AppManager::class);
689
-		$this->registerAlias(IAppManager::class, AppManager::class);
690
-
691
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
692
-			return new DateTimeZone(
693
-				$c->getConfig(),
694
-				$c->getSession()
695
-			);
696
-		});
697
-		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
698
-
699
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
700
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
701
-
702
-			return new DateTimeFormatter(
703
-				$c->getDateTimeZone()->getTimeZone(),
704
-				$c->getL10N('lib', $language)
705
-			);
706
-		});
707
-		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
708
-
709
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
710
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
711
-			$listener = new UserMountCacheListener($mountCache);
712
-			$listener->listen($c->getUserManager());
713
-			return $mountCache;
714
-		});
715
-		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
716
-
717
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
718
-			$loader = \OC\Files\Filesystem::getLoader();
719
-			$mountCache = $c->query('UserMountCache');
720
-			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
721
-
722
-			// builtin providers
723
-
724
-			$config = $c->getConfig();
725
-			$manager->registerProvider(new CacheMountProvider($config));
726
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
727
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
728
-
729
-			return $manager;
730
-		});
731
-		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
732
-
733
-		$this->registerService('IniWrapper', function ($c) {
734
-			return new IniGetWrapper();
735
-		});
736
-		$this->registerService('AsyncCommandBus', function (Server $c) {
737
-			$busClass = $c->getConfig()->getSystemValue('commandbus');
738
-			if ($busClass) {
739
-				list($app, $class) = explode('::', $busClass, 2);
740
-				if ($c->getAppManager()->isInstalled($app)) {
741
-					\OC_App::loadApp($app);
742
-					return $c->query($class);
743
-				} else {
744
-					throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
745
-				}
746
-			} else {
747
-				$jobList = $c->getJobList();
748
-				return new CronBus($jobList);
749
-			}
750
-		});
751
-		$this->registerService('TrustedDomainHelper', function ($c) {
752
-			return new TrustedDomainHelper($this->getConfig());
753
-		});
754
-		$this->registerService('Throttler', function (Server $c) {
755
-			return new Throttler(
756
-				$c->getDatabaseConnection(),
757
-				new TimeFactory(),
758
-				$c->getLogger(),
759
-				$c->getConfig()
760
-			);
761
-		});
762
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
763
-			// IConfig and IAppManager requires a working database. This code
764
-			// might however be called when ownCloud is not yet setup.
765
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
766
-				$config = $c->getConfig();
767
-				$appManager = $c->getAppManager();
768
-			} else {
769
-				$config = null;
770
-				$appManager = null;
771
-			}
772
-
773
-			return new Checker(
774
-				new EnvironmentHelper(),
775
-				new FileAccessHelper(),
776
-				new AppLocator(),
777
-				$config,
778
-				$c->getMemCacheFactory(),
779
-				$appManager,
780
-				$c->getTempManager()
781
-			);
782
-		});
783
-		$this->registerService(\OCP\IRequest::class, function ($c) {
784
-			if (isset($this['urlParams'])) {
785
-				$urlParams = $this['urlParams'];
786
-			} else {
787
-				$urlParams = [];
788
-			}
789
-
790
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
791
-				&& in_array('fakeinput', stream_get_wrappers())
792
-			) {
793
-				$stream = 'fakeinput://data';
794
-			} else {
795
-				$stream = 'php://input';
796
-			}
797
-
798
-			return new Request(
799
-				[
800
-					'get' => $_GET,
801
-					'post' => $_POST,
802
-					'files' => $_FILES,
803
-					'server' => $_SERVER,
804
-					'env' => $_ENV,
805
-					'cookies' => $_COOKIE,
806
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
807
-						? $_SERVER['REQUEST_METHOD']
808
-						: '',
809
-					'urlParams' => $urlParams,
810
-				],
811
-				$this->getSecureRandom(),
812
-				$this->getConfig(),
813
-				$this->getCsrfTokenManager(),
814
-				$stream
815
-			);
816
-		});
817
-		$this->registerAlias('Request', \OCP\IRequest::class);
818
-
819
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
820
-			return new Mailer(
821
-				$c->getConfig(),
822
-				$c->getLogger(),
823
-				$c->query(Defaults::class),
824
-				$c->getURLGenerator(),
825
-				$c->getL10N('lib')
826
-			);
827
-		});
828
-		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
829
-
830
-		$this->registerService('LDAPProvider', function (Server $c) {
831
-			$config = $c->getConfig();
832
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
833
-			if (is_null($factoryClass)) {
834
-				throw new \Exception('ldapProviderFactory not set');
835
-			}
836
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
837
-			$factory = new $factoryClass($this);
838
-			return $factory->getLDAPProvider();
839
-		});
840
-		$this->registerService(ILockingProvider::class, function (Server $c) {
841
-			$ini = $c->getIniWrapper();
842
-			$config = $c->getConfig();
843
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
844
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
845
-				/** @var \OC\Memcache\Factory $memcacheFactory */
846
-				$memcacheFactory = $c->getMemCacheFactory();
847
-				$memcache = $memcacheFactory->createLocking('lock');
848
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
849
-					return new MemcacheLockingProvider($memcache, $ttl);
850
-				}
851
-				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
852
-			}
853
-			return new NoopLockingProvider();
854
-		});
855
-		$this->registerAlias('LockingProvider', ILockingProvider::class);
856
-
857
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
858
-			return new \OC\Files\Mount\Manager();
859
-		});
860
-		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
861
-
862
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
863
-			return new \OC\Files\Type\Detection(
864
-				$c->getURLGenerator(),
865
-				\OC::$configDir,
866
-				\OC::$SERVERROOT . '/resources/config/'
867
-			);
868
-		});
869
-		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
870
-
871
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
872
-			return new \OC\Files\Type\Loader(
873
-				$c->getDatabaseConnection()
874
-			);
875
-		});
876
-		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
877
-		$this->registerService(BundleFetcher::class, function () {
878
-			return new BundleFetcher($this->getL10N('lib'));
879
-		});
880
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
881
-			return new Manager(
882
-				$c->query(IValidator::class)
883
-			);
884
-		});
885
-		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
886
-
887
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
888
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
889
-			$manager->registerCapability(function () use ($c) {
890
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
891
-			});
892
-			$manager->registerCapability(function () use ($c) {
893
-				return $c->query(\OC\Security\Bruteforce\Capabilities::class);
894
-			});
895
-			return $manager;
896
-		});
897
-		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
898
-
899
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
900
-			$config = $c->getConfig();
901
-			$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
902
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
903
-			$factory = new $factoryClass($this);
904
-			$manager = $factory->getManager();
905
-
906
-			$manager->registerDisplayNameResolver('user', function($id) use ($c) {
907
-				$manager = $c->getUserManager();
908
-				$user = $manager->get($id);
909
-				if(is_null($user)) {
910
-					$l = $c->getL10N('core');
911
-					$displayName = $l->t('Unknown user');
912
-				} else {
913
-					$displayName = $user->getDisplayName();
914
-				}
915
-				return $displayName;
916
-			});
917
-
918
-			return $manager;
919
-		});
920
-		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
921
-
922
-		$this->registerService('ThemingDefaults', function (Server $c) {
923
-			/*
154
+    /** @var string */
155
+    private $webRoot;
156
+
157
+    /**
158
+     * @param string $webRoot
159
+     * @param \OC\Config $config
160
+     */
161
+    public function __construct($webRoot, \OC\Config $config) {
162
+        parent::__construct();
163
+        $this->webRoot = $webRoot;
164
+
165
+        $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
166
+            return $c;
167
+        });
168
+
169
+        $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
170
+        $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class);
171
+
172
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
173
+        $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
174
+
175
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
176
+
177
+
178
+        $this->registerService(\OCP\IPreview::class, function (Server $c) {
179
+            return new PreviewManager(
180
+                $c->getConfig(),
181
+                $c->getRootFolder(),
182
+                $c->getAppDataDir('preview'),
183
+                $c->getEventDispatcher(),
184
+                $c->getSession()->get('user_id')
185
+            );
186
+        });
187
+        $this->registerAlias('PreviewManager', \OCP\IPreview::class);
188
+
189
+        $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
190
+            return new \OC\Preview\Watcher(
191
+                $c->getAppDataDir('preview')
192
+            );
193
+        });
194
+
195
+        $this->registerService('EncryptionManager', function (Server $c) {
196
+            $view = new View();
197
+            $util = new Encryption\Util(
198
+                $view,
199
+                $c->getUserManager(),
200
+                $c->getGroupManager(),
201
+                $c->getConfig()
202
+            );
203
+            return new Encryption\Manager(
204
+                $c->getConfig(),
205
+                $c->getLogger(),
206
+                $c->getL10N('core'),
207
+                new View(),
208
+                $util,
209
+                new ArrayCache()
210
+            );
211
+        });
212
+
213
+        $this->registerService('EncryptionFileHelper', function (Server $c) {
214
+            $util = new Encryption\Util(
215
+                new View(),
216
+                $c->getUserManager(),
217
+                $c->getGroupManager(),
218
+                $c->getConfig()
219
+            );
220
+            return new Encryption\File(
221
+                $util,
222
+                $c->getRootFolder(),
223
+                $c->getShareManager()
224
+            );
225
+        });
226
+
227
+        $this->registerService('EncryptionKeyStorage', function (Server $c) {
228
+            $view = new View();
229
+            $util = new Encryption\Util(
230
+                $view,
231
+                $c->getUserManager(),
232
+                $c->getGroupManager(),
233
+                $c->getConfig()
234
+            );
235
+
236
+            return new Encryption\Keys\Storage($view, $util);
237
+        });
238
+        $this->registerService('TagMapper', function (Server $c) {
239
+            return new TagMapper($c->getDatabaseConnection());
240
+        });
241
+
242
+        $this->registerService(\OCP\ITagManager::class, function (Server $c) {
243
+            $tagMapper = $c->query('TagMapper');
244
+            return new TagManager($tagMapper, $c->getUserSession());
245
+        });
246
+        $this->registerAlias('TagManager', \OCP\ITagManager::class);
247
+
248
+        $this->registerService('SystemTagManagerFactory', function (Server $c) {
249
+            $config = $c->getConfig();
250
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
251
+            return new $factoryClass($this);
252
+        });
253
+        $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
254
+            return $c->query('SystemTagManagerFactory')->getManager();
255
+        });
256
+        $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
257
+
258
+        $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
259
+            return $c->query('SystemTagManagerFactory')->getObjectMapper();
260
+        });
261
+        $this->registerService('RootFolder', function (Server $c) {
262
+            $manager = \OC\Files\Filesystem::getMountManager(null);
263
+            $view = new View();
264
+            $root = new Root(
265
+                $manager,
266
+                $view,
267
+                null,
268
+                $c->getUserMountCache(),
269
+                $this->getLogger(),
270
+                $this->getUserManager()
271
+            );
272
+            $connector = new HookConnector($root, $view);
273
+            $connector->viewToNode();
274
+
275
+            $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
276
+            $previewConnector->connectWatcher();
277
+
278
+            return $root;
279
+        });
280
+        $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
281
+
282
+        $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
283
+            return new LazyRoot(function () use ($c) {
284
+                return $c->query('RootFolder');
285
+            });
286
+        });
287
+        $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
288
+
289
+        $this->registerService(\OC\User\Manager::class, function (Server $c) {
290
+            $config = $c->getConfig();
291
+            return new \OC\User\Manager($config);
292
+        });
293
+        $this->registerAlias('UserManager', \OC\User\Manager::class);
294
+        $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
295
+
296
+        $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
297
+            $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
298
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
299
+                \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
300
+            });
301
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
302
+                \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
303
+            });
304
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
305
+                \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
306
+            });
307
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
308
+                \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
309
+            });
310
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
311
+                \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
312
+            });
313
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
314
+                \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
315
+                //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
316
+                \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
317
+            });
318
+            return $groupManager;
319
+        });
320
+        $this->registerAlias('GroupManager', \OCP\IGroupManager::class);
321
+
322
+        $this->registerService(Store::class, function (Server $c) {
323
+            $session = $c->getSession();
324
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
325
+                $tokenProvider = $c->query(IProvider::class);
326
+            } else {
327
+                $tokenProvider = null;
328
+            }
329
+            $logger = $c->getLogger();
330
+            return new Store($session, $logger, $tokenProvider);
331
+        });
332
+        $this->registerAlias(IStore::class, Store::class);
333
+        $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
334
+            $dbConnection = $c->getDatabaseConnection();
335
+            return new Authentication\Token\DefaultTokenMapper($dbConnection);
336
+        });
337
+        $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) {
338
+            $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class);
339
+            $crypto = $c->getCrypto();
340
+            $config = $c->getConfig();
341
+            $logger = $c->getLogger();
342
+            $timeFactory = new TimeFactory();
343
+            return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
344
+        });
345
+        $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class);
346
+
347
+        $this->registerService(\OCP\IUserSession::class, function (Server $c) {
348
+            $manager = $c->getUserManager();
349
+            $session = new \OC\Session\Memory('');
350
+            $timeFactory = new TimeFactory();
351
+            // Token providers might require a working database. This code
352
+            // might however be called when ownCloud is not yet setup.
353
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
354
+                $defaultTokenProvider = $c->query(IProvider::class);
355
+            } else {
356
+                $defaultTokenProvider = null;
357
+            }
358
+
359
+            $dispatcher = $c->getEventDispatcher();
360
+
361
+            $userSession = new \OC\User\Session(
362
+                $manager,
363
+                $session,
364
+                $timeFactory,
365
+                $defaultTokenProvider,
366
+                $c->getConfig(),
367
+                $c->getSecureRandom(),
368
+                $c->getLockdownManager(),
369
+                $c->getLogger()
370
+            );
371
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
372
+                \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
373
+            });
374
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
375
+                /** @var $user \OC\User\User */
376
+                \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
377
+            });
378
+            $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
379
+                /** @var $user \OC\User\User */
380
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
381
+                $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
382
+            });
383
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
384
+                /** @var $user \OC\User\User */
385
+                \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
386
+            });
387
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
388
+                /** @var $user \OC\User\User */
389
+                \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
390
+            });
391
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
392
+                /** @var $user \OC\User\User */
393
+                \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
394
+            });
395
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
396
+                \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
397
+            });
398
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
399
+                /** @var $user \OC\User\User */
400
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
401
+            });
402
+            $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
403
+                /** @var $user \OC\User\User */
404
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
405
+            });
406
+            $userSession->listen('\OC\User', 'logout', function () {
407
+                \OC_Hook::emit('OC_User', 'logout', array());
408
+            });
409
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) {
410
+                /** @var $user \OC\User\User */
411
+                \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
412
+                $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value]));
413
+            });
414
+            return $userSession;
415
+        });
416
+        $this->registerAlias('UserSession', \OCP\IUserSession::class);
417
+
418
+        $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
419
+            return new \OC\Authentication\TwoFactorAuth\Manager(
420
+                $c->getAppManager(),
421
+                $c->getSession(),
422
+                $c->getConfig(),
423
+                $c->getActivityManager(),
424
+                $c->getLogger(),
425
+                $c->query(IProvider::class),
426
+                $c->query(ITimeFactory::class),
427
+                $c->query(EventDispatcherInterface::class)
428
+            );
429
+        });
430
+
431
+        $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
432
+        $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
433
+
434
+        $this->registerService(\OC\AllConfig::class, function (Server $c) {
435
+            return new \OC\AllConfig(
436
+                $c->getSystemConfig()
437
+            );
438
+        });
439
+        $this->registerAlias('AllConfig', \OC\AllConfig::class);
440
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
441
+
442
+        $this->registerService('SystemConfig', function ($c) use ($config) {
443
+            return new \OC\SystemConfig($config);
444
+        });
445
+
446
+        $this->registerService(\OC\AppConfig::class, function (Server $c) {
447
+            return new \OC\AppConfig($c->getDatabaseConnection());
448
+        });
449
+        $this->registerAlias('AppConfig', \OC\AppConfig::class);
450
+        $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
451
+
452
+        $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
453
+            return new \OC\L10N\Factory(
454
+                $c->getConfig(),
455
+                $c->getRequest(),
456
+                $c->getUserSession(),
457
+                \OC::$SERVERROOT
458
+            );
459
+        });
460
+        $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
461
+
462
+        $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
463
+            $config = $c->getConfig();
464
+            $cacheFactory = $c->getMemCacheFactory();
465
+            $request = $c->getRequest();
466
+            return new \OC\URLGenerator(
467
+                $config,
468
+                $cacheFactory,
469
+                $request
470
+            );
471
+        });
472
+        $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
473
+
474
+        $this->registerAlias('AppFetcher', AppFetcher::class);
475
+        $this->registerAlias('CategoryFetcher', CategoryFetcher::class);
476
+
477
+        $this->registerService(\OCP\ICache::class, function ($c) {
478
+            return new Cache\File();
479
+        });
480
+        $this->registerAlias('UserCache', \OCP\ICache::class);
481
+
482
+        $this->registerService(Factory::class, function (Server $c) {
483
+
484
+            $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
485
+                ArrayCache::class,
486
+                ArrayCache::class,
487
+                ArrayCache::class
488
+            );
489
+            $config = $c->getConfig();
490
+            $request = $c->getRequest();
491
+            $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
492
+
493
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
494
+                $v = \OC_App::getAppVersions();
495
+                $v['core'] = implode(',', \OC_Util::getVersion());
496
+                $version = implode(',', $v);
497
+                $instanceId = \OC_Util::getInstanceId();
498
+                $path = \OC::$SERVERROOT;
499
+                $prefix = md5($instanceId . '-' . $version . '-' . $path);
500
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
501
+                    $config->getSystemValue('memcache.local', null),
502
+                    $config->getSystemValue('memcache.distributed', null),
503
+                    $config->getSystemValue('memcache.locking', null)
504
+                );
505
+            }
506
+            return $arrayCacheFactory;
507
+
508
+        });
509
+        $this->registerAlias('MemCacheFactory', Factory::class);
510
+        $this->registerAlias(ICacheFactory::class, Factory::class);
511
+
512
+        $this->registerService('RedisFactory', function (Server $c) {
513
+            $systemConfig = $c->getSystemConfig();
514
+            return new RedisFactory($systemConfig);
515
+        });
516
+
517
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
518
+            return new \OC\Activity\Manager(
519
+                $c->getRequest(),
520
+                $c->getUserSession(),
521
+                $c->getConfig(),
522
+                $c->query(IValidator::class)
523
+            );
524
+        });
525
+        $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
526
+
527
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
528
+            return new \OC\Activity\EventMerger(
529
+                $c->getL10N('lib')
530
+            );
531
+        });
532
+        $this->registerAlias(IValidator::class, Validator::class);
533
+
534
+        $this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
535
+            return new AvatarManager(
536
+                $c->query(\OC\User\Manager::class),
537
+                $c->getAppDataDir('avatar'),
538
+                $c->getL10N('lib'),
539
+                $c->getLogger(),
540
+                $c->getConfig()
541
+            );
542
+        });
543
+        $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
544
+
545
+        $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
546
+
547
+        $this->registerService(\OCP\ILogger::class, function (Server $c) {
548
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
549
+            $logger = Log::getLogClass($logType);
550
+            call_user_func(array($logger, 'init'));
551
+            $config = $this->getSystemConfig();
552
+            $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
553
+
554
+            return new Log($logger, $config, null, $registry);
555
+        });
556
+        $this->registerAlias('Logger', \OCP\ILogger::class);
557
+
558
+        $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
559
+            $config = $c->getConfig();
560
+            return new \OC\BackgroundJob\JobList(
561
+                $c->getDatabaseConnection(),
562
+                $config,
563
+                new TimeFactory()
564
+            );
565
+        });
566
+        $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
567
+
568
+        $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
569
+            $cacheFactory = $c->getMemCacheFactory();
570
+            $logger = $c->getLogger();
571
+            if ($cacheFactory->isLocalCacheAvailable()) {
572
+                $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
573
+            } else {
574
+                $router = new \OC\Route\Router($logger);
575
+            }
576
+            return $router;
577
+        });
578
+        $this->registerAlias('Router', \OCP\Route\IRouter::class);
579
+
580
+        $this->registerService(\OCP\ISearch::class, function ($c) {
581
+            return new Search();
582
+        });
583
+        $this->registerAlias('Search', \OCP\ISearch::class);
584
+
585
+        $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
586
+            return new \OC\Security\RateLimiting\Limiter(
587
+                $this->getUserSession(),
588
+                $this->getRequest(),
589
+                new \OC\AppFramework\Utility\TimeFactory(),
590
+                $c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
591
+            );
592
+        });
593
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
594
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
595
+                $this->getMemCacheFactory(),
596
+                new \OC\AppFramework\Utility\TimeFactory()
597
+            );
598
+        });
599
+
600
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
601
+            return new SecureRandom();
602
+        });
603
+        $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
604
+
605
+        $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
606
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
607
+        });
608
+        $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
609
+
610
+        $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
611
+            return new Hasher($c->getConfig());
612
+        });
613
+        $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
614
+
615
+        $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
616
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
617
+        });
618
+        $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
619
+
620
+        $this->registerService(IDBConnection::class, function (Server $c) {
621
+            $systemConfig = $c->getSystemConfig();
622
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
623
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
624
+            if (!$factory->isValidType($type)) {
625
+                throw new \OC\DatabaseException('Invalid database type');
626
+            }
627
+            $connectionParams = $factory->createConnectionParams();
628
+            $connection = $factory->getConnection($type, $connectionParams);
629
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
630
+            return $connection;
631
+        });
632
+        $this->registerAlias('DatabaseConnection', IDBConnection::class);
633
+
634
+
635
+        $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
636
+            $user = \OC_User::getUser();
637
+            $uid = $user ? $user : null;
638
+            return new ClientService(
639
+                $c->getConfig(),
640
+                new \OC\Security\CertificateManager(
641
+                    $uid,
642
+                    new View(),
643
+                    $c->getConfig(),
644
+                    $c->getLogger(),
645
+                    $c->getSecureRandom()
646
+                )
647
+            );
648
+        });
649
+        $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
650
+        $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
651
+            $eventLogger = new EventLogger();
652
+            if ($c->getSystemConfig()->getValue('debug', false)) {
653
+                // In debug mode, module is being activated by default
654
+                $eventLogger->activate();
655
+            }
656
+            return $eventLogger;
657
+        });
658
+        $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
659
+
660
+        $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
661
+            $queryLogger = new QueryLogger();
662
+            if ($c->getSystemConfig()->getValue('debug', false)) {
663
+                // In debug mode, module is being activated by default
664
+                $queryLogger->activate();
665
+            }
666
+            return $queryLogger;
667
+        });
668
+        $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
669
+
670
+        $this->registerService(TempManager::class, function (Server $c) {
671
+            return new TempManager(
672
+                $c->getLogger(),
673
+                $c->getConfig()
674
+            );
675
+        });
676
+        $this->registerAlias('TempManager', TempManager::class);
677
+        $this->registerAlias(ITempManager::class, TempManager::class);
678
+
679
+        $this->registerService(AppManager::class, function (Server $c) {
680
+            return new \OC\App\AppManager(
681
+                $c->getUserSession(),
682
+                $c->query(\OC\AppConfig::class),
683
+                $c->getGroupManager(),
684
+                $c->getMemCacheFactory(),
685
+                $c->getEventDispatcher()
686
+            );
687
+        });
688
+        $this->registerAlias('AppManager', AppManager::class);
689
+        $this->registerAlias(IAppManager::class, AppManager::class);
690
+
691
+        $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
692
+            return new DateTimeZone(
693
+                $c->getConfig(),
694
+                $c->getSession()
695
+            );
696
+        });
697
+        $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
698
+
699
+        $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
700
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
701
+
702
+            return new DateTimeFormatter(
703
+                $c->getDateTimeZone()->getTimeZone(),
704
+                $c->getL10N('lib', $language)
705
+            );
706
+        });
707
+        $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
708
+
709
+        $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
710
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
711
+            $listener = new UserMountCacheListener($mountCache);
712
+            $listener->listen($c->getUserManager());
713
+            return $mountCache;
714
+        });
715
+        $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
716
+
717
+        $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
718
+            $loader = \OC\Files\Filesystem::getLoader();
719
+            $mountCache = $c->query('UserMountCache');
720
+            $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
721
+
722
+            // builtin providers
723
+
724
+            $config = $c->getConfig();
725
+            $manager->registerProvider(new CacheMountProvider($config));
726
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
727
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
728
+
729
+            return $manager;
730
+        });
731
+        $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
732
+
733
+        $this->registerService('IniWrapper', function ($c) {
734
+            return new IniGetWrapper();
735
+        });
736
+        $this->registerService('AsyncCommandBus', function (Server $c) {
737
+            $busClass = $c->getConfig()->getSystemValue('commandbus');
738
+            if ($busClass) {
739
+                list($app, $class) = explode('::', $busClass, 2);
740
+                if ($c->getAppManager()->isInstalled($app)) {
741
+                    \OC_App::loadApp($app);
742
+                    return $c->query($class);
743
+                } else {
744
+                    throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
745
+                }
746
+            } else {
747
+                $jobList = $c->getJobList();
748
+                return new CronBus($jobList);
749
+            }
750
+        });
751
+        $this->registerService('TrustedDomainHelper', function ($c) {
752
+            return new TrustedDomainHelper($this->getConfig());
753
+        });
754
+        $this->registerService('Throttler', function (Server $c) {
755
+            return new Throttler(
756
+                $c->getDatabaseConnection(),
757
+                new TimeFactory(),
758
+                $c->getLogger(),
759
+                $c->getConfig()
760
+            );
761
+        });
762
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
763
+            // IConfig and IAppManager requires a working database. This code
764
+            // might however be called when ownCloud is not yet setup.
765
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
766
+                $config = $c->getConfig();
767
+                $appManager = $c->getAppManager();
768
+            } else {
769
+                $config = null;
770
+                $appManager = null;
771
+            }
772
+
773
+            return new Checker(
774
+                new EnvironmentHelper(),
775
+                new FileAccessHelper(),
776
+                new AppLocator(),
777
+                $config,
778
+                $c->getMemCacheFactory(),
779
+                $appManager,
780
+                $c->getTempManager()
781
+            );
782
+        });
783
+        $this->registerService(\OCP\IRequest::class, function ($c) {
784
+            if (isset($this['urlParams'])) {
785
+                $urlParams = $this['urlParams'];
786
+            } else {
787
+                $urlParams = [];
788
+            }
789
+
790
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
791
+                && in_array('fakeinput', stream_get_wrappers())
792
+            ) {
793
+                $stream = 'fakeinput://data';
794
+            } else {
795
+                $stream = 'php://input';
796
+            }
797
+
798
+            return new Request(
799
+                [
800
+                    'get' => $_GET,
801
+                    'post' => $_POST,
802
+                    'files' => $_FILES,
803
+                    'server' => $_SERVER,
804
+                    'env' => $_ENV,
805
+                    'cookies' => $_COOKIE,
806
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
807
+                        ? $_SERVER['REQUEST_METHOD']
808
+                        : '',
809
+                    'urlParams' => $urlParams,
810
+                ],
811
+                $this->getSecureRandom(),
812
+                $this->getConfig(),
813
+                $this->getCsrfTokenManager(),
814
+                $stream
815
+            );
816
+        });
817
+        $this->registerAlias('Request', \OCP\IRequest::class);
818
+
819
+        $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
820
+            return new Mailer(
821
+                $c->getConfig(),
822
+                $c->getLogger(),
823
+                $c->query(Defaults::class),
824
+                $c->getURLGenerator(),
825
+                $c->getL10N('lib')
826
+            );
827
+        });
828
+        $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
829
+
830
+        $this->registerService('LDAPProvider', function (Server $c) {
831
+            $config = $c->getConfig();
832
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
833
+            if (is_null($factoryClass)) {
834
+                throw new \Exception('ldapProviderFactory not set');
835
+            }
836
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
837
+            $factory = new $factoryClass($this);
838
+            return $factory->getLDAPProvider();
839
+        });
840
+        $this->registerService(ILockingProvider::class, function (Server $c) {
841
+            $ini = $c->getIniWrapper();
842
+            $config = $c->getConfig();
843
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
844
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
845
+                /** @var \OC\Memcache\Factory $memcacheFactory */
846
+                $memcacheFactory = $c->getMemCacheFactory();
847
+                $memcache = $memcacheFactory->createLocking('lock');
848
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
849
+                    return new MemcacheLockingProvider($memcache, $ttl);
850
+                }
851
+                return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
852
+            }
853
+            return new NoopLockingProvider();
854
+        });
855
+        $this->registerAlias('LockingProvider', ILockingProvider::class);
856
+
857
+        $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
858
+            return new \OC\Files\Mount\Manager();
859
+        });
860
+        $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
861
+
862
+        $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
863
+            return new \OC\Files\Type\Detection(
864
+                $c->getURLGenerator(),
865
+                \OC::$configDir,
866
+                \OC::$SERVERROOT . '/resources/config/'
867
+            );
868
+        });
869
+        $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
870
+
871
+        $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
872
+            return new \OC\Files\Type\Loader(
873
+                $c->getDatabaseConnection()
874
+            );
875
+        });
876
+        $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
877
+        $this->registerService(BundleFetcher::class, function () {
878
+            return new BundleFetcher($this->getL10N('lib'));
879
+        });
880
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
881
+            return new Manager(
882
+                $c->query(IValidator::class)
883
+            );
884
+        });
885
+        $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
886
+
887
+        $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
888
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
889
+            $manager->registerCapability(function () use ($c) {
890
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
891
+            });
892
+            $manager->registerCapability(function () use ($c) {
893
+                return $c->query(\OC\Security\Bruteforce\Capabilities::class);
894
+            });
895
+            return $manager;
896
+        });
897
+        $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
898
+
899
+        $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
900
+            $config = $c->getConfig();
901
+            $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
902
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
903
+            $factory = new $factoryClass($this);
904
+            $manager = $factory->getManager();
905
+
906
+            $manager->registerDisplayNameResolver('user', function($id) use ($c) {
907
+                $manager = $c->getUserManager();
908
+                $user = $manager->get($id);
909
+                if(is_null($user)) {
910
+                    $l = $c->getL10N('core');
911
+                    $displayName = $l->t('Unknown user');
912
+                } else {
913
+                    $displayName = $user->getDisplayName();
914
+                }
915
+                return $displayName;
916
+            });
917
+
918
+            return $manager;
919
+        });
920
+        $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
921
+
922
+        $this->registerService('ThemingDefaults', function (Server $c) {
923
+            /*
924 924
 			 * Dark magic for autoloader.
925 925
 			 * If we do a class_exists it will try to load the class which will
926 926
 			 * make composer cache the result. Resulting in errors when enabling
927 927
 			 * the theming app.
928 928
 			 */
929
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
930
-			if (isset($prefixes['OCA\\Theming\\'])) {
931
-				$classExists = true;
932
-			} else {
933
-				$classExists = false;
934
-			}
935
-
936
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
937
-				return new ThemingDefaults(
938
-					$c->getConfig(),
939
-					$c->getL10N('theming'),
940
-					$c->getURLGenerator(),
941
-					$c->getMemCacheFactory(),
942
-					new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
943
-					new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator()),
944
-					$c->getAppManager()
945
-				);
946
-			}
947
-			return new \OC_Defaults();
948
-		});
949
-		$this->registerService(SCSSCacher::class, function (Server $c) {
950
-			/** @var Factory $cacheFactory */
951
-			$cacheFactory = $c->query(Factory::class);
952
-			return new SCSSCacher(
953
-				$c->getLogger(),
954
-				$c->query(\OC\Files\AppData\Factory::class),
955
-				$c->getURLGenerator(),
956
-				$c->getConfig(),
957
-				$c->getThemingDefaults(),
958
-				\OC::$SERVERROOT,
959
-				$this->getMemCacheFactory()
960
-			);
961
-		});
962
-		$this->registerService(JSCombiner::class, function (Server $c) {
963
-			/** @var Factory $cacheFactory */
964
-			$cacheFactory = $c->query(Factory::class);
965
-			return new JSCombiner(
966
-				$c->getAppDataDir('js'),
967
-				$c->getURLGenerator(),
968
-				$this->getMemCacheFactory(),
969
-				$c->getSystemConfig(),
970
-				$c->getLogger()
971
-			);
972
-		});
973
-		$this->registerService(EventDispatcher::class, function () {
974
-			return new EventDispatcher();
975
-		});
976
-		$this->registerAlias('EventDispatcher', EventDispatcher::class);
977
-		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
978
-
979
-		$this->registerService('CryptoWrapper', function (Server $c) {
980
-			// FIXME: Instantiiated here due to cyclic dependency
981
-			$request = new Request(
982
-				[
983
-					'get' => $_GET,
984
-					'post' => $_POST,
985
-					'files' => $_FILES,
986
-					'server' => $_SERVER,
987
-					'env' => $_ENV,
988
-					'cookies' => $_COOKIE,
989
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
990
-						? $_SERVER['REQUEST_METHOD']
991
-						: null,
992
-				],
993
-				$c->getSecureRandom(),
994
-				$c->getConfig()
995
-			);
996
-
997
-			return new CryptoWrapper(
998
-				$c->getConfig(),
999
-				$c->getCrypto(),
1000
-				$c->getSecureRandom(),
1001
-				$request
1002
-			);
1003
-		});
1004
-		$this->registerService('CsrfTokenManager', function (Server $c) {
1005
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1006
-
1007
-			return new CsrfTokenManager(
1008
-				$tokenGenerator,
1009
-				$c->query(SessionStorage::class)
1010
-			);
1011
-		});
1012
-		$this->registerService(SessionStorage::class, function (Server $c) {
1013
-			return new SessionStorage($c->getSession());
1014
-		});
1015
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
1016
-			return new ContentSecurityPolicyManager();
1017
-		});
1018
-		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
1019
-
1020
-		$this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1021
-			return new ContentSecurityPolicyNonceManager(
1022
-				$c->getCsrfTokenManager(),
1023
-				$c->getRequest()
1024
-			);
1025
-		});
1026
-
1027
-		$this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1028
-			$config = $c->getConfig();
1029
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1030
-			/** @var \OCP\Share\IProviderFactory $factory */
1031
-			$factory = new $factoryClass($this);
1032
-
1033
-			$manager = new \OC\Share20\Manager(
1034
-				$c->getLogger(),
1035
-				$c->getConfig(),
1036
-				$c->getSecureRandom(),
1037
-				$c->getHasher(),
1038
-				$c->getMountManager(),
1039
-				$c->getGroupManager(),
1040
-				$c->getL10N('lib'),
1041
-				$c->getL10NFactory(),
1042
-				$factory,
1043
-				$c->getUserManager(),
1044
-				$c->getLazyRootFolder(),
1045
-				$c->getEventDispatcher(),
1046
-				$c->getMailer(),
1047
-				$c->getURLGenerator(),
1048
-				$c->getThemingDefaults()
1049
-			);
1050
-
1051
-			return $manager;
1052
-		});
1053
-		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
1054
-
1055
-		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
1056
-			$instance = new Collaboration\Collaborators\Search($c);
1057
-
1058
-			// register default plugins
1059
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1060
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1061
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1062
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1063
-
1064
-			return $instance;
1065
-		});
1066
-		$this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1067
-
1068
-		$this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1069
-
1070
-		$this->registerService('SettingsManager', function (Server $c) {
1071
-			$manager = new \OC\Settings\Manager(
1072
-				$c->getLogger(),
1073
-				$c->getDatabaseConnection(),
1074
-				$c->getL10N('lib'),
1075
-				$c->getConfig(),
1076
-				$c->getEncryptionManager(),
1077
-				$c->getUserManager(),
1078
-				$c->getLockingProvider(),
1079
-				$c->getRequest(),
1080
-				$c->getURLGenerator(),
1081
-				$c->query(AccountManager::class),
1082
-				$c->getGroupManager(),
1083
-				$c->getL10NFactory(),
1084
-				$c->getAppManager()
1085
-			);
1086
-			return $manager;
1087
-		});
1088
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1089
-			return new \OC\Files\AppData\Factory(
1090
-				$c->getRootFolder(),
1091
-				$c->getSystemConfig()
1092
-			);
1093
-		});
1094
-
1095
-		$this->registerService('LockdownManager', function (Server $c) {
1096
-			return new LockdownManager(function () use ($c) {
1097
-				return $c->getSession();
1098
-			});
1099
-		});
1100
-
1101
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1102
-			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1103
-		});
1104
-
1105
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1106
-			return new CloudIdManager();
1107
-		});
1108
-
1109
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1110
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1111
-
1112
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1113
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1114
-
1115
-		$this->registerService(Defaults::class, function (Server $c) {
1116
-			return new Defaults(
1117
-				$c->getThemingDefaults()
1118
-			);
1119
-		});
1120
-		$this->registerAlias('Defaults', \OCP\Defaults::class);
1121
-
1122
-		$this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1123
-			return $c->query(\OCP\IUserSession::class)->getSession();
1124
-		});
1125
-
1126
-		$this->registerService(IShareHelper::class, function (Server $c) {
1127
-			return new ShareHelper(
1128
-				$c->query(\OCP\Share\IManager::class)
1129
-			);
1130
-		});
1131
-
1132
-		$this->registerService(Installer::class, function(Server $c) {
1133
-			return new Installer(
1134
-				$c->getAppFetcher(),
1135
-				$c->getHTTPClientService(),
1136
-				$c->getTempManager(),
1137
-				$c->getLogger(),
1138
-				$c->getConfig()
1139
-			);
1140
-		});
1141
-
1142
-		$this->registerService(IApiFactory::class, function(Server $c) {
1143
-			return new ApiFactory($c->getHTTPClientService());
1144
-		});
1145
-
1146
-		$this->registerService(IInstanceFactory::class, function(Server $c) {
1147
-			$memcacheFactory = $c->getMemCacheFactory();
1148
-			return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
1149
-		});
1150
-
1151
-		$this->registerService(IContactsStore::class, function(Server $c) {
1152
-			return new ContactsStore(
1153
-				$c->getContactsManager(),
1154
-				$c->getConfig(),
1155
-				$c->getUserManager(),
1156
-				$c->getGroupManager()
1157
-			);
1158
-		});
1159
-		$this->registerAlias(IContactsStore::class, ContactsStore::class);
1160
-
1161
-		$this->connectDispatcher();
1162
-	}
1163
-
1164
-	/**
1165
-	 * @return \OCP\Calendar\IManager
1166
-	 */
1167
-	public function getCalendarManager() {
1168
-		return $this->query('CalendarManager');
1169
-	}
1170
-
1171
-	private function connectDispatcher() {
1172
-		$dispatcher = $this->getEventDispatcher();
1173
-
1174
-		// Delete avatar on user deletion
1175
-		$dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
1176
-			$logger = $this->getLogger();
1177
-			$manager = $this->getAvatarManager();
1178
-			/** @var IUser $user */
1179
-			$user = $e->getSubject();
1180
-
1181
-			try {
1182
-				$avatar = $manager->getAvatar($user->getUID());
1183
-				$avatar->remove();
1184
-			} catch (NotFoundException $e) {
1185
-				// no avatar to remove
1186
-			} catch (\Exception $e) {
1187
-				// Ignore exceptions
1188
-				$logger->info('Could not cleanup avatar of ' . $user->getUID());
1189
-			}
1190
-		});
1191
-
1192
-		$dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1193
-			$manager = $this->getAvatarManager();
1194
-			/** @var IUser $user */
1195
-			$user = $e->getSubject();
1196
-			$feature = $e->getArgument('feature');
1197
-			$oldValue = $e->getArgument('oldValue');
1198
-			$value = $e->getArgument('value');
1199
-
1200
-			try {
1201
-				$avatar = $manager->getAvatar($user->getUID());
1202
-				$avatar->userChanged($feature, $oldValue, $value);
1203
-			} catch (NotFoundException $e) {
1204
-				// no avatar to remove
1205
-			}
1206
-		});
1207
-	}
1208
-
1209
-	/**
1210
-	 * @return \OCP\Contacts\IManager
1211
-	 */
1212
-	public function getContactsManager() {
1213
-		return $this->query('ContactsManager');
1214
-	}
1215
-
1216
-	/**
1217
-	 * @return \OC\Encryption\Manager
1218
-	 */
1219
-	public function getEncryptionManager() {
1220
-		return $this->query('EncryptionManager');
1221
-	}
1222
-
1223
-	/**
1224
-	 * @return \OC\Encryption\File
1225
-	 */
1226
-	public function getEncryptionFilesHelper() {
1227
-		return $this->query('EncryptionFileHelper');
1228
-	}
1229
-
1230
-	/**
1231
-	 * @return \OCP\Encryption\Keys\IStorage
1232
-	 */
1233
-	public function getEncryptionKeyStorage() {
1234
-		return $this->query('EncryptionKeyStorage');
1235
-	}
1236
-
1237
-	/**
1238
-	 * The current request object holding all information about the request
1239
-	 * currently being processed is returned from this method.
1240
-	 * In case the current execution was not initiated by a web request null is returned
1241
-	 *
1242
-	 * @return \OCP\IRequest
1243
-	 */
1244
-	public function getRequest() {
1245
-		return $this->query('Request');
1246
-	}
1247
-
1248
-	/**
1249
-	 * Returns the preview manager which can create preview images for a given file
1250
-	 *
1251
-	 * @return \OCP\IPreview
1252
-	 */
1253
-	public function getPreviewManager() {
1254
-		return $this->query('PreviewManager');
1255
-	}
1256
-
1257
-	/**
1258
-	 * Returns the tag manager which can get and set tags for different object types
1259
-	 *
1260
-	 * @see \OCP\ITagManager::load()
1261
-	 * @return \OCP\ITagManager
1262
-	 */
1263
-	public function getTagManager() {
1264
-		return $this->query('TagManager');
1265
-	}
1266
-
1267
-	/**
1268
-	 * Returns the system-tag manager
1269
-	 *
1270
-	 * @return \OCP\SystemTag\ISystemTagManager
1271
-	 *
1272
-	 * @since 9.0.0
1273
-	 */
1274
-	public function getSystemTagManager() {
1275
-		return $this->query('SystemTagManager');
1276
-	}
1277
-
1278
-	/**
1279
-	 * Returns the system-tag object mapper
1280
-	 *
1281
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1282
-	 *
1283
-	 * @since 9.0.0
1284
-	 */
1285
-	public function getSystemTagObjectMapper() {
1286
-		return $this->query('SystemTagObjectMapper');
1287
-	}
1288
-
1289
-	/**
1290
-	 * Returns the avatar manager, used for avatar functionality
1291
-	 *
1292
-	 * @return \OCP\IAvatarManager
1293
-	 */
1294
-	public function getAvatarManager() {
1295
-		return $this->query('AvatarManager');
1296
-	}
1297
-
1298
-	/**
1299
-	 * Returns the root folder of ownCloud's data directory
1300
-	 *
1301
-	 * @return \OCP\Files\IRootFolder
1302
-	 */
1303
-	public function getRootFolder() {
1304
-		return $this->query('LazyRootFolder');
1305
-	}
1306
-
1307
-	/**
1308
-	 * Returns the root folder of ownCloud's data directory
1309
-	 * This is the lazy variant so this gets only initialized once it
1310
-	 * is actually used.
1311
-	 *
1312
-	 * @return \OCP\Files\IRootFolder
1313
-	 */
1314
-	public function getLazyRootFolder() {
1315
-		return $this->query('LazyRootFolder');
1316
-	}
1317
-
1318
-	/**
1319
-	 * Returns a view to ownCloud's files folder
1320
-	 *
1321
-	 * @param string $userId user ID
1322
-	 * @return \OCP\Files\Folder|null
1323
-	 */
1324
-	public function getUserFolder($userId = null) {
1325
-		if ($userId === null) {
1326
-			$user = $this->getUserSession()->getUser();
1327
-			if (!$user) {
1328
-				return null;
1329
-			}
1330
-			$userId = $user->getUID();
1331
-		}
1332
-		$root = $this->getRootFolder();
1333
-		return $root->getUserFolder($userId);
1334
-	}
1335
-
1336
-	/**
1337
-	 * Returns an app-specific view in ownClouds data directory
1338
-	 *
1339
-	 * @return \OCP\Files\Folder
1340
-	 * @deprecated since 9.2.0 use IAppData
1341
-	 */
1342
-	public function getAppFolder() {
1343
-		$dir = '/' . \OC_App::getCurrentApp();
1344
-		$root = $this->getRootFolder();
1345
-		if (!$root->nodeExists($dir)) {
1346
-			$folder = $root->newFolder($dir);
1347
-		} else {
1348
-			$folder = $root->get($dir);
1349
-		}
1350
-		return $folder;
1351
-	}
1352
-
1353
-	/**
1354
-	 * @return \OC\User\Manager
1355
-	 */
1356
-	public function getUserManager() {
1357
-		return $this->query('UserManager');
1358
-	}
1359
-
1360
-	/**
1361
-	 * @return \OC\Group\Manager
1362
-	 */
1363
-	public function getGroupManager() {
1364
-		return $this->query('GroupManager');
1365
-	}
1366
-
1367
-	/**
1368
-	 * @return \OC\User\Session
1369
-	 */
1370
-	public function getUserSession() {
1371
-		return $this->query('UserSession');
1372
-	}
1373
-
1374
-	/**
1375
-	 * @return \OCP\ISession
1376
-	 */
1377
-	public function getSession() {
1378
-		return $this->query('UserSession')->getSession();
1379
-	}
1380
-
1381
-	/**
1382
-	 * @param \OCP\ISession $session
1383
-	 */
1384
-	public function setSession(\OCP\ISession $session) {
1385
-		$this->query(SessionStorage::class)->setSession($session);
1386
-		$this->query('UserSession')->setSession($session);
1387
-		$this->query(Store::class)->setSession($session);
1388
-	}
1389
-
1390
-	/**
1391
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1392
-	 */
1393
-	public function getTwoFactorAuthManager() {
1394
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1395
-	}
1396
-
1397
-	/**
1398
-	 * @return \OC\NavigationManager
1399
-	 */
1400
-	public function getNavigationManager() {
1401
-		return $this->query('NavigationManager');
1402
-	}
1403
-
1404
-	/**
1405
-	 * @return \OCP\IConfig
1406
-	 */
1407
-	public function getConfig() {
1408
-		return $this->query('AllConfig');
1409
-	}
1410
-
1411
-	/**
1412
-	 * @return \OC\SystemConfig
1413
-	 */
1414
-	public function getSystemConfig() {
1415
-		return $this->query('SystemConfig');
1416
-	}
1417
-
1418
-	/**
1419
-	 * Returns the app config manager
1420
-	 *
1421
-	 * @return \OCP\IAppConfig
1422
-	 */
1423
-	public function getAppConfig() {
1424
-		return $this->query('AppConfig');
1425
-	}
1426
-
1427
-	/**
1428
-	 * @return \OCP\L10N\IFactory
1429
-	 */
1430
-	public function getL10NFactory() {
1431
-		return $this->query('L10NFactory');
1432
-	}
1433
-
1434
-	/**
1435
-	 * get an L10N instance
1436
-	 *
1437
-	 * @param string $app appid
1438
-	 * @param string $lang
1439
-	 * @return IL10N
1440
-	 */
1441
-	public function getL10N($app, $lang = null) {
1442
-		return $this->getL10NFactory()->get($app, $lang);
1443
-	}
1444
-
1445
-	/**
1446
-	 * @return \OCP\IURLGenerator
1447
-	 */
1448
-	public function getURLGenerator() {
1449
-		return $this->query('URLGenerator');
1450
-	}
1451
-
1452
-	/**
1453
-	 * @return AppFetcher
1454
-	 */
1455
-	public function getAppFetcher() {
1456
-		return $this->query(AppFetcher::class);
1457
-	}
1458
-
1459
-	/**
1460
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1461
-	 * getMemCacheFactory() instead.
1462
-	 *
1463
-	 * @return \OCP\ICache
1464
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1465
-	 */
1466
-	public function getCache() {
1467
-		return $this->query('UserCache');
1468
-	}
1469
-
1470
-	/**
1471
-	 * Returns an \OCP\CacheFactory instance
1472
-	 *
1473
-	 * @return \OCP\ICacheFactory
1474
-	 */
1475
-	public function getMemCacheFactory() {
1476
-		return $this->query('MemCacheFactory');
1477
-	}
1478
-
1479
-	/**
1480
-	 * Returns an \OC\RedisFactory instance
1481
-	 *
1482
-	 * @return \OC\RedisFactory
1483
-	 */
1484
-	public function getGetRedisFactory() {
1485
-		return $this->query('RedisFactory');
1486
-	}
1487
-
1488
-
1489
-	/**
1490
-	 * Returns the current session
1491
-	 *
1492
-	 * @return \OCP\IDBConnection
1493
-	 */
1494
-	public function getDatabaseConnection() {
1495
-		return $this->query('DatabaseConnection');
1496
-	}
1497
-
1498
-	/**
1499
-	 * Returns the activity manager
1500
-	 *
1501
-	 * @return \OCP\Activity\IManager
1502
-	 */
1503
-	public function getActivityManager() {
1504
-		return $this->query('ActivityManager');
1505
-	}
1506
-
1507
-	/**
1508
-	 * Returns an job list for controlling background jobs
1509
-	 *
1510
-	 * @return \OCP\BackgroundJob\IJobList
1511
-	 */
1512
-	public function getJobList() {
1513
-		return $this->query('JobList');
1514
-	}
1515
-
1516
-	/**
1517
-	 * Returns a logger instance
1518
-	 *
1519
-	 * @return \OCP\ILogger
1520
-	 */
1521
-	public function getLogger() {
1522
-		return $this->query('Logger');
1523
-	}
1524
-
1525
-	/**
1526
-	 * Returns a router for generating and matching urls
1527
-	 *
1528
-	 * @return \OCP\Route\IRouter
1529
-	 */
1530
-	public function getRouter() {
1531
-		return $this->query('Router');
1532
-	}
1533
-
1534
-	/**
1535
-	 * Returns a search instance
1536
-	 *
1537
-	 * @return \OCP\ISearch
1538
-	 */
1539
-	public function getSearch() {
1540
-		return $this->query('Search');
1541
-	}
1542
-
1543
-	/**
1544
-	 * Returns a SecureRandom instance
1545
-	 *
1546
-	 * @return \OCP\Security\ISecureRandom
1547
-	 */
1548
-	public function getSecureRandom() {
1549
-		return $this->query('SecureRandom');
1550
-	}
1551
-
1552
-	/**
1553
-	 * Returns a Crypto instance
1554
-	 *
1555
-	 * @return \OCP\Security\ICrypto
1556
-	 */
1557
-	public function getCrypto() {
1558
-		return $this->query('Crypto');
1559
-	}
1560
-
1561
-	/**
1562
-	 * Returns a Hasher instance
1563
-	 *
1564
-	 * @return \OCP\Security\IHasher
1565
-	 */
1566
-	public function getHasher() {
1567
-		return $this->query('Hasher');
1568
-	}
1569
-
1570
-	/**
1571
-	 * Returns a CredentialsManager instance
1572
-	 *
1573
-	 * @return \OCP\Security\ICredentialsManager
1574
-	 */
1575
-	public function getCredentialsManager() {
1576
-		return $this->query('CredentialsManager');
1577
-	}
1578
-
1579
-	/**
1580
-	 * Get the certificate manager for the user
1581
-	 *
1582
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1583
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1584
-	 */
1585
-	public function getCertificateManager($userId = '') {
1586
-		if ($userId === '') {
1587
-			$userSession = $this->getUserSession();
1588
-			$user = $userSession->getUser();
1589
-			if (is_null($user)) {
1590
-				return null;
1591
-			}
1592
-			$userId = $user->getUID();
1593
-		}
1594
-		return new CertificateManager(
1595
-			$userId,
1596
-			new View(),
1597
-			$this->getConfig(),
1598
-			$this->getLogger(),
1599
-			$this->getSecureRandom()
1600
-		);
1601
-	}
1602
-
1603
-	/**
1604
-	 * Returns an instance of the HTTP client service
1605
-	 *
1606
-	 * @return \OCP\Http\Client\IClientService
1607
-	 */
1608
-	public function getHTTPClientService() {
1609
-		return $this->query('HttpClientService');
1610
-	}
1611
-
1612
-	/**
1613
-	 * Create a new event source
1614
-	 *
1615
-	 * @return \OCP\IEventSource
1616
-	 */
1617
-	public function createEventSource() {
1618
-		return new \OC_EventSource();
1619
-	}
1620
-
1621
-	/**
1622
-	 * Get the active event logger
1623
-	 *
1624
-	 * The returned logger only logs data when debug mode is enabled
1625
-	 *
1626
-	 * @return \OCP\Diagnostics\IEventLogger
1627
-	 */
1628
-	public function getEventLogger() {
1629
-		return $this->query('EventLogger');
1630
-	}
1631
-
1632
-	/**
1633
-	 * Get the active query logger
1634
-	 *
1635
-	 * The returned logger only logs data when debug mode is enabled
1636
-	 *
1637
-	 * @return \OCP\Diagnostics\IQueryLogger
1638
-	 */
1639
-	public function getQueryLogger() {
1640
-		return $this->query('QueryLogger');
1641
-	}
1642
-
1643
-	/**
1644
-	 * Get the manager for temporary files and folders
1645
-	 *
1646
-	 * @return \OCP\ITempManager
1647
-	 */
1648
-	public function getTempManager() {
1649
-		return $this->query('TempManager');
1650
-	}
1651
-
1652
-	/**
1653
-	 * Get the app manager
1654
-	 *
1655
-	 * @return \OCP\App\IAppManager
1656
-	 */
1657
-	public function getAppManager() {
1658
-		return $this->query('AppManager');
1659
-	}
1660
-
1661
-	/**
1662
-	 * Creates a new mailer
1663
-	 *
1664
-	 * @return \OCP\Mail\IMailer
1665
-	 */
1666
-	public function getMailer() {
1667
-		return $this->query('Mailer');
1668
-	}
1669
-
1670
-	/**
1671
-	 * Get the webroot
1672
-	 *
1673
-	 * @return string
1674
-	 */
1675
-	public function getWebRoot() {
1676
-		return $this->webRoot;
1677
-	}
1678
-
1679
-	/**
1680
-	 * @return \OC\OCSClient
1681
-	 */
1682
-	public function getOcsClient() {
1683
-		return $this->query('OcsClient');
1684
-	}
1685
-
1686
-	/**
1687
-	 * @return \OCP\IDateTimeZone
1688
-	 */
1689
-	public function getDateTimeZone() {
1690
-		return $this->query('DateTimeZone');
1691
-	}
1692
-
1693
-	/**
1694
-	 * @return \OCP\IDateTimeFormatter
1695
-	 */
1696
-	public function getDateTimeFormatter() {
1697
-		return $this->query('DateTimeFormatter');
1698
-	}
1699
-
1700
-	/**
1701
-	 * @return \OCP\Files\Config\IMountProviderCollection
1702
-	 */
1703
-	public function getMountProviderCollection() {
1704
-		return $this->query('MountConfigManager');
1705
-	}
1706
-
1707
-	/**
1708
-	 * Get the IniWrapper
1709
-	 *
1710
-	 * @return IniGetWrapper
1711
-	 */
1712
-	public function getIniWrapper() {
1713
-		return $this->query('IniWrapper');
1714
-	}
1715
-
1716
-	/**
1717
-	 * @return \OCP\Command\IBus
1718
-	 */
1719
-	public function getCommandBus() {
1720
-		return $this->query('AsyncCommandBus');
1721
-	}
1722
-
1723
-	/**
1724
-	 * Get the trusted domain helper
1725
-	 *
1726
-	 * @return TrustedDomainHelper
1727
-	 */
1728
-	public function getTrustedDomainHelper() {
1729
-		return $this->query('TrustedDomainHelper');
1730
-	}
1731
-
1732
-	/**
1733
-	 * Get the locking provider
1734
-	 *
1735
-	 * @return \OCP\Lock\ILockingProvider
1736
-	 * @since 8.1.0
1737
-	 */
1738
-	public function getLockingProvider() {
1739
-		return $this->query('LockingProvider');
1740
-	}
1741
-
1742
-	/**
1743
-	 * @return \OCP\Files\Mount\IMountManager
1744
-	 **/
1745
-	function getMountManager() {
1746
-		return $this->query('MountManager');
1747
-	}
1748
-
1749
-	/** @return \OCP\Files\Config\IUserMountCache */
1750
-	function getUserMountCache() {
1751
-		return $this->query('UserMountCache');
1752
-	}
1753
-
1754
-	/**
1755
-	 * Get the MimeTypeDetector
1756
-	 *
1757
-	 * @return \OCP\Files\IMimeTypeDetector
1758
-	 */
1759
-	public function getMimeTypeDetector() {
1760
-		return $this->query('MimeTypeDetector');
1761
-	}
1762
-
1763
-	/**
1764
-	 * Get the MimeTypeLoader
1765
-	 *
1766
-	 * @return \OCP\Files\IMimeTypeLoader
1767
-	 */
1768
-	public function getMimeTypeLoader() {
1769
-		return $this->query('MimeTypeLoader');
1770
-	}
1771
-
1772
-	/**
1773
-	 * Get the manager of all the capabilities
1774
-	 *
1775
-	 * @return \OC\CapabilitiesManager
1776
-	 */
1777
-	public function getCapabilitiesManager() {
1778
-		return $this->query('CapabilitiesManager');
1779
-	}
1780
-
1781
-	/**
1782
-	 * Get the EventDispatcher
1783
-	 *
1784
-	 * @return EventDispatcherInterface
1785
-	 * @since 8.2.0
1786
-	 */
1787
-	public function getEventDispatcher() {
1788
-		return $this->query('EventDispatcher');
1789
-	}
1790
-
1791
-	/**
1792
-	 * Get the Notification Manager
1793
-	 *
1794
-	 * @return \OCP\Notification\IManager
1795
-	 * @since 8.2.0
1796
-	 */
1797
-	public function getNotificationManager() {
1798
-		return $this->query('NotificationManager');
1799
-	}
1800
-
1801
-	/**
1802
-	 * @return \OCP\Comments\ICommentsManager
1803
-	 */
1804
-	public function getCommentsManager() {
1805
-		return $this->query('CommentsManager');
1806
-	}
1807
-
1808
-	/**
1809
-	 * @return \OCA\Theming\ThemingDefaults
1810
-	 */
1811
-	public function getThemingDefaults() {
1812
-		return $this->query('ThemingDefaults');
1813
-	}
1814
-
1815
-	/**
1816
-	 * @return \OC\IntegrityCheck\Checker
1817
-	 */
1818
-	public function getIntegrityCodeChecker() {
1819
-		return $this->query('IntegrityCodeChecker');
1820
-	}
1821
-
1822
-	/**
1823
-	 * @return \OC\Session\CryptoWrapper
1824
-	 */
1825
-	public function getSessionCryptoWrapper() {
1826
-		return $this->query('CryptoWrapper');
1827
-	}
1828
-
1829
-	/**
1830
-	 * @return CsrfTokenManager
1831
-	 */
1832
-	public function getCsrfTokenManager() {
1833
-		return $this->query('CsrfTokenManager');
1834
-	}
1835
-
1836
-	/**
1837
-	 * @return Throttler
1838
-	 */
1839
-	public function getBruteForceThrottler() {
1840
-		return $this->query('Throttler');
1841
-	}
1842
-
1843
-	/**
1844
-	 * @return IContentSecurityPolicyManager
1845
-	 */
1846
-	public function getContentSecurityPolicyManager() {
1847
-		return $this->query('ContentSecurityPolicyManager');
1848
-	}
1849
-
1850
-	/**
1851
-	 * @return ContentSecurityPolicyNonceManager
1852
-	 */
1853
-	public function getContentSecurityPolicyNonceManager() {
1854
-		return $this->query('ContentSecurityPolicyNonceManager');
1855
-	}
1856
-
1857
-	/**
1858
-	 * Not a public API as of 8.2, wait for 9.0
1859
-	 *
1860
-	 * @return \OCA\Files_External\Service\BackendService
1861
-	 */
1862
-	public function getStoragesBackendService() {
1863
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1864
-	}
1865
-
1866
-	/**
1867
-	 * Not a public API as of 8.2, wait for 9.0
1868
-	 *
1869
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1870
-	 */
1871
-	public function getGlobalStoragesService() {
1872
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1873
-	}
1874
-
1875
-	/**
1876
-	 * Not a public API as of 8.2, wait for 9.0
1877
-	 *
1878
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1879
-	 */
1880
-	public function getUserGlobalStoragesService() {
1881
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1882
-	}
1883
-
1884
-	/**
1885
-	 * Not a public API as of 8.2, wait for 9.0
1886
-	 *
1887
-	 * @return \OCA\Files_External\Service\UserStoragesService
1888
-	 */
1889
-	public function getUserStoragesService() {
1890
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1891
-	}
1892
-
1893
-	/**
1894
-	 * @return \OCP\Share\IManager
1895
-	 */
1896
-	public function getShareManager() {
1897
-		return $this->query('ShareManager');
1898
-	}
1899
-
1900
-	/**
1901
-	 * @return \OCP\Collaboration\Collaborators\ISearch
1902
-	 */
1903
-	public function getCollaboratorSearch() {
1904
-		return $this->query('CollaboratorSearch');
1905
-	}
1906
-
1907
-	/**
1908
-	 * @return \OCP\Collaboration\AutoComplete\IManager
1909
-	 */
1910
-	public function getAutoCompleteManager(){
1911
-		return $this->query(IManager::class);
1912
-	}
1913
-
1914
-	/**
1915
-	 * Returns the LDAP Provider
1916
-	 *
1917
-	 * @return \OCP\LDAP\ILDAPProvider
1918
-	 */
1919
-	public function getLDAPProvider() {
1920
-		return $this->query('LDAPProvider');
1921
-	}
1922
-
1923
-	/**
1924
-	 * @return \OCP\Settings\IManager
1925
-	 */
1926
-	public function getSettingsManager() {
1927
-		return $this->query('SettingsManager');
1928
-	}
1929
-
1930
-	/**
1931
-	 * @return \OCP\Files\IAppData
1932
-	 */
1933
-	public function getAppDataDir($app) {
1934
-		/** @var \OC\Files\AppData\Factory $factory */
1935
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
1936
-		return $factory->get($app);
1937
-	}
1938
-
1939
-	/**
1940
-	 * @return \OCP\Lockdown\ILockdownManager
1941
-	 */
1942
-	public function getLockdownManager() {
1943
-		return $this->query('LockdownManager');
1944
-	}
1945
-
1946
-	/**
1947
-	 * @return \OCP\Federation\ICloudIdManager
1948
-	 */
1949
-	public function getCloudIdManager() {
1950
-		return $this->query(ICloudIdManager::class);
1951
-	}
1952
-
1953
-	/**
1954
-	 * @return \OCP\Remote\Api\IApiFactory
1955
-	 */
1956
-	public function getRemoteApiFactory() {
1957
-		return $this->query(IApiFactory::class);
1958
-	}
1959
-
1960
-	/**
1961
-	 * @return \OCP\Remote\IInstanceFactory
1962
-	 */
1963
-	public function getRemoteInstanceFactory() {
1964
-		return $this->query(IInstanceFactory::class);
1965
-	}
929
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
930
+            if (isset($prefixes['OCA\\Theming\\'])) {
931
+                $classExists = true;
932
+            } else {
933
+                $classExists = false;
934
+            }
935
+
936
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
937
+                return new ThemingDefaults(
938
+                    $c->getConfig(),
939
+                    $c->getL10N('theming'),
940
+                    $c->getURLGenerator(),
941
+                    $c->getMemCacheFactory(),
942
+                    new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
943
+                    new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator()),
944
+                    $c->getAppManager()
945
+                );
946
+            }
947
+            return new \OC_Defaults();
948
+        });
949
+        $this->registerService(SCSSCacher::class, function (Server $c) {
950
+            /** @var Factory $cacheFactory */
951
+            $cacheFactory = $c->query(Factory::class);
952
+            return new SCSSCacher(
953
+                $c->getLogger(),
954
+                $c->query(\OC\Files\AppData\Factory::class),
955
+                $c->getURLGenerator(),
956
+                $c->getConfig(),
957
+                $c->getThemingDefaults(),
958
+                \OC::$SERVERROOT,
959
+                $this->getMemCacheFactory()
960
+            );
961
+        });
962
+        $this->registerService(JSCombiner::class, function (Server $c) {
963
+            /** @var Factory $cacheFactory */
964
+            $cacheFactory = $c->query(Factory::class);
965
+            return new JSCombiner(
966
+                $c->getAppDataDir('js'),
967
+                $c->getURLGenerator(),
968
+                $this->getMemCacheFactory(),
969
+                $c->getSystemConfig(),
970
+                $c->getLogger()
971
+            );
972
+        });
973
+        $this->registerService(EventDispatcher::class, function () {
974
+            return new EventDispatcher();
975
+        });
976
+        $this->registerAlias('EventDispatcher', EventDispatcher::class);
977
+        $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
978
+
979
+        $this->registerService('CryptoWrapper', function (Server $c) {
980
+            // FIXME: Instantiiated here due to cyclic dependency
981
+            $request = new Request(
982
+                [
983
+                    'get' => $_GET,
984
+                    'post' => $_POST,
985
+                    'files' => $_FILES,
986
+                    'server' => $_SERVER,
987
+                    'env' => $_ENV,
988
+                    'cookies' => $_COOKIE,
989
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
990
+                        ? $_SERVER['REQUEST_METHOD']
991
+                        : null,
992
+                ],
993
+                $c->getSecureRandom(),
994
+                $c->getConfig()
995
+            );
996
+
997
+            return new CryptoWrapper(
998
+                $c->getConfig(),
999
+                $c->getCrypto(),
1000
+                $c->getSecureRandom(),
1001
+                $request
1002
+            );
1003
+        });
1004
+        $this->registerService('CsrfTokenManager', function (Server $c) {
1005
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1006
+
1007
+            return new CsrfTokenManager(
1008
+                $tokenGenerator,
1009
+                $c->query(SessionStorage::class)
1010
+            );
1011
+        });
1012
+        $this->registerService(SessionStorage::class, function (Server $c) {
1013
+            return new SessionStorage($c->getSession());
1014
+        });
1015
+        $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
1016
+            return new ContentSecurityPolicyManager();
1017
+        });
1018
+        $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
1019
+
1020
+        $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1021
+            return new ContentSecurityPolicyNonceManager(
1022
+                $c->getCsrfTokenManager(),
1023
+                $c->getRequest()
1024
+            );
1025
+        });
1026
+
1027
+        $this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1028
+            $config = $c->getConfig();
1029
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1030
+            /** @var \OCP\Share\IProviderFactory $factory */
1031
+            $factory = new $factoryClass($this);
1032
+
1033
+            $manager = new \OC\Share20\Manager(
1034
+                $c->getLogger(),
1035
+                $c->getConfig(),
1036
+                $c->getSecureRandom(),
1037
+                $c->getHasher(),
1038
+                $c->getMountManager(),
1039
+                $c->getGroupManager(),
1040
+                $c->getL10N('lib'),
1041
+                $c->getL10NFactory(),
1042
+                $factory,
1043
+                $c->getUserManager(),
1044
+                $c->getLazyRootFolder(),
1045
+                $c->getEventDispatcher(),
1046
+                $c->getMailer(),
1047
+                $c->getURLGenerator(),
1048
+                $c->getThemingDefaults()
1049
+            );
1050
+
1051
+            return $manager;
1052
+        });
1053
+        $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
1054
+
1055
+        $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
1056
+            $instance = new Collaboration\Collaborators\Search($c);
1057
+
1058
+            // register default plugins
1059
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1060
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1061
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1062
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1063
+
1064
+            return $instance;
1065
+        });
1066
+        $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1067
+
1068
+        $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1069
+
1070
+        $this->registerService('SettingsManager', function (Server $c) {
1071
+            $manager = new \OC\Settings\Manager(
1072
+                $c->getLogger(),
1073
+                $c->getDatabaseConnection(),
1074
+                $c->getL10N('lib'),
1075
+                $c->getConfig(),
1076
+                $c->getEncryptionManager(),
1077
+                $c->getUserManager(),
1078
+                $c->getLockingProvider(),
1079
+                $c->getRequest(),
1080
+                $c->getURLGenerator(),
1081
+                $c->query(AccountManager::class),
1082
+                $c->getGroupManager(),
1083
+                $c->getL10NFactory(),
1084
+                $c->getAppManager()
1085
+            );
1086
+            return $manager;
1087
+        });
1088
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1089
+            return new \OC\Files\AppData\Factory(
1090
+                $c->getRootFolder(),
1091
+                $c->getSystemConfig()
1092
+            );
1093
+        });
1094
+
1095
+        $this->registerService('LockdownManager', function (Server $c) {
1096
+            return new LockdownManager(function () use ($c) {
1097
+                return $c->getSession();
1098
+            });
1099
+        });
1100
+
1101
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1102
+            return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1103
+        });
1104
+
1105
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
1106
+            return new CloudIdManager();
1107
+        });
1108
+
1109
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1110
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1111
+
1112
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1113
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1114
+
1115
+        $this->registerService(Defaults::class, function (Server $c) {
1116
+            return new Defaults(
1117
+                $c->getThemingDefaults()
1118
+            );
1119
+        });
1120
+        $this->registerAlias('Defaults', \OCP\Defaults::class);
1121
+
1122
+        $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1123
+            return $c->query(\OCP\IUserSession::class)->getSession();
1124
+        });
1125
+
1126
+        $this->registerService(IShareHelper::class, function (Server $c) {
1127
+            return new ShareHelper(
1128
+                $c->query(\OCP\Share\IManager::class)
1129
+            );
1130
+        });
1131
+
1132
+        $this->registerService(Installer::class, function(Server $c) {
1133
+            return new Installer(
1134
+                $c->getAppFetcher(),
1135
+                $c->getHTTPClientService(),
1136
+                $c->getTempManager(),
1137
+                $c->getLogger(),
1138
+                $c->getConfig()
1139
+            );
1140
+        });
1141
+
1142
+        $this->registerService(IApiFactory::class, function(Server $c) {
1143
+            return new ApiFactory($c->getHTTPClientService());
1144
+        });
1145
+
1146
+        $this->registerService(IInstanceFactory::class, function(Server $c) {
1147
+            $memcacheFactory = $c->getMemCacheFactory();
1148
+            return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
1149
+        });
1150
+
1151
+        $this->registerService(IContactsStore::class, function(Server $c) {
1152
+            return new ContactsStore(
1153
+                $c->getContactsManager(),
1154
+                $c->getConfig(),
1155
+                $c->getUserManager(),
1156
+                $c->getGroupManager()
1157
+            );
1158
+        });
1159
+        $this->registerAlias(IContactsStore::class, ContactsStore::class);
1160
+
1161
+        $this->connectDispatcher();
1162
+    }
1163
+
1164
+    /**
1165
+     * @return \OCP\Calendar\IManager
1166
+     */
1167
+    public function getCalendarManager() {
1168
+        return $this->query('CalendarManager');
1169
+    }
1170
+
1171
+    private function connectDispatcher() {
1172
+        $dispatcher = $this->getEventDispatcher();
1173
+
1174
+        // Delete avatar on user deletion
1175
+        $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
1176
+            $logger = $this->getLogger();
1177
+            $manager = $this->getAvatarManager();
1178
+            /** @var IUser $user */
1179
+            $user = $e->getSubject();
1180
+
1181
+            try {
1182
+                $avatar = $manager->getAvatar($user->getUID());
1183
+                $avatar->remove();
1184
+            } catch (NotFoundException $e) {
1185
+                // no avatar to remove
1186
+            } catch (\Exception $e) {
1187
+                // Ignore exceptions
1188
+                $logger->info('Could not cleanup avatar of ' . $user->getUID());
1189
+            }
1190
+        });
1191
+
1192
+        $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1193
+            $manager = $this->getAvatarManager();
1194
+            /** @var IUser $user */
1195
+            $user = $e->getSubject();
1196
+            $feature = $e->getArgument('feature');
1197
+            $oldValue = $e->getArgument('oldValue');
1198
+            $value = $e->getArgument('value');
1199
+
1200
+            try {
1201
+                $avatar = $manager->getAvatar($user->getUID());
1202
+                $avatar->userChanged($feature, $oldValue, $value);
1203
+            } catch (NotFoundException $e) {
1204
+                // no avatar to remove
1205
+            }
1206
+        });
1207
+    }
1208
+
1209
+    /**
1210
+     * @return \OCP\Contacts\IManager
1211
+     */
1212
+    public function getContactsManager() {
1213
+        return $this->query('ContactsManager');
1214
+    }
1215
+
1216
+    /**
1217
+     * @return \OC\Encryption\Manager
1218
+     */
1219
+    public function getEncryptionManager() {
1220
+        return $this->query('EncryptionManager');
1221
+    }
1222
+
1223
+    /**
1224
+     * @return \OC\Encryption\File
1225
+     */
1226
+    public function getEncryptionFilesHelper() {
1227
+        return $this->query('EncryptionFileHelper');
1228
+    }
1229
+
1230
+    /**
1231
+     * @return \OCP\Encryption\Keys\IStorage
1232
+     */
1233
+    public function getEncryptionKeyStorage() {
1234
+        return $this->query('EncryptionKeyStorage');
1235
+    }
1236
+
1237
+    /**
1238
+     * The current request object holding all information about the request
1239
+     * currently being processed is returned from this method.
1240
+     * In case the current execution was not initiated by a web request null is returned
1241
+     *
1242
+     * @return \OCP\IRequest
1243
+     */
1244
+    public function getRequest() {
1245
+        return $this->query('Request');
1246
+    }
1247
+
1248
+    /**
1249
+     * Returns the preview manager which can create preview images for a given file
1250
+     *
1251
+     * @return \OCP\IPreview
1252
+     */
1253
+    public function getPreviewManager() {
1254
+        return $this->query('PreviewManager');
1255
+    }
1256
+
1257
+    /**
1258
+     * Returns the tag manager which can get and set tags for different object types
1259
+     *
1260
+     * @see \OCP\ITagManager::load()
1261
+     * @return \OCP\ITagManager
1262
+     */
1263
+    public function getTagManager() {
1264
+        return $this->query('TagManager');
1265
+    }
1266
+
1267
+    /**
1268
+     * Returns the system-tag manager
1269
+     *
1270
+     * @return \OCP\SystemTag\ISystemTagManager
1271
+     *
1272
+     * @since 9.0.0
1273
+     */
1274
+    public function getSystemTagManager() {
1275
+        return $this->query('SystemTagManager');
1276
+    }
1277
+
1278
+    /**
1279
+     * Returns the system-tag object mapper
1280
+     *
1281
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
1282
+     *
1283
+     * @since 9.0.0
1284
+     */
1285
+    public function getSystemTagObjectMapper() {
1286
+        return $this->query('SystemTagObjectMapper');
1287
+    }
1288
+
1289
+    /**
1290
+     * Returns the avatar manager, used for avatar functionality
1291
+     *
1292
+     * @return \OCP\IAvatarManager
1293
+     */
1294
+    public function getAvatarManager() {
1295
+        return $this->query('AvatarManager');
1296
+    }
1297
+
1298
+    /**
1299
+     * Returns the root folder of ownCloud's data directory
1300
+     *
1301
+     * @return \OCP\Files\IRootFolder
1302
+     */
1303
+    public function getRootFolder() {
1304
+        return $this->query('LazyRootFolder');
1305
+    }
1306
+
1307
+    /**
1308
+     * Returns the root folder of ownCloud's data directory
1309
+     * This is the lazy variant so this gets only initialized once it
1310
+     * is actually used.
1311
+     *
1312
+     * @return \OCP\Files\IRootFolder
1313
+     */
1314
+    public function getLazyRootFolder() {
1315
+        return $this->query('LazyRootFolder');
1316
+    }
1317
+
1318
+    /**
1319
+     * Returns a view to ownCloud's files folder
1320
+     *
1321
+     * @param string $userId user ID
1322
+     * @return \OCP\Files\Folder|null
1323
+     */
1324
+    public function getUserFolder($userId = null) {
1325
+        if ($userId === null) {
1326
+            $user = $this->getUserSession()->getUser();
1327
+            if (!$user) {
1328
+                return null;
1329
+            }
1330
+            $userId = $user->getUID();
1331
+        }
1332
+        $root = $this->getRootFolder();
1333
+        return $root->getUserFolder($userId);
1334
+    }
1335
+
1336
+    /**
1337
+     * Returns an app-specific view in ownClouds data directory
1338
+     *
1339
+     * @return \OCP\Files\Folder
1340
+     * @deprecated since 9.2.0 use IAppData
1341
+     */
1342
+    public function getAppFolder() {
1343
+        $dir = '/' . \OC_App::getCurrentApp();
1344
+        $root = $this->getRootFolder();
1345
+        if (!$root->nodeExists($dir)) {
1346
+            $folder = $root->newFolder($dir);
1347
+        } else {
1348
+            $folder = $root->get($dir);
1349
+        }
1350
+        return $folder;
1351
+    }
1352
+
1353
+    /**
1354
+     * @return \OC\User\Manager
1355
+     */
1356
+    public function getUserManager() {
1357
+        return $this->query('UserManager');
1358
+    }
1359
+
1360
+    /**
1361
+     * @return \OC\Group\Manager
1362
+     */
1363
+    public function getGroupManager() {
1364
+        return $this->query('GroupManager');
1365
+    }
1366
+
1367
+    /**
1368
+     * @return \OC\User\Session
1369
+     */
1370
+    public function getUserSession() {
1371
+        return $this->query('UserSession');
1372
+    }
1373
+
1374
+    /**
1375
+     * @return \OCP\ISession
1376
+     */
1377
+    public function getSession() {
1378
+        return $this->query('UserSession')->getSession();
1379
+    }
1380
+
1381
+    /**
1382
+     * @param \OCP\ISession $session
1383
+     */
1384
+    public function setSession(\OCP\ISession $session) {
1385
+        $this->query(SessionStorage::class)->setSession($session);
1386
+        $this->query('UserSession')->setSession($session);
1387
+        $this->query(Store::class)->setSession($session);
1388
+    }
1389
+
1390
+    /**
1391
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1392
+     */
1393
+    public function getTwoFactorAuthManager() {
1394
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1395
+    }
1396
+
1397
+    /**
1398
+     * @return \OC\NavigationManager
1399
+     */
1400
+    public function getNavigationManager() {
1401
+        return $this->query('NavigationManager');
1402
+    }
1403
+
1404
+    /**
1405
+     * @return \OCP\IConfig
1406
+     */
1407
+    public function getConfig() {
1408
+        return $this->query('AllConfig');
1409
+    }
1410
+
1411
+    /**
1412
+     * @return \OC\SystemConfig
1413
+     */
1414
+    public function getSystemConfig() {
1415
+        return $this->query('SystemConfig');
1416
+    }
1417
+
1418
+    /**
1419
+     * Returns the app config manager
1420
+     *
1421
+     * @return \OCP\IAppConfig
1422
+     */
1423
+    public function getAppConfig() {
1424
+        return $this->query('AppConfig');
1425
+    }
1426
+
1427
+    /**
1428
+     * @return \OCP\L10N\IFactory
1429
+     */
1430
+    public function getL10NFactory() {
1431
+        return $this->query('L10NFactory');
1432
+    }
1433
+
1434
+    /**
1435
+     * get an L10N instance
1436
+     *
1437
+     * @param string $app appid
1438
+     * @param string $lang
1439
+     * @return IL10N
1440
+     */
1441
+    public function getL10N($app, $lang = null) {
1442
+        return $this->getL10NFactory()->get($app, $lang);
1443
+    }
1444
+
1445
+    /**
1446
+     * @return \OCP\IURLGenerator
1447
+     */
1448
+    public function getURLGenerator() {
1449
+        return $this->query('URLGenerator');
1450
+    }
1451
+
1452
+    /**
1453
+     * @return AppFetcher
1454
+     */
1455
+    public function getAppFetcher() {
1456
+        return $this->query(AppFetcher::class);
1457
+    }
1458
+
1459
+    /**
1460
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1461
+     * getMemCacheFactory() instead.
1462
+     *
1463
+     * @return \OCP\ICache
1464
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1465
+     */
1466
+    public function getCache() {
1467
+        return $this->query('UserCache');
1468
+    }
1469
+
1470
+    /**
1471
+     * Returns an \OCP\CacheFactory instance
1472
+     *
1473
+     * @return \OCP\ICacheFactory
1474
+     */
1475
+    public function getMemCacheFactory() {
1476
+        return $this->query('MemCacheFactory');
1477
+    }
1478
+
1479
+    /**
1480
+     * Returns an \OC\RedisFactory instance
1481
+     *
1482
+     * @return \OC\RedisFactory
1483
+     */
1484
+    public function getGetRedisFactory() {
1485
+        return $this->query('RedisFactory');
1486
+    }
1487
+
1488
+
1489
+    /**
1490
+     * Returns the current session
1491
+     *
1492
+     * @return \OCP\IDBConnection
1493
+     */
1494
+    public function getDatabaseConnection() {
1495
+        return $this->query('DatabaseConnection');
1496
+    }
1497
+
1498
+    /**
1499
+     * Returns the activity manager
1500
+     *
1501
+     * @return \OCP\Activity\IManager
1502
+     */
1503
+    public function getActivityManager() {
1504
+        return $this->query('ActivityManager');
1505
+    }
1506
+
1507
+    /**
1508
+     * Returns an job list for controlling background jobs
1509
+     *
1510
+     * @return \OCP\BackgroundJob\IJobList
1511
+     */
1512
+    public function getJobList() {
1513
+        return $this->query('JobList');
1514
+    }
1515
+
1516
+    /**
1517
+     * Returns a logger instance
1518
+     *
1519
+     * @return \OCP\ILogger
1520
+     */
1521
+    public function getLogger() {
1522
+        return $this->query('Logger');
1523
+    }
1524
+
1525
+    /**
1526
+     * Returns a router for generating and matching urls
1527
+     *
1528
+     * @return \OCP\Route\IRouter
1529
+     */
1530
+    public function getRouter() {
1531
+        return $this->query('Router');
1532
+    }
1533
+
1534
+    /**
1535
+     * Returns a search instance
1536
+     *
1537
+     * @return \OCP\ISearch
1538
+     */
1539
+    public function getSearch() {
1540
+        return $this->query('Search');
1541
+    }
1542
+
1543
+    /**
1544
+     * Returns a SecureRandom instance
1545
+     *
1546
+     * @return \OCP\Security\ISecureRandom
1547
+     */
1548
+    public function getSecureRandom() {
1549
+        return $this->query('SecureRandom');
1550
+    }
1551
+
1552
+    /**
1553
+     * Returns a Crypto instance
1554
+     *
1555
+     * @return \OCP\Security\ICrypto
1556
+     */
1557
+    public function getCrypto() {
1558
+        return $this->query('Crypto');
1559
+    }
1560
+
1561
+    /**
1562
+     * Returns a Hasher instance
1563
+     *
1564
+     * @return \OCP\Security\IHasher
1565
+     */
1566
+    public function getHasher() {
1567
+        return $this->query('Hasher');
1568
+    }
1569
+
1570
+    /**
1571
+     * Returns a CredentialsManager instance
1572
+     *
1573
+     * @return \OCP\Security\ICredentialsManager
1574
+     */
1575
+    public function getCredentialsManager() {
1576
+        return $this->query('CredentialsManager');
1577
+    }
1578
+
1579
+    /**
1580
+     * Get the certificate manager for the user
1581
+     *
1582
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1583
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1584
+     */
1585
+    public function getCertificateManager($userId = '') {
1586
+        if ($userId === '') {
1587
+            $userSession = $this->getUserSession();
1588
+            $user = $userSession->getUser();
1589
+            if (is_null($user)) {
1590
+                return null;
1591
+            }
1592
+            $userId = $user->getUID();
1593
+        }
1594
+        return new CertificateManager(
1595
+            $userId,
1596
+            new View(),
1597
+            $this->getConfig(),
1598
+            $this->getLogger(),
1599
+            $this->getSecureRandom()
1600
+        );
1601
+    }
1602
+
1603
+    /**
1604
+     * Returns an instance of the HTTP client service
1605
+     *
1606
+     * @return \OCP\Http\Client\IClientService
1607
+     */
1608
+    public function getHTTPClientService() {
1609
+        return $this->query('HttpClientService');
1610
+    }
1611
+
1612
+    /**
1613
+     * Create a new event source
1614
+     *
1615
+     * @return \OCP\IEventSource
1616
+     */
1617
+    public function createEventSource() {
1618
+        return new \OC_EventSource();
1619
+    }
1620
+
1621
+    /**
1622
+     * Get the active event logger
1623
+     *
1624
+     * The returned logger only logs data when debug mode is enabled
1625
+     *
1626
+     * @return \OCP\Diagnostics\IEventLogger
1627
+     */
1628
+    public function getEventLogger() {
1629
+        return $this->query('EventLogger');
1630
+    }
1631
+
1632
+    /**
1633
+     * Get the active query logger
1634
+     *
1635
+     * The returned logger only logs data when debug mode is enabled
1636
+     *
1637
+     * @return \OCP\Diagnostics\IQueryLogger
1638
+     */
1639
+    public function getQueryLogger() {
1640
+        return $this->query('QueryLogger');
1641
+    }
1642
+
1643
+    /**
1644
+     * Get the manager for temporary files and folders
1645
+     *
1646
+     * @return \OCP\ITempManager
1647
+     */
1648
+    public function getTempManager() {
1649
+        return $this->query('TempManager');
1650
+    }
1651
+
1652
+    /**
1653
+     * Get the app manager
1654
+     *
1655
+     * @return \OCP\App\IAppManager
1656
+     */
1657
+    public function getAppManager() {
1658
+        return $this->query('AppManager');
1659
+    }
1660
+
1661
+    /**
1662
+     * Creates a new mailer
1663
+     *
1664
+     * @return \OCP\Mail\IMailer
1665
+     */
1666
+    public function getMailer() {
1667
+        return $this->query('Mailer');
1668
+    }
1669
+
1670
+    /**
1671
+     * Get the webroot
1672
+     *
1673
+     * @return string
1674
+     */
1675
+    public function getWebRoot() {
1676
+        return $this->webRoot;
1677
+    }
1678
+
1679
+    /**
1680
+     * @return \OC\OCSClient
1681
+     */
1682
+    public function getOcsClient() {
1683
+        return $this->query('OcsClient');
1684
+    }
1685
+
1686
+    /**
1687
+     * @return \OCP\IDateTimeZone
1688
+     */
1689
+    public function getDateTimeZone() {
1690
+        return $this->query('DateTimeZone');
1691
+    }
1692
+
1693
+    /**
1694
+     * @return \OCP\IDateTimeFormatter
1695
+     */
1696
+    public function getDateTimeFormatter() {
1697
+        return $this->query('DateTimeFormatter');
1698
+    }
1699
+
1700
+    /**
1701
+     * @return \OCP\Files\Config\IMountProviderCollection
1702
+     */
1703
+    public function getMountProviderCollection() {
1704
+        return $this->query('MountConfigManager');
1705
+    }
1706
+
1707
+    /**
1708
+     * Get the IniWrapper
1709
+     *
1710
+     * @return IniGetWrapper
1711
+     */
1712
+    public function getIniWrapper() {
1713
+        return $this->query('IniWrapper');
1714
+    }
1715
+
1716
+    /**
1717
+     * @return \OCP\Command\IBus
1718
+     */
1719
+    public function getCommandBus() {
1720
+        return $this->query('AsyncCommandBus');
1721
+    }
1722
+
1723
+    /**
1724
+     * Get the trusted domain helper
1725
+     *
1726
+     * @return TrustedDomainHelper
1727
+     */
1728
+    public function getTrustedDomainHelper() {
1729
+        return $this->query('TrustedDomainHelper');
1730
+    }
1731
+
1732
+    /**
1733
+     * Get the locking provider
1734
+     *
1735
+     * @return \OCP\Lock\ILockingProvider
1736
+     * @since 8.1.0
1737
+     */
1738
+    public function getLockingProvider() {
1739
+        return $this->query('LockingProvider');
1740
+    }
1741
+
1742
+    /**
1743
+     * @return \OCP\Files\Mount\IMountManager
1744
+     **/
1745
+    function getMountManager() {
1746
+        return $this->query('MountManager');
1747
+    }
1748
+
1749
+    /** @return \OCP\Files\Config\IUserMountCache */
1750
+    function getUserMountCache() {
1751
+        return $this->query('UserMountCache');
1752
+    }
1753
+
1754
+    /**
1755
+     * Get the MimeTypeDetector
1756
+     *
1757
+     * @return \OCP\Files\IMimeTypeDetector
1758
+     */
1759
+    public function getMimeTypeDetector() {
1760
+        return $this->query('MimeTypeDetector');
1761
+    }
1762
+
1763
+    /**
1764
+     * Get the MimeTypeLoader
1765
+     *
1766
+     * @return \OCP\Files\IMimeTypeLoader
1767
+     */
1768
+    public function getMimeTypeLoader() {
1769
+        return $this->query('MimeTypeLoader');
1770
+    }
1771
+
1772
+    /**
1773
+     * Get the manager of all the capabilities
1774
+     *
1775
+     * @return \OC\CapabilitiesManager
1776
+     */
1777
+    public function getCapabilitiesManager() {
1778
+        return $this->query('CapabilitiesManager');
1779
+    }
1780
+
1781
+    /**
1782
+     * Get the EventDispatcher
1783
+     *
1784
+     * @return EventDispatcherInterface
1785
+     * @since 8.2.0
1786
+     */
1787
+    public function getEventDispatcher() {
1788
+        return $this->query('EventDispatcher');
1789
+    }
1790
+
1791
+    /**
1792
+     * Get the Notification Manager
1793
+     *
1794
+     * @return \OCP\Notification\IManager
1795
+     * @since 8.2.0
1796
+     */
1797
+    public function getNotificationManager() {
1798
+        return $this->query('NotificationManager');
1799
+    }
1800
+
1801
+    /**
1802
+     * @return \OCP\Comments\ICommentsManager
1803
+     */
1804
+    public function getCommentsManager() {
1805
+        return $this->query('CommentsManager');
1806
+    }
1807
+
1808
+    /**
1809
+     * @return \OCA\Theming\ThemingDefaults
1810
+     */
1811
+    public function getThemingDefaults() {
1812
+        return $this->query('ThemingDefaults');
1813
+    }
1814
+
1815
+    /**
1816
+     * @return \OC\IntegrityCheck\Checker
1817
+     */
1818
+    public function getIntegrityCodeChecker() {
1819
+        return $this->query('IntegrityCodeChecker');
1820
+    }
1821
+
1822
+    /**
1823
+     * @return \OC\Session\CryptoWrapper
1824
+     */
1825
+    public function getSessionCryptoWrapper() {
1826
+        return $this->query('CryptoWrapper');
1827
+    }
1828
+
1829
+    /**
1830
+     * @return CsrfTokenManager
1831
+     */
1832
+    public function getCsrfTokenManager() {
1833
+        return $this->query('CsrfTokenManager');
1834
+    }
1835
+
1836
+    /**
1837
+     * @return Throttler
1838
+     */
1839
+    public function getBruteForceThrottler() {
1840
+        return $this->query('Throttler');
1841
+    }
1842
+
1843
+    /**
1844
+     * @return IContentSecurityPolicyManager
1845
+     */
1846
+    public function getContentSecurityPolicyManager() {
1847
+        return $this->query('ContentSecurityPolicyManager');
1848
+    }
1849
+
1850
+    /**
1851
+     * @return ContentSecurityPolicyNonceManager
1852
+     */
1853
+    public function getContentSecurityPolicyNonceManager() {
1854
+        return $this->query('ContentSecurityPolicyNonceManager');
1855
+    }
1856
+
1857
+    /**
1858
+     * Not a public API as of 8.2, wait for 9.0
1859
+     *
1860
+     * @return \OCA\Files_External\Service\BackendService
1861
+     */
1862
+    public function getStoragesBackendService() {
1863
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1864
+    }
1865
+
1866
+    /**
1867
+     * Not a public API as of 8.2, wait for 9.0
1868
+     *
1869
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1870
+     */
1871
+    public function getGlobalStoragesService() {
1872
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1873
+    }
1874
+
1875
+    /**
1876
+     * Not a public API as of 8.2, wait for 9.0
1877
+     *
1878
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1879
+     */
1880
+    public function getUserGlobalStoragesService() {
1881
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1882
+    }
1883
+
1884
+    /**
1885
+     * Not a public API as of 8.2, wait for 9.0
1886
+     *
1887
+     * @return \OCA\Files_External\Service\UserStoragesService
1888
+     */
1889
+    public function getUserStoragesService() {
1890
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1891
+    }
1892
+
1893
+    /**
1894
+     * @return \OCP\Share\IManager
1895
+     */
1896
+    public function getShareManager() {
1897
+        return $this->query('ShareManager');
1898
+    }
1899
+
1900
+    /**
1901
+     * @return \OCP\Collaboration\Collaborators\ISearch
1902
+     */
1903
+    public function getCollaboratorSearch() {
1904
+        return $this->query('CollaboratorSearch');
1905
+    }
1906
+
1907
+    /**
1908
+     * @return \OCP\Collaboration\AutoComplete\IManager
1909
+     */
1910
+    public function getAutoCompleteManager(){
1911
+        return $this->query(IManager::class);
1912
+    }
1913
+
1914
+    /**
1915
+     * Returns the LDAP Provider
1916
+     *
1917
+     * @return \OCP\LDAP\ILDAPProvider
1918
+     */
1919
+    public function getLDAPProvider() {
1920
+        return $this->query('LDAPProvider');
1921
+    }
1922
+
1923
+    /**
1924
+     * @return \OCP\Settings\IManager
1925
+     */
1926
+    public function getSettingsManager() {
1927
+        return $this->query('SettingsManager');
1928
+    }
1929
+
1930
+    /**
1931
+     * @return \OCP\Files\IAppData
1932
+     */
1933
+    public function getAppDataDir($app) {
1934
+        /** @var \OC\Files\AppData\Factory $factory */
1935
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
1936
+        return $factory->get($app);
1937
+    }
1938
+
1939
+    /**
1940
+     * @return \OCP\Lockdown\ILockdownManager
1941
+     */
1942
+    public function getLockdownManager() {
1943
+        return $this->query('LockdownManager');
1944
+    }
1945
+
1946
+    /**
1947
+     * @return \OCP\Federation\ICloudIdManager
1948
+     */
1949
+    public function getCloudIdManager() {
1950
+        return $this->query(ICloudIdManager::class);
1951
+    }
1952
+
1953
+    /**
1954
+     * @return \OCP\Remote\Api\IApiFactory
1955
+     */
1956
+    public function getRemoteApiFactory() {
1957
+        return $this->query(IApiFactory::class);
1958
+    }
1959
+
1960
+    /**
1961
+     * @return \OCP\Remote\IInstanceFactory
1962
+     */
1963
+    public function getRemoteInstanceFactory() {
1964
+        return $this->query(IInstanceFactory::class);
1965
+    }
1966 1966
 }
Please login to merge, or discard this patch.