Passed
Push — master ( 7e7284...62fa85 )
by Roeland
17:42 queued 12s
created
lib/public/Files/Template/ITemplateManager.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -33,62 +33,62 @@
 block discarded – undo
33 33
  */
34 34
 interface ITemplateManager {
35 35
 
36
-	/**
37
-	 * Register a template type support
38
-	 *
39
-	 * @param callable(): TemplateFileCreator $callback A callback which returns the TemplateFileCreator instance to register
40
-	 * @since 21.0.0
41
-	 */
42
-	public function registerTemplateFileCreator(callable $callback): void;
36
+    /**
37
+     * Register a template type support
38
+     *
39
+     * @param callable(): TemplateFileCreator $callback A callback which returns the TemplateFileCreator instance to register
40
+     * @since 21.0.0
41
+     */
42
+    public function registerTemplateFileCreator(callable $callback): void;
43 43
 
44
-	/**
45
-	 * Get a list of available file creators
46
-	 *
47
-	 * @return array
48
-	 * @since 21.0.0
49
-	 */
50
-	public function listCreators(): array;
44
+    /**
45
+     * Get a list of available file creators
46
+     *
47
+     * @return array
48
+     * @since 21.0.0
49
+     */
50
+    public function listCreators(): array;
51 51
 
52
-	/**
53
-	 * Get a list of available file creators and their offered templates
54
-	 *
55
-	 * @return array
56
-	 * @since 21.0.0
57
-	 */
58
-	public function listTemplates(): array;
52
+    /**
53
+     * Get a list of available file creators and their offered templates
54
+     *
55
+     * @return array
56
+     * @since 21.0.0
57
+     */
58
+    public function listTemplates(): array;
59 59
 
60
-	/**
61
-	 * @return bool
62
-	 * @since 21.0.0
63
-	 */
64
-	public function hasTemplateDirectory(): bool;
60
+    /**
61
+     * @return bool
62
+     * @since 21.0.0
63
+     */
64
+    public function hasTemplateDirectory(): bool;
65 65
 
66
-	/**
67
-	 * @param string $path
68
-	 * @return void
69
-	 * @since 21.0.0
70
-	 */
71
-	public function setTemplatePath(string $path): void;
66
+    /**
67
+     * @param string $path
68
+     * @return void
69
+     * @since 21.0.0
70
+     */
71
+    public function setTemplatePath(string $path): void;
72 72
 
73
-	/**
74
-	 * @return string
75
-	 * @since 21.0.0
76
-	 */
77
-	public function getTemplatePath(): string;
73
+    /**
74
+     * @return string
75
+     * @since 21.0.0
76
+     */
77
+    public function getTemplatePath(): string;
78 78
 
79
-	/**
80
-	 * @param string|null $path
81
-	 * @param string|null $userId
82
-	 * @since 21.0.0
83
-	 */
84
-	public function initializeTemplateDirectory(string $path = null, string $userId = null, $copyTemplates = true): string;
79
+    /**
80
+     * @param string|null $path
81
+     * @param string|null $userId
82
+     * @since 21.0.0
83
+     */
84
+    public function initializeTemplateDirectory(string $path = null, string $userId = null, $copyTemplates = true): string;
85 85
 
86
-	/**
87
-	 * @param string $filePath
88
-	 * @param string $templateId
89
-	 * @return array
90
-	 * @throws GenericFileException
91
-	 * @since 21.0.0
92
-	 */
93
-	public function createFromTemplate(string $filePath, string $templateId = '', string $templateType = 'user'): array;
86
+    /**
87
+     * @param string $filePath
88
+     * @param string $templateId
89
+     * @return array
90
+     * @throws GenericFileException
91
+     * @since 21.0.0
92
+     */
93
+    public function createFromTemplate(string $filePath, string $templateId = '', string $templateType = 'user'): array;
94 94
 }
Please login to merge, or discard this patch.
lib/public/Files/Template/Template.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -33,57 +33,57 @@
 block discarded – undo
33 33
  */
34 34
 final class Template implements \JsonSerializable {
35 35
 
36
-	/** @var string */
37
-	private $templateType;
38
-	/** @var string */
39
-	private $templateId;
40
-	/** @var File */
41
-	private $file;
42
-	/** @var bool */
43
-	private $hasPreview = false;
44
-	/** @var string|null */
45
-	private $previewUrl = null;
36
+    /** @var string */
37
+    private $templateType;
38
+    /** @var string */
39
+    private $templateId;
40
+    /** @var File */
41
+    private $file;
42
+    /** @var bool */
43
+    private $hasPreview = false;
44
+    /** @var string|null */
45
+    private $previewUrl = null;
46 46
 
47
-	/**
48
-	 * @since 21.0.0
49
-	 */
50
-	public function __construct(string $templateType, string $templateId, File $file) {
51
-		$this->templateType = $templateType;
52
-		$this->templateId = $templateId;
53
-		$this->file = $file;
54
-	}
47
+    /**
48
+     * @since 21.0.0
49
+     */
50
+    public function __construct(string $templateType, string $templateId, File $file) {
51
+        $this->templateType = $templateType;
52
+        $this->templateId = $templateId;
53
+        $this->file = $file;
54
+    }
55 55
 
56
-	/**
57
-	 * @since 21.0.0
58
-	 */
59
-	public function setCustomPreviewUrl(string $previewUrl): void {
60
-		$this->previewUrl = $previewUrl;
61
-	}
56
+    /**
57
+     * @since 21.0.0
58
+     */
59
+    public function setCustomPreviewUrl(string $previewUrl): void {
60
+        $this->previewUrl = $previewUrl;
61
+    }
62 62
 
63
-	/**
64
-	 * @since 21.0.0
65
-	 */
66
-	public function setHasPreview(bool $hasPreview): void {
67
-		$this->hasPreview = $hasPreview;
68
-	}
63
+    /**
64
+     * @since 21.0.0
65
+     */
66
+    public function setHasPreview(bool $hasPreview): void {
67
+        $this->hasPreview = $hasPreview;
68
+    }
69 69
 
70
-	/**
71
-	 * @since 21.0.0
72
-	 */
73
-	public function jsonSerialize() {
74
-		return [
75
-			'templateType' => $this->templateType,
76
-			'templateId' => $this->templateId,
77
-			'basename' => $this->file->getName(),
78
-			'etag' => $this->file->getEtag(),
79
-			'fileid' => $this->file->getId(),
80
-			'filename' => $this->templateId,
81
-			'lastmod' => $this->file->getMTime(),
82
-			'mime' => $this->file->getMimetype(),
83
-			'size' => $this->file->getSize(),
84
-			'type' => $this->file->getType(),
85
-			'hasPreview' => $this->hasPreview,
86
-			'previewUrl' => $this->previewUrl
87
-		];
88
-	}
70
+    /**
71
+     * @since 21.0.0
72
+     */
73
+    public function jsonSerialize() {
74
+        return [
75
+            'templateType' => $this->templateType,
76
+            'templateId' => $this->templateId,
77
+            'basename' => $this->file->getName(),
78
+            'etag' => $this->file->getEtag(),
79
+            'fileid' => $this->file->getId(),
80
+            'filename' => $this->templateId,
81
+            'lastmod' => $this->file->getMTime(),
82
+            'mime' => $this->file->getMimetype(),
83
+            'size' => $this->file->getSize(),
84
+            'type' => $this->file->getType(),
85
+            'hasPreview' => $this->hasPreview,
86
+            'previewUrl' => $this->previewUrl
87
+        ];
88
+    }
89 89
 }
Please login to merge, or discard this patch.
lib/public/Files/Template/FileCreatedFromTemplateEvent.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -33,32 +33,32 @@
 block discarded – undo
33 33
  * @since 21.0.0
34 34
  */
35 35
 class FileCreatedFromTemplateEvent extends Event {
36
-	private $template;
37
-	private $target;
36
+    private $template;
37
+    private $target;
38 38
 
39
-	/**
40
-	 * @param File|null $template
41
-	 * @param File $target
42
-	 * @since 21.0.0
43
-	 */
44
-	public function __construct(?File $template, File $target) {
45
-		$this->template = $template;
46
-		$this->target = $target;
47
-	}
39
+    /**
40
+     * @param File|null $template
41
+     * @param File $target
42
+     * @since 21.0.0
43
+     */
44
+    public function __construct(?File $template, File $target) {
45
+        $this->template = $template;
46
+        $this->target = $target;
47
+    }
48 48
 
49
-	/**
50
-	 * @return File|null
51
-	 * @since 21.0.0
52
-	 */
53
-	public function getTemplate(): ?File {
54
-		return $this->template;
55
-	}
49
+    /**
50
+     * @return File|null
51
+     * @since 21.0.0
52
+     */
53
+    public function getTemplate(): ?File {
54
+        return $this->template;
55
+    }
56 56
 
57
-	/**
58
-	 * @return File
59
-	 * @since 21.0.0
60
-	 */
61
-	public function getTarget(): File {
62
-		return $this->target;
63
-	}
57
+    /**
58
+     * @return File
59
+     * @since 21.0.0
60
+     */
61
+    public function getTarget(): File {
62
+        return $this->target;
63
+    }
64 64
 }
Please login to merge, or discard this patch.
lib/public/Files/Template/TemplateFileCreator.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -29,90 +29,90 @@
 block discarded – undo
29 29
  * @since 21.0.0
30 30
  */
31 31
 final class TemplateFileCreator implements \JsonSerializable {
32
-	protected $appId;
33
-	protected $mimetypes = [];
34
-	protected $actionName;
35
-	protected $fileExtension;
36
-	protected $iconClass;
37
-	protected $ratio = null;
38
-	protected $order = 100;
32
+    protected $appId;
33
+    protected $mimetypes = [];
34
+    protected $actionName;
35
+    protected $fileExtension;
36
+    protected $iconClass;
37
+    protected $ratio = null;
38
+    protected $order = 100;
39 39
 
40
-	/**
41
-	 * @since 21.0.0
42
-	 */
43
-	public function __construct(
44
-		string $appId, string $actionName, string $fileExtension
45
-	) {
46
-		$this->appId = $appId;
47
-		$this->actionName = $actionName;
48
-		$this->fileExtension = $fileExtension;
49
-	}
40
+    /**
41
+     * @since 21.0.0
42
+     */
43
+    public function __construct(
44
+        string $appId, string $actionName, string $fileExtension
45
+    ) {
46
+        $this->appId = $appId;
47
+        $this->actionName = $actionName;
48
+        $this->fileExtension = $fileExtension;
49
+    }
50 50
 
51
-	/**
52
-	 * @since 21.0.0
53
-	 */
54
-	public function getAppId(): string {
55
-		return $this->appId;
56
-	}
51
+    /**
52
+     * @since 21.0.0
53
+     */
54
+    public function getAppId(): string {
55
+        return $this->appId;
56
+    }
57 57
 
58
-	/**
59
-	 * @since 21.0.0
60
-	 */
61
-	public function setIconClass(string $iconClass): TemplateFileCreator {
62
-		$this->iconClass = $iconClass;
63
-		return $this;
64
-	}
58
+    /**
59
+     * @since 21.0.0
60
+     */
61
+    public function setIconClass(string $iconClass): TemplateFileCreator {
62
+        $this->iconClass = $iconClass;
63
+        return $this;
64
+    }
65 65
 
66
-	/**
67
-	 * @since 21.0.0
68
-	 */
69
-	public function addMimetype(string $mimetype): TemplateFileCreator {
70
-		$this->mimetypes[] = $mimetype;
71
-		return $this;
72
-	}
66
+    /**
67
+     * @since 21.0.0
68
+     */
69
+    public function addMimetype(string $mimetype): TemplateFileCreator {
70
+        $this->mimetypes[] = $mimetype;
71
+        return $this;
72
+    }
73 73
 
74
-	/**
75
-	 * @since 21.0.0
76
-	 */
77
-	public function getMimetypes(): array {
78
-		return $this->mimetypes;
79
-	}
74
+    /**
75
+     * @since 21.0.0
76
+     */
77
+    public function getMimetypes(): array {
78
+        return $this->mimetypes;
79
+    }
80 80
 
81
-	/**
82
-	 * @since 21.0.0
83
-	 */
84
-	public function setRatio(float $ratio): TemplateFileCreator {
85
-		$this->ratio = $ratio;
86
-		return $this;
87
-	}
81
+    /**
82
+     * @since 21.0.0
83
+     */
84
+    public function setRatio(float $ratio): TemplateFileCreator {
85
+        $this->ratio = $ratio;
86
+        return $this;
87
+    }
88 88
 
89
-	/**
90
-	 * @param int $order order in which the create action shall be listed
91
-	 * @since 21.0.0
92
-	 */
93
-	public function setOrder(int $order): TemplateFileCreator {
94
-		$this->order = $order;
95
-		return $this;
96
-	}
89
+    /**
90
+     * @param int $order order in which the create action shall be listed
91
+     * @since 21.0.0
92
+     */
93
+    public function setOrder(int $order): TemplateFileCreator {
94
+        $this->order = $order;
95
+        return $this;
96
+    }
97 97
 
98
-	/**
99
-	 * @since 21.0.0
100
-	 */
101
-	public function getOrder(): int {
102
-		return $this->order;
103
-	}
98
+    /**
99
+     * @since 21.0.0
100
+     */
101
+    public function getOrder(): int {
102
+        return $this->order;
103
+    }
104 104
 
105
-	/**
106
-	 * @since 21.0.0
107
-	 */
108
-	public function jsonSerialize() {
109
-		return [
110
-			'app' => $this->appId,
111
-			'label' => $this->actionName,
112
-			'extension' => $this->fileExtension,
113
-			'iconClass' => $this->iconClass,
114
-			'mimetypes' => $this->mimetypes,
115
-			'ratio' => $this->ratio
116
-		];
117
-	}
105
+    /**
106
+     * @since 21.0.0
107
+     */
108
+    public function jsonSerialize() {
109
+        return [
110
+            'app' => $this->appId,
111
+            'label' => $this->actionName,
112
+            'extension' => $this->fileExtension,
113
+            'iconClass' => $this->iconClass,
114
+            'mimetypes' => $this->mimetypes,
115
+            'ratio' => $this->ratio
116
+        ];
117
+    }
118 118
 }
Please login to merge, or discard this patch.
lib/public/Files/Template/ICustomTemplateProvider.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -32,20 +32,20 @@
 block discarded – undo
32 32
  * @since 21.0.0
33 33
  */
34 34
 interface ICustomTemplateProvider {
35
-	/**
36
-	 * Return a list of additional templates that the template provider is offering
37
-	 *
38
-	 * @return File[]
39
-	 * @since 21.0.0
40
-	 */
41
-	public function getCustomTemplates(string $mimetype): array;
35
+    /**
36
+     * Return a list of additional templates that the template provider is offering
37
+     *
38
+     * @return File[]
39
+     * @since 21.0.0
40
+     */
41
+    public function getCustomTemplates(string $mimetype): array;
42 42
 
43
-	/**
44
-	 * Return the file for a given template id
45
-	 *
46
-	 * @param string $template identifier of the template
47
-	 * @return File
48
-	 * @since 21.0.0
49
-	 */
50
-	public function getCustomTemplate(string $template): File;
43
+    /**
44
+     * Return the file for a given template id
45
+     *
46
+     * @param string $template identifier of the template
47
+     * @return File
48
+     * @since 21.0.0
49
+     */
50
+    public function getCustomTemplate(string $template): File;
51 51
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Bootstrap/IRegistrationContext.php 1 patch
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -42,169 +42,169 @@
 block discarded – undo
42 42
  */
43 43
 interface IRegistrationContext {
44 44
 
45
-	/**
46
-	 * @param string $capability
47
-	 * @see IAppContainer::registerCapability
48
-	 *
49
-	 * @since 20.0.0
50
-	 */
51
-	public function registerCapability(string $capability): void;
52
-
53
-	/**
54
-	 * Register an implementation of \OCP\Support\CrashReport\IReporter that
55
-	 * will receive unhandled exceptions and throwables
56
-	 *
57
-	 * @param string $reporterClass
58
-	 * @psalm-param class-string<\OCP\Support\CrashReport\IReporter> $reporterClass
59
-	 * @return void
60
-	 * @since 20.0.0
61
-	 */
62
-	public function registerCrashReporter(string $reporterClass): void;
63
-
64
-	/**
65
-	 * Register an implementation of \OCP\Dashboard\IWidget that
66
-	 * will handle the implementation of a dashboard widget
67
-	 *
68
-	 * @param string $widgetClass
69
-	 * @psalm-param class-string<\OCP\Dashboard\IWidget> $widgetClass
70
-	 * @return void
71
-	 * @since 20.0.0
72
-	 */
73
-	public function registerDashboardWidget(string $widgetClass): void;
74
-	/**
75
-	 * Register a service
76
-	 *
77
-	 * @param string $name
78
-	 * @param callable $factory
79
-	 * @psalm-param callable(\Psr\Container\ContainerInterface): mixed $factory
80
-	 * @param bool $shared
81
-	 *
82
-	 * @return void
83
-	 * @see IContainer::registerService()
84
-	 *
85
-	 * @since 20.0.0
86
-	 */
87
-	public function registerService(string $name, callable $factory, bool $shared = true): void;
88
-
89
-	/**
90
-	 * @param string $alias
91
-	 * @psalm-param string|class-string $alias
92
-	 * @param string $target
93
-	 * @psalm-param string|class-string $target
94
-	 *
95
-	 * @return void
96
-	 * @see IContainer::registerAlias()
97
-	 *
98
-	 * @since 20.0.0
99
-	 */
100
-	public function registerServiceAlias(string $alias, string $target): void;
101
-
102
-	/**
103
-	 * @param string $name
104
-	 * @param mixed $value
105
-	 *
106
-	 * @return void
107
-	 * @see IContainer::registerParameter()
108
-	 *
109
-	 * @since 20.0.0
110
-	 */
111
-	public function registerParameter(string $name, $value): void;
112
-
113
-	/**
114
-	 * Register a service listener
115
-	 *
116
-	 * This is equivalent to calling IEventDispatcher::addServiceListener
117
-	 *
118
-	 * @template T of \OCP\EventDispatcher\Event
119
-	 * @param string $event preferably the fully-qualified class name of the Event sub class to listen for
120
-	 * @psalm-param string|class-string<T> $event preferably the fully-qualified class name of the Event sub class to listen for
121
-	 * @param string $listener fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container
122
-	 * @psalm-param class-string<\OCP\EventDispatcher\IEventListener<T>> $listener fully qualified class name that can be built by the DI container
123
-	 * @param int $priority The higher this value, the earlier an event
124
-	 *                      listener will be triggered in the chain (defaults to 0)
125
-	 *
126
-	 * @see IEventDispatcher::addServiceListener()
127
-	 *
128
-	 * @since 20.0.0
129
-	 */
130
-	public function registerEventListener(string $event, string $listener, int $priority = 0): void;
131
-
132
-	/**
133
-	 * @param string $class
134
-	 * @psalm-param class-string<\OCP\AppFramework\Middleware> $class
135
-	 *
136
-	 * @return void
137
-	 * @see IAppContainer::registerMiddleWare()
138
-	 *
139
-	 * @since 20.0.0
140
-	 */
141
-	public function registerMiddleware(string $class): void;
142
-
143
-	/**
144
-	 * Register a search provider for the unified search
145
-	 *
146
-	 * It is allowed to register more than one provider per app as the search
147
-	 * results can go into distinct sections, e.g. "Files" and "Files shared
148
-	 * with you" in the Files app.
149
-	 *
150
-	 * @param string $class
151
-	 * @psalm-param class-string<\OCP\Search\IProvider> $class
152
-	 *
153
-	 * @return void
154
-	 *
155
-	 * @since 20.0.0
156
-	 */
157
-	public function registerSearchProvider(string $class): void;
158
-
159
-	/**
160
-	 * Register an alternative login option
161
-	 *
162
-	 * It is allowed to register more than one option per app.
163
-	 *
164
-	 * @param string $class
165
-	 * @psalm-param class-string<\OCP\Authentication\IAlternativeLogin> $class
166
-	 *
167
-	 * @return void
168
-	 *
169
-	 * @since 20.0.0
170
-	 */
171
-	public function registerAlternativeLogin(string $class): void;
172
-
173
-	/**
174
-	 * Register an initialstate provider
175
-	 *
176
-	 * It is allowed to register more than one provider per app.
177
-	 *
178
-	 * @param string $class
179
-	 * @psalm-param class-string<\OCP\AppFramework\Services\InitialStateProvider> $class
180
-	 *
181
-	 * @return void
182
-	 *
183
-	 * @since 21.0.0
184
-	 */
185
-	public function registerInitialStateProvider(string $class): void;
186
-
187
-	/**
188
-	 * Register a well known protocol handler
189
-	 *
190
-	 * It is allowed to register more than one handler per app.
191
-	 *
192
-	 * @param string $class
193
-	 * @psalm-param class-string<\OCP\Http\WellKnown\IHandler> $class
194
-	 *
195
-	 * @return void
196
-	 *
197
-	 * @since 21.0.0
198
-	 */
199
-	public function registerWellKnownHandler(string $class): void;
200
-
201
-	/**
202
-	 * Register a custom template provider class that is able to inject custom templates
203
-	 * in addition to the user defined ones
204
-	 *
205
-	 * @param string $providerClass
206
-	 * @psalm-param class-string<ICustomTemplateProvider> $providerClass
207
-	 * @since 21.0.0
208
-	 */
209
-	public function registerTemplateProvider(string $providerClass): void;
45
+    /**
46
+     * @param string $capability
47
+     * @see IAppContainer::registerCapability
48
+     *
49
+     * @since 20.0.0
50
+     */
51
+    public function registerCapability(string $capability): void;
52
+
53
+    /**
54
+     * Register an implementation of \OCP\Support\CrashReport\IReporter that
55
+     * will receive unhandled exceptions and throwables
56
+     *
57
+     * @param string $reporterClass
58
+     * @psalm-param class-string<\OCP\Support\CrashReport\IReporter> $reporterClass
59
+     * @return void
60
+     * @since 20.0.0
61
+     */
62
+    public function registerCrashReporter(string $reporterClass): void;
63
+
64
+    /**
65
+     * Register an implementation of \OCP\Dashboard\IWidget that
66
+     * will handle the implementation of a dashboard widget
67
+     *
68
+     * @param string $widgetClass
69
+     * @psalm-param class-string<\OCP\Dashboard\IWidget> $widgetClass
70
+     * @return void
71
+     * @since 20.0.0
72
+     */
73
+    public function registerDashboardWidget(string $widgetClass): void;
74
+    /**
75
+     * Register a service
76
+     *
77
+     * @param string $name
78
+     * @param callable $factory
79
+     * @psalm-param callable(\Psr\Container\ContainerInterface): mixed $factory
80
+     * @param bool $shared
81
+     *
82
+     * @return void
83
+     * @see IContainer::registerService()
84
+     *
85
+     * @since 20.0.0
86
+     */
87
+    public function registerService(string $name, callable $factory, bool $shared = true): void;
88
+
89
+    /**
90
+     * @param string $alias
91
+     * @psalm-param string|class-string $alias
92
+     * @param string $target
93
+     * @psalm-param string|class-string $target
94
+     *
95
+     * @return void
96
+     * @see IContainer::registerAlias()
97
+     *
98
+     * @since 20.0.0
99
+     */
100
+    public function registerServiceAlias(string $alias, string $target): void;
101
+
102
+    /**
103
+     * @param string $name
104
+     * @param mixed $value
105
+     *
106
+     * @return void
107
+     * @see IContainer::registerParameter()
108
+     *
109
+     * @since 20.0.0
110
+     */
111
+    public function registerParameter(string $name, $value): void;
112
+
113
+    /**
114
+     * Register a service listener
115
+     *
116
+     * This is equivalent to calling IEventDispatcher::addServiceListener
117
+     *
118
+     * @template T of \OCP\EventDispatcher\Event
119
+     * @param string $event preferably the fully-qualified class name of the Event sub class to listen for
120
+     * @psalm-param string|class-string<T> $event preferably the fully-qualified class name of the Event sub class to listen for
121
+     * @param string $listener fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container
122
+     * @psalm-param class-string<\OCP\EventDispatcher\IEventListener<T>> $listener fully qualified class name that can be built by the DI container
123
+     * @param int $priority The higher this value, the earlier an event
124
+     *                      listener will be triggered in the chain (defaults to 0)
125
+     *
126
+     * @see IEventDispatcher::addServiceListener()
127
+     *
128
+     * @since 20.0.0
129
+     */
130
+    public function registerEventListener(string $event, string $listener, int $priority = 0): void;
131
+
132
+    /**
133
+     * @param string $class
134
+     * @psalm-param class-string<\OCP\AppFramework\Middleware> $class
135
+     *
136
+     * @return void
137
+     * @see IAppContainer::registerMiddleWare()
138
+     *
139
+     * @since 20.0.0
140
+     */
141
+    public function registerMiddleware(string $class): void;
142
+
143
+    /**
144
+     * Register a search provider for the unified search
145
+     *
146
+     * It is allowed to register more than one provider per app as the search
147
+     * results can go into distinct sections, e.g. "Files" and "Files shared
148
+     * with you" in the Files app.
149
+     *
150
+     * @param string $class
151
+     * @psalm-param class-string<\OCP\Search\IProvider> $class
152
+     *
153
+     * @return void
154
+     *
155
+     * @since 20.0.0
156
+     */
157
+    public function registerSearchProvider(string $class): void;
158
+
159
+    /**
160
+     * Register an alternative login option
161
+     *
162
+     * It is allowed to register more than one option per app.
163
+     *
164
+     * @param string $class
165
+     * @psalm-param class-string<\OCP\Authentication\IAlternativeLogin> $class
166
+     *
167
+     * @return void
168
+     *
169
+     * @since 20.0.0
170
+     */
171
+    public function registerAlternativeLogin(string $class): void;
172
+
173
+    /**
174
+     * Register an initialstate provider
175
+     *
176
+     * It is allowed to register more than one provider per app.
177
+     *
178
+     * @param string $class
179
+     * @psalm-param class-string<\OCP\AppFramework\Services\InitialStateProvider> $class
180
+     *
181
+     * @return void
182
+     *
183
+     * @since 21.0.0
184
+     */
185
+    public function registerInitialStateProvider(string $class): void;
186
+
187
+    /**
188
+     * Register a well known protocol handler
189
+     *
190
+     * It is allowed to register more than one handler per app.
191
+     *
192
+     * @param string $class
193
+     * @psalm-param class-string<\OCP\Http\WellKnown\IHandler> $class
194
+     *
195
+     * @return void
196
+     *
197
+     * @since 21.0.0
198
+     */
199
+    public function registerWellKnownHandler(string $class): void;
200
+
201
+    /**
202
+     * Register a custom template provider class that is able to inject custom templates
203
+     * in addition to the user defined ones
204
+     *
205
+     * @param string $providerClass
206
+     * @psalm-param class-string<ICustomTemplateProvider> $providerClass
207
+     * @since 21.0.0
208
+     */
209
+    public function registerTemplateProvider(string $providerClass): void;
210 210
 }
Please login to merge, or discard this patch.
lib/private/Files/Template/TemplateManager.php 2 patches
Indentation   +294 added lines, -294 removed lines patch added patch discarded remove patch
@@ -49,298 +49,298 @@
 block discarded – undo
49 49
 use Psr\Log\LoggerInterface;
50 50
 
51 51
 class TemplateManager implements ITemplateManager {
52
-	private $registeredTypes = [];
53
-	private $types = [];
54
-
55
-	/** @var array|null */
56
-	private $providers = null;
57
-
58
-	private $serverContainer;
59
-	private $eventDispatcher;
60
-	private $rootFolder;
61
-	private $previewManager;
62
-	private $config;
63
-	private $l10n;
64
-	private $logger;
65
-	private $userId;
66
-	private $l10nFactory;
67
-	/** @var Coordinator */
68
-	private $bootstrapCoordinator;
69
-
70
-	public function __construct(
71
-		IServerContainer $serverContainer,
72
-		IEventDispatcher $eventDispatcher,
73
-		Coordinator $coordinator,
74
-		IRootFolder $rootFolder,
75
-		IUserSession $userSession,
76
-		IPreview $previewManager,
77
-		IConfig $config,
78
-		IFactory $l10nFactory,
79
-		LoggerInterface $logger
80
-	) {
81
-		$this->serverContainer = $serverContainer;
82
-		$this->eventDispatcher = $eventDispatcher;
83
-		$this->bootstrapCoordinator = $coordinator;
84
-		$this->rootFolder = $rootFolder;
85
-		$this->previewManager = $previewManager;
86
-		$this->config = $config;
87
-		$this->l10nFactory = $l10nFactory;
88
-		$this->l10n = $l10nFactory->get('lib');
89
-		$this->logger = $logger;
90
-		$user = $userSession->getUser();
91
-		$this->userId = $user ? $user->getUID() : null;
92
-	}
93
-
94
-	public function registerTemplateFileCreator(callable $callback): void {
95
-		$this->registeredTypes[] = $callback;
96
-	}
97
-
98
-	public function getRegisteredProviders(): array {
99
-		if ($this->providers !== null) {
100
-			return $this->providers;
101
-		}
102
-
103
-		$context = $this->bootstrapCoordinator->getRegistrationContext();
104
-
105
-		$this->providers = [];
106
-		foreach ($context->getTemplateProviders() as $provider) {
107
-			$this->providers[$provider['class']] = $this->serverContainer->get($provider['class']);
108
-		}
109
-		return $this->providers;
110
-	}
111
-
112
-	public function getTypes(): array {
113
-		foreach ($this->registeredTypes as $registeredType) {
114
-			$this->types[] = $registeredType();
115
-		}
116
-		return $this->types;
117
-	}
118
-
119
-	public function listCreators(): array {
120
-		$types = $this->getTypes();
121
-		usort($types, function (TemplateFileCreator $a, TemplateFileCreator $b) {
122
-			return $a->getOrder() - $b->getOrder();
123
-		});
124
-		return $types;
125
-	}
126
-
127
-	public function listTemplates(): array {
128
-		return array_map(function (TemplateFileCreator $entry) {
129
-			return array_merge($entry->jsonSerialize(), [
130
-				'templates' => $this->getTemplateFiles($entry)
131
-			]);
132
-		}, $this->listCreators());
133
-	}
134
-
135
-	/**
136
-	 * @param string $filePath
137
-	 * @param string $templateId
138
-	 * @return array
139
-	 * @throws GenericFileException
140
-	 */
141
-	public function createFromTemplate(string $filePath, string $templateId = '', string $templateType = 'user'): array {
142
-		$userFolder = $this->rootFolder->getUserFolder($this->userId);
143
-		try {
144
-			$userFolder->get($filePath);
145
-			throw new GenericFileException($this->l10n->t('File already exists'));
146
-		} catch (NotFoundException $e) {
147
-		}
148
-		try {
149
-			$targetFile = $userFolder->newFile($filePath);
150
-			if ($templateType === 'user' && $templateId !== '') {
151
-				$template = $userFolder->get($templateId);
152
-				$template->copy($targetFile->getPath());
153
-			} else {
154
-				$matchingProvider = array_filter($this->getRegisteredProviders(), function (ICustomTemplateProvider $provider) use ($templateType) {
155
-					return $templateType === get_class($provider);
156
-				});
157
-				$provider = array_shift($matchingProvider);
158
-				if ($provider) {
159
-					$template = $provider->getCustomTemplate($templateId);
160
-					$template->copy($targetFile->getPath());
161
-				}
162
-			}
163
-			$this->eventDispatcher->dispatchTyped(new FileCreatedFromTemplateEvent($template, $targetFile));
164
-			return $this->formatFile($userFolder->get($filePath));
165
-		} catch (\Exception $e) {
166
-			$this->logger->error($e->getMessage(), ['exception' => $e]);
167
-			throw new GenericFileException($this->l10n->t('Failed to create file from template'));
168
-		}
169
-	}
170
-
171
-	/**
172
-	 * @return Folder
173
-	 * @throws \OCP\Files\NotFoundException
174
-	 * @throws \OCP\Files\NotPermittedException
175
-	 * @throws \OC\User\NoUserException
176
-	 */
177
-	private function getTemplateFolder(): Node {
178
-		if ($this->getTemplatePath() !== '') {
179
-			return $this->rootFolder->getUserFolder($this->userId)->get($this->getTemplatePath());
180
-		}
181
-		throw new NotFoundException();
182
-	}
183
-
184
-	private function getTemplateFiles(TemplateFileCreator $type): array {
185
-		$templates = [];
186
-		foreach ($this->getRegisteredProviders() as $provider) {
187
-			foreach ($type->getMimetypes() as $mimetype) {
188
-				foreach ($provider->getCustomTemplates($mimetype) as $template) {
189
-					$templates[] = $template;
190
-				}
191
-			}
192
-		}
193
-		try {
194
-			$userTemplateFolder = $this->getTemplateFolder();
195
-		} catch (\Exception $e) {
196
-			return $templates;
197
-		}
198
-		foreach ($type->getMimetypes() as $mimetype) {
199
-			foreach ($userTemplateFolder->searchByMime($mimetype) as $templateFile) {
200
-				$template = new Template(
201
-					'user',
202
-					$this->rootFolder->getUserFolder($this->userId)->getRelativePath($templateFile->getPath()),
203
-					$templateFile
204
-				);
205
-				$template->setHasPreview($this->previewManager->isAvailable($templateFile));
206
-				$templates[] = $template;
207
-			}
208
-		}
209
-
210
-		return $templates;
211
-	}
212
-
213
-	/**
214
-	 * @param Node|File $file
215
-	 * @return array
216
-	 * @throws NotFoundException
217
-	 * @throws \OCP\Files\InvalidPathException
218
-	 */
219
-	private function formatFile(Node $file): array {
220
-		return [
221
-			'basename' => $file->getName(),
222
-			'etag' => $file->getEtag(),
223
-			'fileid' => $file->getId(),
224
-			'filename' => $this->rootFolder->getUserFolder($this->userId)->getRelativePath($file->getPath()),
225
-			'lastmod' => $file->getMTime(),
226
-			'mime' => $file->getMimetype(),
227
-			'size' => $file->getSize(),
228
-			'type' => $file->getType(),
229
-			'hasPreview' => $this->previewManager->isAvailable($file)
230
-		];
231
-	}
232
-
233
-	public function hasTemplateDirectory(): bool {
234
-		try {
235
-			$this->getTemplateFolder();
236
-			return true;
237
-		} catch (\Exception $e) {
238
-		}
239
-		return false;
240
-	}
241
-
242
-	public function setTemplatePath(string $path): void {
243
-		$this->config->setUserValue($this->userId, 'core', 'templateDirectory', $path);
244
-	}
245
-
246
-	public function getTemplatePath(): string {
247
-		return $this->config->getUserValue($this->userId, 'core', 'templateDirectory', '');
248
-	}
249
-
250
-	public function initializeTemplateDirectory(string $path = null, string $userId = null, $copyTemplates = true): string {
251
-		if ($userId !== null) {
252
-			$this->userId = $userId;
253
-		}
254
-
255
-		$defaultSkeletonDirectory = \OC::$SERVERROOT . '/core/skeleton';
256
-		$defaultTemplateDirectory = \OC::$SERVERROOT . '/core/skeleton/Templates';
257
-		$skeletonPath = $this->config->getSystemValue('skeletondirectory', $defaultSkeletonDirectory);
258
-		$skeletonTemplatePath = $this->config->getSystemValue('templatedirectory', $defaultTemplateDirectory);
259
-		$isDefaultSkeleton = $skeletonPath === $defaultSkeletonDirectory;
260
-		$isDefaultTemplates = $skeletonTemplatePath === $defaultTemplateDirectory;
261
-		$userLang = $this->l10nFactory->getUserLanguage();
262
-
263
-		try {
264
-			$l10n = $this->l10nFactory->get('lib', $userLang);
265
-			$userFolder = $this->rootFolder->getUserFolder($this->userId);
266
-			$userTemplatePath = $path ?? $l10n->t('Templates') . '/';
267
-
268
-			// Initial user setup without a provided path
269
-			if ($path === null) {
270
-				// All locations are default so we just need to rename the directory to the users language
271
-				if ($isDefaultSkeleton && $isDefaultTemplates) {
272
-					if (!$userFolder->nodeExists('Templates')) {
273
-						return '';
274
-					}
275
-					$newPath = $userFolder->getPath() . '/' . $userTemplatePath;
276
-					if ($newPath !== $userFolder->get('Templates')->getPath()) {
277
-						$userFolder->get('Templates')->move($newPath);
278
-					}
279
-					$this->setTemplatePath($userTemplatePath);
280
-					return $userTemplatePath;
281
-				}
282
-
283
-				if ($isDefaultSkeleton && !empty($skeletonTemplatePath) && !$isDefaultTemplates && $userFolder->nodeExists('Templates')) {
284
-					$shippedSkeletonTemplates = $userFolder->get('Templates');
285
-					$shippedSkeletonTemplates->delete();
286
-				}
287
-			}
288
-
289
-			try {
290
-				$folder = $userFolder->newFolder($userTemplatePath);
291
-			} catch (NotPermittedException $e) {
292
-				$folder = $userFolder->get($userTemplatePath);
293
-			}
294
-
295
-			$folderIsEmpty = count($folder->getDirectoryListing()) === 0;
296
-
297
-			if (!$copyTemplates) {
298
-				$this->setTemplatePath($userTemplatePath);
299
-				return $userTemplatePath;
300
-			}
301
-
302
-			if (!$isDefaultTemplates && $folderIsEmpty) {
303
-				$localizedSkeletonTemplatePath = $this->getLocalizedTemplatePath($skeletonTemplatePath, $userLang);
304
-				if (!empty($localizedSkeletonTemplatePath) && file_exists($localizedSkeletonTemplatePath)) {
305
-					\OC_Util::copyr($localizedSkeletonTemplatePath, $folder);
306
-					$userFolder->getStorage()->getScanner()->scan($userTemplatePath, Scanner::SCAN_RECURSIVE);
307
-					$this->setTemplatePath($userTemplatePath);
308
-					return $userTemplatePath;
309
-				}
310
-			}
311
-
312
-			if ($path !== null && $isDefaultSkeleton && $isDefaultTemplates && $folderIsEmpty) {
313
-				$localizedSkeletonPath = $this->getLocalizedTemplatePath($skeletonPath . '/Templates', $userLang);
314
-				if (!empty($localizedSkeletonPath) && file_exists($localizedSkeletonPath)) {
315
-					\OC_Util::copyr($localizedSkeletonPath, $folder);
316
-					$userFolder->getStorage()->getScanner()->scan($userTemplatePath, Scanner::SCAN_RECURSIVE);
317
-					$this->setTemplatePath($userTemplatePath);
318
-					return $userTemplatePath;
319
-				}
320
-			}
321
-
322
-			$this->setTemplatePath($path ?? '');
323
-			return $this->getTemplatePath();
324
-		} catch (\Throwable $e) {
325
-			$this->logger->error('Failed to initialize templates directory to user language ' . $userLang . ' for ' . $userId, ['app' => 'files_templates', 'exception' => $e]);
326
-		}
327
-		$this->setTemplatePath('');
328
-		return $this->getTemplatePath();
329
-	}
330
-
331
-	private function getLocalizedTemplatePath(string $skeletonTemplatePath, string $userLang) {
332
-		$localizedSkeletonTemplatePath = str_replace('{lang}', $userLang, $skeletonTemplatePath);
333
-
334
-		if (!file_exists($localizedSkeletonTemplatePath)) {
335
-			$dialectStart = strpos($userLang, '_');
336
-			if ($dialectStart !== false) {
337
-				$localizedSkeletonTemplatePath = str_replace('{lang}', substr($userLang, 0, $dialectStart), $skeletonTemplatePath);
338
-			}
339
-			if ($dialectStart === false || !file_exists($localizedSkeletonTemplatePath)) {
340
-				$localizedSkeletonTemplatePath = str_replace('{lang}', 'default', $skeletonTemplatePath);
341
-			}
342
-		}
343
-
344
-		return $localizedSkeletonTemplatePath;
345
-	}
52
+    private $registeredTypes = [];
53
+    private $types = [];
54
+
55
+    /** @var array|null */
56
+    private $providers = null;
57
+
58
+    private $serverContainer;
59
+    private $eventDispatcher;
60
+    private $rootFolder;
61
+    private $previewManager;
62
+    private $config;
63
+    private $l10n;
64
+    private $logger;
65
+    private $userId;
66
+    private $l10nFactory;
67
+    /** @var Coordinator */
68
+    private $bootstrapCoordinator;
69
+
70
+    public function __construct(
71
+        IServerContainer $serverContainer,
72
+        IEventDispatcher $eventDispatcher,
73
+        Coordinator $coordinator,
74
+        IRootFolder $rootFolder,
75
+        IUserSession $userSession,
76
+        IPreview $previewManager,
77
+        IConfig $config,
78
+        IFactory $l10nFactory,
79
+        LoggerInterface $logger
80
+    ) {
81
+        $this->serverContainer = $serverContainer;
82
+        $this->eventDispatcher = $eventDispatcher;
83
+        $this->bootstrapCoordinator = $coordinator;
84
+        $this->rootFolder = $rootFolder;
85
+        $this->previewManager = $previewManager;
86
+        $this->config = $config;
87
+        $this->l10nFactory = $l10nFactory;
88
+        $this->l10n = $l10nFactory->get('lib');
89
+        $this->logger = $logger;
90
+        $user = $userSession->getUser();
91
+        $this->userId = $user ? $user->getUID() : null;
92
+    }
93
+
94
+    public function registerTemplateFileCreator(callable $callback): void {
95
+        $this->registeredTypes[] = $callback;
96
+    }
97
+
98
+    public function getRegisteredProviders(): array {
99
+        if ($this->providers !== null) {
100
+            return $this->providers;
101
+        }
102
+
103
+        $context = $this->bootstrapCoordinator->getRegistrationContext();
104
+
105
+        $this->providers = [];
106
+        foreach ($context->getTemplateProviders() as $provider) {
107
+            $this->providers[$provider['class']] = $this->serverContainer->get($provider['class']);
108
+        }
109
+        return $this->providers;
110
+    }
111
+
112
+    public function getTypes(): array {
113
+        foreach ($this->registeredTypes as $registeredType) {
114
+            $this->types[] = $registeredType();
115
+        }
116
+        return $this->types;
117
+    }
118
+
119
+    public function listCreators(): array {
120
+        $types = $this->getTypes();
121
+        usort($types, function (TemplateFileCreator $a, TemplateFileCreator $b) {
122
+            return $a->getOrder() - $b->getOrder();
123
+        });
124
+        return $types;
125
+    }
126
+
127
+    public function listTemplates(): array {
128
+        return array_map(function (TemplateFileCreator $entry) {
129
+            return array_merge($entry->jsonSerialize(), [
130
+                'templates' => $this->getTemplateFiles($entry)
131
+            ]);
132
+        }, $this->listCreators());
133
+    }
134
+
135
+    /**
136
+     * @param string $filePath
137
+     * @param string $templateId
138
+     * @return array
139
+     * @throws GenericFileException
140
+     */
141
+    public function createFromTemplate(string $filePath, string $templateId = '', string $templateType = 'user'): array {
142
+        $userFolder = $this->rootFolder->getUserFolder($this->userId);
143
+        try {
144
+            $userFolder->get($filePath);
145
+            throw new GenericFileException($this->l10n->t('File already exists'));
146
+        } catch (NotFoundException $e) {
147
+        }
148
+        try {
149
+            $targetFile = $userFolder->newFile($filePath);
150
+            if ($templateType === 'user' && $templateId !== '') {
151
+                $template = $userFolder->get($templateId);
152
+                $template->copy($targetFile->getPath());
153
+            } else {
154
+                $matchingProvider = array_filter($this->getRegisteredProviders(), function (ICustomTemplateProvider $provider) use ($templateType) {
155
+                    return $templateType === get_class($provider);
156
+                });
157
+                $provider = array_shift($matchingProvider);
158
+                if ($provider) {
159
+                    $template = $provider->getCustomTemplate($templateId);
160
+                    $template->copy($targetFile->getPath());
161
+                }
162
+            }
163
+            $this->eventDispatcher->dispatchTyped(new FileCreatedFromTemplateEvent($template, $targetFile));
164
+            return $this->formatFile($userFolder->get($filePath));
165
+        } catch (\Exception $e) {
166
+            $this->logger->error($e->getMessage(), ['exception' => $e]);
167
+            throw new GenericFileException($this->l10n->t('Failed to create file from template'));
168
+        }
169
+    }
170
+
171
+    /**
172
+     * @return Folder
173
+     * @throws \OCP\Files\NotFoundException
174
+     * @throws \OCP\Files\NotPermittedException
175
+     * @throws \OC\User\NoUserException
176
+     */
177
+    private function getTemplateFolder(): Node {
178
+        if ($this->getTemplatePath() !== '') {
179
+            return $this->rootFolder->getUserFolder($this->userId)->get($this->getTemplatePath());
180
+        }
181
+        throw new NotFoundException();
182
+    }
183
+
184
+    private function getTemplateFiles(TemplateFileCreator $type): array {
185
+        $templates = [];
186
+        foreach ($this->getRegisteredProviders() as $provider) {
187
+            foreach ($type->getMimetypes() as $mimetype) {
188
+                foreach ($provider->getCustomTemplates($mimetype) as $template) {
189
+                    $templates[] = $template;
190
+                }
191
+            }
192
+        }
193
+        try {
194
+            $userTemplateFolder = $this->getTemplateFolder();
195
+        } catch (\Exception $e) {
196
+            return $templates;
197
+        }
198
+        foreach ($type->getMimetypes() as $mimetype) {
199
+            foreach ($userTemplateFolder->searchByMime($mimetype) as $templateFile) {
200
+                $template = new Template(
201
+                    'user',
202
+                    $this->rootFolder->getUserFolder($this->userId)->getRelativePath($templateFile->getPath()),
203
+                    $templateFile
204
+                );
205
+                $template->setHasPreview($this->previewManager->isAvailable($templateFile));
206
+                $templates[] = $template;
207
+            }
208
+        }
209
+
210
+        return $templates;
211
+    }
212
+
213
+    /**
214
+     * @param Node|File $file
215
+     * @return array
216
+     * @throws NotFoundException
217
+     * @throws \OCP\Files\InvalidPathException
218
+     */
219
+    private function formatFile(Node $file): array {
220
+        return [
221
+            'basename' => $file->getName(),
222
+            'etag' => $file->getEtag(),
223
+            'fileid' => $file->getId(),
224
+            'filename' => $this->rootFolder->getUserFolder($this->userId)->getRelativePath($file->getPath()),
225
+            'lastmod' => $file->getMTime(),
226
+            'mime' => $file->getMimetype(),
227
+            'size' => $file->getSize(),
228
+            'type' => $file->getType(),
229
+            'hasPreview' => $this->previewManager->isAvailable($file)
230
+        ];
231
+    }
232
+
233
+    public function hasTemplateDirectory(): bool {
234
+        try {
235
+            $this->getTemplateFolder();
236
+            return true;
237
+        } catch (\Exception $e) {
238
+        }
239
+        return false;
240
+    }
241
+
242
+    public function setTemplatePath(string $path): void {
243
+        $this->config->setUserValue($this->userId, 'core', 'templateDirectory', $path);
244
+    }
245
+
246
+    public function getTemplatePath(): string {
247
+        return $this->config->getUserValue($this->userId, 'core', 'templateDirectory', '');
248
+    }
249
+
250
+    public function initializeTemplateDirectory(string $path = null, string $userId = null, $copyTemplates = true): string {
251
+        if ($userId !== null) {
252
+            $this->userId = $userId;
253
+        }
254
+
255
+        $defaultSkeletonDirectory = \OC::$SERVERROOT . '/core/skeleton';
256
+        $defaultTemplateDirectory = \OC::$SERVERROOT . '/core/skeleton/Templates';
257
+        $skeletonPath = $this->config->getSystemValue('skeletondirectory', $defaultSkeletonDirectory);
258
+        $skeletonTemplatePath = $this->config->getSystemValue('templatedirectory', $defaultTemplateDirectory);
259
+        $isDefaultSkeleton = $skeletonPath === $defaultSkeletonDirectory;
260
+        $isDefaultTemplates = $skeletonTemplatePath === $defaultTemplateDirectory;
261
+        $userLang = $this->l10nFactory->getUserLanguage();
262
+
263
+        try {
264
+            $l10n = $this->l10nFactory->get('lib', $userLang);
265
+            $userFolder = $this->rootFolder->getUserFolder($this->userId);
266
+            $userTemplatePath = $path ?? $l10n->t('Templates') . '/';
267
+
268
+            // Initial user setup without a provided path
269
+            if ($path === null) {
270
+                // All locations are default so we just need to rename the directory to the users language
271
+                if ($isDefaultSkeleton && $isDefaultTemplates) {
272
+                    if (!$userFolder->nodeExists('Templates')) {
273
+                        return '';
274
+                    }
275
+                    $newPath = $userFolder->getPath() . '/' . $userTemplatePath;
276
+                    if ($newPath !== $userFolder->get('Templates')->getPath()) {
277
+                        $userFolder->get('Templates')->move($newPath);
278
+                    }
279
+                    $this->setTemplatePath($userTemplatePath);
280
+                    return $userTemplatePath;
281
+                }
282
+
283
+                if ($isDefaultSkeleton && !empty($skeletonTemplatePath) && !$isDefaultTemplates && $userFolder->nodeExists('Templates')) {
284
+                    $shippedSkeletonTemplates = $userFolder->get('Templates');
285
+                    $shippedSkeletonTemplates->delete();
286
+                }
287
+            }
288
+
289
+            try {
290
+                $folder = $userFolder->newFolder($userTemplatePath);
291
+            } catch (NotPermittedException $e) {
292
+                $folder = $userFolder->get($userTemplatePath);
293
+            }
294
+
295
+            $folderIsEmpty = count($folder->getDirectoryListing()) === 0;
296
+
297
+            if (!$copyTemplates) {
298
+                $this->setTemplatePath($userTemplatePath);
299
+                return $userTemplatePath;
300
+            }
301
+
302
+            if (!$isDefaultTemplates && $folderIsEmpty) {
303
+                $localizedSkeletonTemplatePath = $this->getLocalizedTemplatePath($skeletonTemplatePath, $userLang);
304
+                if (!empty($localizedSkeletonTemplatePath) && file_exists($localizedSkeletonTemplatePath)) {
305
+                    \OC_Util::copyr($localizedSkeletonTemplatePath, $folder);
306
+                    $userFolder->getStorage()->getScanner()->scan($userTemplatePath, Scanner::SCAN_RECURSIVE);
307
+                    $this->setTemplatePath($userTemplatePath);
308
+                    return $userTemplatePath;
309
+                }
310
+            }
311
+
312
+            if ($path !== null && $isDefaultSkeleton && $isDefaultTemplates && $folderIsEmpty) {
313
+                $localizedSkeletonPath = $this->getLocalizedTemplatePath($skeletonPath . '/Templates', $userLang);
314
+                if (!empty($localizedSkeletonPath) && file_exists($localizedSkeletonPath)) {
315
+                    \OC_Util::copyr($localizedSkeletonPath, $folder);
316
+                    $userFolder->getStorage()->getScanner()->scan($userTemplatePath, Scanner::SCAN_RECURSIVE);
317
+                    $this->setTemplatePath($userTemplatePath);
318
+                    return $userTemplatePath;
319
+                }
320
+            }
321
+
322
+            $this->setTemplatePath($path ?? '');
323
+            return $this->getTemplatePath();
324
+        } catch (\Throwable $e) {
325
+            $this->logger->error('Failed to initialize templates directory to user language ' . $userLang . ' for ' . $userId, ['app' => 'files_templates', 'exception' => $e]);
326
+        }
327
+        $this->setTemplatePath('');
328
+        return $this->getTemplatePath();
329
+    }
330
+
331
+    private function getLocalizedTemplatePath(string $skeletonTemplatePath, string $userLang) {
332
+        $localizedSkeletonTemplatePath = str_replace('{lang}', $userLang, $skeletonTemplatePath);
333
+
334
+        if (!file_exists($localizedSkeletonTemplatePath)) {
335
+            $dialectStart = strpos($userLang, '_');
336
+            if ($dialectStart !== false) {
337
+                $localizedSkeletonTemplatePath = str_replace('{lang}', substr($userLang, 0, $dialectStart), $skeletonTemplatePath);
338
+            }
339
+            if ($dialectStart === false || !file_exists($localizedSkeletonTemplatePath)) {
340
+                $localizedSkeletonTemplatePath = str_replace('{lang}', 'default', $skeletonTemplatePath);
341
+            }
342
+        }
343
+
344
+        return $localizedSkeletonTemplatePath;
345
+    }
346 346
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -118,14 +118,14 @@  discard block
 block discarded – undo
118 118
 
119 119
 	public function listCreators(): array {
120 120
 		$types = $this->getTypes();
121
-		usort($types, function (TemplateFileCreator $a, TemplateFileCreator $b) {
121
+		usort($types, function(TemplateFileCreator $a, TemplateFileCreator $b) {
122 122
 			return $a->getOrder() - $b->getOrder();
123 123
 		});
124 124
 		return $types;
125 125
 	}
126 126
 
127 127
 	public function listTemplates(): array {
128
-		return array_map(function (TemplateFileCreator $entry) {
128
+		return array_map(function(TemplateFileCreator $entry) {
129 129
 			return array_merge($entry->jsonSerialize(), [
130 130
 				'templates' => $this->getTemplateFiles($entry)
131 131
 			]);
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 				$template = $userFolder->get($templateId);
152 152
 				$template->copy($targetFile->getPath());
153 153
 			} else {
154
-				$matchingProvider = array_filter($this->getRegisteredProviders(), function (ICustomTemplateProvider $provider) use ($templateType) {
154
+				$matchingProvider = array_filter($this->getRegisteredProviders(), function(ICustomTemplateProvider $provider) use ($templateType) {
155 155
 					return $templateType === get_class($provider);
156 156
 				});
157 157
 				$provider = array_shift($matchingProvider);
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 			$this->userId = $userId;
253 253
 		}
254 254
 
255
-		$defaultSkeletonDirectory = \OC::$SERVERROOT . '/core/skeleton';
256
-		$defaultTemplateDirectory = \OC::$SERVERROOT . '/core/skeleton/Templates';
255
+		$defaultSkeletonDirectory = \OC::$SERVERROOT.'/core/skeleton';
256
+		$defaultTemplateDirectory = \OC::$SERVERROOT.'/core/skeleton/Templates';
257 257
 		$skeletonPath = $this->config->getSystemValue('skeletondirectory', $defaultSkeletonDirectory);
258 258
 		$skeletonTemplatePath = $this->config->getSystemValue('templatedirectory', $defaultTemplateDirectory);
259 259
 		$isDefaultSkeleton = $skeletonPath === $defaultSkeletonDirectory;
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 		try {
264 264
 			$l10n = $this->l10nFactory->get('lib', $userLang);
265 265
 			$userFolder = $this->rootFolder->getUserFolder($this->userId);
266
-			$userTemplatePath = $path ?? $l10n->t('Templates') . '/';
266
+			$userTemplatePath = $path ?? $l10n->t('Templates').'/';
267 267
 
268 268
 			// Initial user setup without a provided path
269 269
 			if ($path === null) {
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 					if (!$userFolder->nodeExists('Templates')) {
273 273
 						return '';
274 274
 					}
275
-					$newPath = $userFolder->getPath() . '/' . $userTemplatePath;
275
+					$newPath = $userFolder->getPath().'/'.$userTemplatePath;
276 276
 					if ($newPath !== $userFolder->get('Templates')->getPath()) {
277 277
 						$userFolder->get('Templates')->move($newPath);
278 278
 					}
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 			}
311 311
 
312 312
 			if ($path !== null && $isDefaultSkeleton && $isDefaultTemplates && $folderIsEmpty) {
313
-				$localizedSkeletonPath = $this->getLocalizedTemplatePath($skeletonPath . '/Templates', $userLang);
313
+				$localizedSkeletonPath = $this->getLocalizedTemplatePath($skeletonPath.'/Templates', $userLang);
314 314
 				if (!empty($localizedSkeletonPath) && file_exists($localizedSkeletonPath)) {
315 315
 					\OC_Util::copyr($localizedSkeletonPath, $folder);
316 316
 					$userFolder->getStorage()->getScanner()->scan($userTemplatePath, Scanner::SCAN_RECURSIVE);
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 			$this->setTemplatePath($path ?? '');
323 323
 			return $this->getTemplatePath();
324 324
 		} catch (\Throwable $e) {
325
-			$this->logger->error('Failed to initialize templates directory to user language ' . $userLang . ' for ' . $userId, ['app' => 'files_templates', 'exception' => $e]);
325
+			$this->logger->error('Failed to initialize templates directory to user language '.$userLang.' for '.$userId, ['app' => 'files_templates', 'exception' => $e]);
326 326
 		}
327 327
 		$this->setTemplatePath('');
328 328
 		return $this->getTemplatePath();
Please login to merge, or discard this patch.
lib/private/AppFramework/Bootstrap/RegistrationContext.php 1 patch
Indentation   +443 added lines, -443 removed lines patch added patch discarded remove patch
@@ -41,447 +41,447 @@
 block discarded – undo
41 41
 
42 42
 class RegistrationContext {
43 43
 
44
-	/** @var array[] */
45
-	private $capabilities = [];
46
-
47
-	/** @var array[] */
48
-	private $crashReporters = [];
49
-
50
-	/** @var array[] */
51
-	private $dashboardPanels = [];
52
-
53
-	/** @var array[] */
54
-	private $services = [];
55
-
56
-	/** @var array[] */
57
-	private $aliases = [];
58
-
59
-	/** @var array[] */
60
-	private $parameters = [];
61
-
62
-	/** @var array[] */
63
-	private $eventListeners = [];
64
-
65
-	/** @var array[] */
66
-	private $middlewares = [];
67
-
68
-	/** @var array[] */
69
-	private $searchProviders = [];
70
-
71
-	/** @var array[] */
72
-	private $alternativeLogins = [];
73
-
74
-	/** @var array[] */
75
-	private $initialStates = [];
76
-
77
-	/** @var array[] */
78
-	private $wellKnownHandlers = [];
79
-
80
-	/** @var array[] */
81
-	private $templateProviders = [];
82
-
83
-	/** @var ILogger */
84
-	private $logger;
85
-
86
-	public function __construct(ILogger $logger) {
87
-		$this->logger = $logger;
88
-	}
89
-
90
-	public function for(string $appId): IRegistrationContext {
91
-		return new class($appId, $this) implements IRegistrationContext {
92
-			/** @var string */
93
-			private $appId;
94
-
95
-			/** @var RegistrationContext */
96
-			private $context;
97
-
98
-			public function __construct(string $appId, RegistrationContext $context) {
99
-				$this->appId = $appId;
100
-				$this->context = $context;
101
-			}
102
-
103
-			public function registerCapability(string $capability): void {
104
-				$this->context->registerCapability(
105
-					$this->appId,
106
-					$capability
107
-				);
108
-			}
109
-
110
-			public function registerCrashReporter(string $reporterClass): void {
111
-				$this->context->registerCrashReporter(
112
-					$this->appId,
113
-					$reporterClass
114
-				);
115
-			}
116
-
117
-			public function registerDashboardWidget(string $widgetClass): void {
118
-				$this->context->registerDashboardPanel(
119
-					$this->appId,
120
-					$widgetClass
121
-				);
122
-			}
123
-
124
-			public function registerService(string $name, callable $factory, bool $shared = true): void {
125
-				$this->context->registerService(
126
-					$this->appId,
127
-					$name,
128
-					$factory,
129
-					$shared
130
-				);
131
-			}
132
-
133
-			public function registerServiceAlias(string $alias, string $target): void {
134
-				$this->context->registerServiceAlias(
135
-					$this->appId,
136
-					$alias,
137
-					$target
138
-				);
139
-			}
140
-
141
-			public function registerParameter(string $name, $value): void {
142
-				$this->context->registerParameter(
143
-					$this->appId,
144
-					$name,
145
-					$value
146
-				);
147
-			}
148
-
149
-			public function registerEventListener(string $event, string $listener, int $priority = 0): void {
150
-				$this->context->registerEventListener(
151
-					$this->appId,
152
-					$event,
153
-					$listener,
154
-					$priority
155
-				);
156
-			}
157
-
158
-			public function registerMiddleware(string $class): void {
159
-				$this->context->registerMiddleware(
160
-					$this->appId,
161
-					$class
162
-				);
163
-			}
164
-
165
-			public function registerSearchProvider(string $class): void {
166
-				$this->context->registerSearchProvider(
167
-					$this->appId,
168
-					$class
169
-				);
170
-			}
171
-
172
-			public function registerAlternativeLogin(string $class): void {
173
-				$this->context->registerAlternativeLogin(
174
-					$this->appId,
175
-					$class
176
-				);
177
-			}
178
-
179
-			public function registerInitialStateProvider(string $class): void {
180
-				$this->context->registerInitialState(
181
-					$this->appId,
182
-					$class
183
-				);
184
-			}
185
-
186
-			public function registerWellKnownHandler(string $class): void {
187
-				$this->context->registerWellKnown(
188
-					$this->appId,
189
-					$class
190
-				);
191
-			}
192
-
193
-			public function registerTemplateProvider(string $providerClass): void {
194
-				$this->context->registerTemplateProvider(
195
-					$this->appId,
196
-					$providerClass
197
-				);
198
-			}
199
-		};
200
-	}
201
-
202
-	public function registerCapability(string $appId, string $capability): void {
203
-		$this->capabilities[] = [
204
-			'appId' => $appId,
205
-			'capability' => $capability
206
-		];
207
-	}
208
-
209
-	public function registerCrashReporter(string $appId, string $reporterClass): void {
210
-		$this->crashReporters[] = [
211
-			'appId' => $appId,
212
-			'class' => $reporterClass,
213
-		];
214
-	}
215
-
216
-	public function registerDashboardPanel(string $appId, string $panelClass): void {
217
-		$this->dashboardPanels[] = [
218
-			'appId' => $appId,
219
-			'class' => $panelClass
220
-		];
221
-	}
222
-
223
-	public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void {
224
-		$this->services[] = [
225
-			"appId" => $appId,
226
-			"name" => $name,
227
-			"factory" => $factory,
228
-			"shared" => $shared,
229
-		];
230
-	}
231
-
232
-	public function registerServiceAlias(string $appId, string $alias, string $target): void {
233
-		$this->aliases[] = [
234
-			"appId" => $appId,
235
-			"alias" => $alias,
236
-			"target" => $target,
237
-		];
238
-	}
239
-
240
-	public function registerParameter(string $appId, string $name, $value): void {
241
-		$this->parameters[] = [
242
-			"appId" => $appId,
243
-			"name" => $name,
244
-			"value" => $value,
245
-		];
246
-	}
247
-
248
-	public function registerEventListener(string $appId, string $event, string $listener, int $priority = 0): void {
249
-		$this->eventListeners[] = [
250
-			"appId" => $appId,
251
-			"event" => $event,
252
-			"listener" => $listener,
253
-			"priority" => $priority,
254
-		];
255
-	}
256
-
257
-	public function registerMiddleware(string $appId, string $class): void {
258
-		$this->middlewares[] = [
259
-			"appId" => $appId,
260
-			"class" => $class,
261
-		];
262
-	}
263
-
264
-	public function registerSearchProvider(string $appId, string $class) {
265
-		$this->searchProviders[] = [
266
-			'appId' => $appId,
267
-			'class' => $class,
268
-		];
269
-	}
270
-
271
-	public function registerAlternativeLogin(string $appId, string $class): void {
272
-		$this->alternativeLogins[] = [
273
-			'appId' => $appId,
274
-			'class' => $class,
275
-		];
276
-	}
277
-
278
-	public function registerInitialState(string $appId, string $class): void {
279
-		$this->initialStates[] = [
280
-			'appId' => $appId,
281
-			'class' => $class,
282
-		];
283
-	}
284
-
285
-	public function registerWellKnown(string $appId, string $class): void {
286
-		$this->wellKnownHandlers[] = [
287
-			'appId' => $appId,
288
-			'class' => $class,
289
-		];
290
-	}
291
-
292
-	public function registerTemplateProvider(string $appId, string $class): void {
293
-		$this->templateProviders[] = [
294
-			'appId' => $appId,
295
-			'class' => $class,
296
-		];
297
-	}
298
-
299
-	/**
300
-	 * @param App[] $apps
301
-	 */
302
-	public function delegateCapabilityRegistrations(array $apps): void {
303
-		while (($registration = array_shift($this->capabilities)) !== null) {
304
-			try {
305
-				$apps[$registration['appId']]
306
-					->getContainer()
307
-					->registerCapability($registration['capability']);
308
-			} catch (Throwable $e) {
309
-				$appId = $registration['appId'];
310
-				$this->logger->logException($e, [
311
-					'message' => "Error during capability registration of $appId: " . $e->getMessage(),
312
-					'level' => ILogger::ERROR,
313
-				]);
314
-			}
315
-		}
316
-	}
317
-
318
-	/**
319
-	 * @param App[] $apps
320
-	 */
321
-	public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void {
322
-		while (($registration = array_shift($this->crashReporters)) !== null) {
323
-			try {
324
-				$registry->registerLazy($registration['class']);
325
-			} catch (Throwable $e) {
326
-				$appId = $registration['appId'];
327
-				$this->logger->logException($e, [
328
-					'message' => "Error during crash reporter registration of $appId: " . $e->getMessage(),
329
-					'level' => ILogger::ERROR,
330
-				]);
331
-			}
332
-		}
333
-	}
334
-
335
-	/**
336
-	 * @param App[] $apps
337
-	 */
338
-	public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void {
339
-		while (($panel = array_shift($this->dashboardPanels)) !== null) {
340
-			try {
341
-				$dashboardManager->lazyRegisterWidget($panel['class']);
342
-			} catch (Throwable $e) {
343
-				$appId = $panel['appId'];
344
-				$this->logger->logException($e, [
345
-					'message' => "Error during dashboard registration of $appId: " . $e->getMessage(),
346
-					'level' => ILogger::ERROR,
347
-				]);
348
-			}
349
-		}
350
-	}
351
-
352
-	public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void {
353
-		while (($registration = array_shift($this->eventListeners)) !== null) {
354
-			try {
355
-				if (isset($registration['priority'])) {
356
-					$eventDispatcher->addServiceListener(
357
-						$registration['event'],
358
-						$registration['listener'],
359
-						$registration['priority']
360
-					);
361
-				} else {
362
-					$eventDispatcher->addServiceListener(
363
-						$registration['event'],
364
-						$registration['listener']
365
-					);
366
-				}
367
-			} catch (Throwable $e) {
368
-				$appId = $registration['appId'];
369
-				$this->logger->logException($e, [
370
-					'message' => "Error during event listener registration of $appId: " . $e->getMessage(),
371
-					'level' => ILogger::ERROR,
372
-				]);
373
-			}
374
-		}
375
-	}
376
-
377
-	/**
378
-	 * @param App[] $apps
379
-	 */
380
-	public function delegateContainerRegistrations(array $apps): void {
381
-		while (($registration = array_shift($this->services)) !== null) {
382
-			try {
383
-				/**
384
-				 * Register the service and convert the callable into a \Closure if necessary
385
-				 */
386
-				$apps[$registration['appId']]
387
-					->getContainer()
388
-					->registerService(
389
-						$registration['name'],
390
-						Closure::fromCallable($registration['factory']),
391
-						$registration['shared'] ?? true
392
-					);
393
-			} catch (Throwable $e) {
394
-				$appId = $registration['appId'];
395
-				$this->logger->logException($e, [
396
-					'message' => "Error during service registration of $appId: " . $e->getMessage(),
397
-					'level' => ILogger::ERROR,
398
-				]);
399
-			}
400
-		}
401
-
402
-		foreach ($this->aliases as $registration) {
403
-			try {
404
-				$apps[$registration['appId']]
405
-					->getContainer()
406
-					->registerAlias(
407
-						$registration['alias'],
408
-						$registration['target']
409
-					);
410
-			} catch (Throwable $e) {
411
-				$appId = $registration['appId'];
412
-				$this->logger->logException($e, [
413
-					'message' => "Error during service alias registration of $appId: " . $e->getMessage(),
414
-					'level' => ILogger::ERROR,
415
-				]);
416
-			}
417
-		}
418
-
419
-		foreach ($this->parameters as $registration) {
420
-			try {
421
-				$apps[$registration['appId']]
422
-					->getContainer()
423
-					->registerParameter(
424
-						$registration['name'],
425
-						$registration['value']
426
-					);
427
-			} catch (Throwable $e) {
428
-				$appId = $registration['appId'];
429
-				$this->logger->logException($e, [
430
-					'message' => "Error during service alias registration of $appId: " . $e->getMessage(),
431
-					'level' => ILogger::ERROR,
432
-				]);
433
-			}
434
-		}
435
-	}
436
-
437
-	/**
438
-	 * @param App[] $apps
439
-	 */
440
-	public function delegateMiddlewareRegistrations(array $apps): void {
441
-		while (($middleware = array_shift($this->middlewares)) !== null) {
442
-			try {
443
-				$apps[$middleware['appId']]
444
-					->getContainer()
445
-					->registerMiddleWare($middleware['class']);
446
-			} catch (Throwable $e) {
447
-				$appId = $middleware['appId'];
448
-				$this->logger->logException($e, [
449
-					'message' => "Error during capability registration of $appId: " . $e->getMessage(),
450
-					'level' => ILogger::ERROR,
451
-				]);
452
-			}
453
-		}
454
-	}
455
-
456
-	/**
457
-	 * @return array[]
458
-	 */
459
-	public function getSearchProviders(): array {
460
-		return $this->searchProviders;
461
-	}
462
-
463
-	/**
464
-	 * @return array[]
465
-	 */
466
-	public function getAlternativeLogins(): array {
467
-		return $this->alternativeLogins;
468
-	}
469
-
470
-	/**
471
-	 * @return array[]
472
-	 */
473
-	public function getInitialStates(): array {
474
-		return $this->initialStates;
475
-	}
476
-
477
-	/**
478
-	 * @return array[]
479
-	 */
480
-	public function getWellKnownHandlers(): array {
481
-		return $this->wellKnownHandlers;
482
-	}
483
-
484
-	public function getTemplateProviders(): array {
485
-		return $this->templateProviders;
486
-	}
44
+    /** @var array[] */
45
+    private $capabilities = [];
46
+
47
+    /** @var array[] */
48
+    private $crashReporters = [];
49
+
50
+    /** @var array[] */
51
+    private $dashboardPanels = [];
52
+
53
+    /** @var array[] */
54
+    private $services = [];
55
+
56
+    /** @var array[] */
57
+    private $aliases = [];
58
+
59
+    /** @var array[] */
60
+    private $parameters = [];
61
+
62
+    /** @var array[] */
63
+    private $eventListeners = [];
64
+
65
+    /** @var array[] */
66
+    private $middlewares = [];
67
+
68
+    /** @var array[] */
69
+    private $searchProviders = [];
70
+
71
+    /** @var array[] */
72
+    private $alternativeLogins = [];
73
+
74
+    /** @var array[] */
75
+    private $initialStates = [];
76
+
77
+    /** @var array[] */
78
+    private $wellKnownHandlers = [];
79
+
80
+    /** @var array[] */
81
+    private $templateProviders = [];
82
+
83
+    /** @var ILogger */
84
+    private $logger;
85
+
86
+    public function __construct(ILogger $logger) {
87
+        $this->logger = $logger;
88
+    }
89
+
90
+    public function for(string $appId): IRegistrationContext {
91
+        return new class($appId, $this) implements IRegistrationContext {
92
+            /** @var string */
93
+            private $appId;
94
+
95
+            /** @var RegistrationContext */
96
+            private $context;
97
+
98
+            public function __construct(string $appId, RegistrationContext $context) {
99
+                $this->appId = $appId;
100
+                $this->context = $context;
101
+            }
102
+
103
+            public function registerCapability(string $capability): void {
104
+                $this->context->registerCapability(
105
+                    $this->appId,
106
+                    $capability
107
+                );
108
+            }
109
+
110
+            public function registerCrashReporter(string $reporterClass): void {
111
+                $this->context->registerCrashReporter(
112
+                    $this->appId,
113
+                    $reporterClass
114
+                );
115
+            }
116
+
117
+            public function registerDashboardWidget(string $widgetClass): void {
118
+                $this->context->registerDashboardPanel(
119
+                    $this->appId,
120
+                    $widgetClass
121
+                );
122
+            }
123
+
124
+            public function registerService(string $name, callable $factory, bool $shared = true): void {
125
+                $this->context->registerService(
126
+                    $this->appId,
127
+                    $name,
128
+                    $factory,
129
+                    $shared
130
+                );
131
+            }
132
+
133
+            public function registerServiceAlias(string $alias, string $target): void {
134
+                $this->context->registerServiceAlias(
135
+                    $this->appId,
136
+                    $alias,
137
+                    $target
138
+                );
139
+            }
140
+
141
+            public function registerParameter(string $name, $value): void {
142
+                $this->context->registerParameter(
143
+                    $this->appId,
144
+                    $name,
145
+                    $value
146
+                );
147
+            }
148
+
149
+            public function registerEventListener(string $event, string $listener, int $priority = 0): void {
150
+                $this->context->registerEventListener(
151
+                    $this->appId,
152
+                    $event,
153
+                    $listener,
154
+                    $priority
155
+                );
156
+            }
157
+
158
+            public function registerMiddleware(string $class): void {
159
+                $this->context->registerMiddleware(
160
+                    $this->appId,
161
+                    $class
162
+                );
163
+            }
164
+
165
+            public function registerSearchProvider(string $class): void {
166
+                $this->context->registerSearchProvider(
167
+                    $this->appId,
168
+                    $class
169
+                );
170
+            }
171
+
172
+            public function registerAlternativeLogin(string $class): void {
173
+                $this->context->registerAlternativeLogin(
174
+                    $this->appId,
175
+                    $class
176
+                );
177
+            }
178
+
179
+            public function registerInitialStateProvider(string $class): void {
180
+                $this->context->registerInitialState(
181
+                    $this->appId,
182
+                    $class
183
+                );
184
+            }
185
+
186
+            public function registerWellKnownHandler(string $class): void {
187
+                $this->context->registerWellKnown(
188
+                    $this->appId,
189
+                    $class
190
+                );
191
+            }
192
+
193
+            public function registerTemplateProvider(string $providerClass): void {
194
+                $this->context->registerTemplateProvider(
195
+                    $this->appId,
196
+                    $providerClass
197
+                );
198
+            }
199
+        };
200
+    }
201
+
202
+    public function registerCapability(string $appId, string $capability): void {
203
+        $this->capabilities[] = [
204
+            'appId' => $appId,
205
+            'capability' => $capability
206
+        ];
207
+    }
208
+
209
+    public function registerCrashReporter(string $appId, string $reporterClass): void {
210
+        $this->crashReporters[] = [
211
+            'appId' => $appId,
212
+            'class' => $reporterClass,
213
+        ];
214
+    }
215
+
216
+    public function registerDashboardPanel(string $appId, string $panelClass): void {
217
+        $this->dashboardPanels[] = [
218
+            'appId' => $appId,
219
+            'class' => $panelClass
220
+        ];
221
+    }
222
+
223
+    public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void {
224
+        $this->services[] = [
225
+            "appId" => $appId,
226
+            "name" => $name,
227
+            "factory" => $factory,
228
+            "shared" => $shared,
229
+        ];
230
+    }
231
+
232
+    public function registerServiceAlias(string $appId, string $alias, string $target): void {
233
+        $this->aliases[] = [
234
+            "appId" => $appId,
235
+            "alias" => $alias,
236
+            "target" => $target,
237
+        ];
238
+    }
239
+
240
+    public function registerParameter(string $appId, string $name, $value): void {
241
+        $this->parameters[] = [
242
+            "appId" => $appId,
243
+            "name" => $name,
244
+            "value" => $value,
245
+        ];
246
+    }
247
+
248
+    public function registerEventListener(string $appId, string $event, string $listener, int $priority = 0): void {
249
+        $this->eventListeners[] = [
250
+            "appId" => $appId,
251
+            "event" => $event,
252
+            "listener" => $listener,
253
+            "priority" => $priority,
254
+        ];
255
+    }
256
+
257
+    public function registerMiddleware(string $appId, string $class): void {
258
+        $this->middlewares[] = [
259
+            "appId" => $appId,
260
+            "class" => $class,
261
+        ];
262
+    }
263
+
264
+    public function registerSearchProvider(string $appId, string $class) {
265
+        $this->searchProviders[] = [
266
+            'appId' => $appId,
267
+            'class' => $class,
268
+        ];
269
+    }
270
+
271
+    public function registerAlternativeLogin(string $appId, string $class): void {
272
+        $this->alternativeLogins[] = [
273
+            'appId' => $appId,
274
+            'class' => $class,
275
+        ];
276
+    }
277
+
278
+    public function registerInitialState(string $appId, string $class): void {
279
+        $this->initialStates[] = [
280
+            'appId' => $appId,
281
+            'class' => $class,
282
+        ];
283
+    }
284
+
285
+    public function registerWellKnown(string $appId, string $class): void {
286
+        $this->wellKnownHandlers[] = [
287
+            'appId' => $appId,
288
+            'class' => $class,
289
+        ];
290
+    }
291
+
292
+    public function registerTemplateProvider(string $appId, string $class): void {
293
+        $this->templateProviders[] = [
294
+            'appId' => $appId,
295
+            'class' => $class,
296
+        ];
297
+    }
298
+
299
+    /**
300
+     * @param App[] $apps
301
+     */
302
+    public function delegateCapabilityRegistrations(array $apps): void {
303
+        while (($registration = array_shift($this->capabilities)) !== null) {
304
+            try {
305
+                $apps[$registration['appId']]
306
+                    ->getContainer()
307
+                    ->registerCapability($registration['capability']);
308
+            } catch (Throwable $e) {
309
+                $appId = $registration['appId'];
310
+                $this->logger->logException($e, [
311
+                    'message' => "Error during capability registration of $appId: " . $e->getMessage(),
312
+                    'level' => ILogger::ERROR,
313
+                ]);
314
+            }
315
+        }
316
+    }
317
+
318
+    /**
319
+     * @param App[] $apps
320
+     */
321
+    public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void {
322
+        while (($registration = array_shift($this->crashReporters)) !== null) {
323
+            try {
324
+                $registry->registerLazy($registration['class']);
325
+            } catch (Throwable $e) {
326
+                $appId = $registration['appId'];
327
+                $this->logger->logException($e, [
328
+                    'message' => "Error during crash reporter registration of $appId: " . $e->getMessage(),
329
+                    'level' => ILogger::ERROR,
330
+                ]);
331
+            }
332
+        }
333
+    }
334
+
335
+    /**
336
+     * @param App[] $apps
337
+     */
338
+    public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void {
339
+        while (($panel = array_shift($this->dashboardPanels)) !== null) {
340
+            try {
341
+                $dashboardManager->lazyRegisterWidget($panel['class']);
342
+            } catch (Throwable $e) {
343
+                $appId = $panel['appId'];
344
+                $this->logger->logException($e, [
345
+                    'message' => "Error during dashboard registration of $appId: " . $e->getMessage(),
346
+                    'level' => ILogger::ERROR,
347
+                ]);
348
+            }
349
+        }
350
+    }
351
+
352
+    public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void {
353
+        while (($registration = array_shift($this->eventListeners)) !== null) {
354
+            try {
355
+                if (isset($registration['priority'])) {
356
+                    $eventDispatcher->addServiceListener(
357
+                        $registration['event'],
358
+                        $registration['listener'],
359
+                        $registration['priority']
360
+                    );
361
+                } else {
362
+                    $eventDispatcher->addServiceListener(
363
+                        $registration['event'],
364
+                        $registration['listener']
365
+                    );
366
+                }
367
+            } catch (Throwable $e) {
368
+                $appId = $registration['appId'];
369
+                $this->logger->logException($e, [
370
+                    'message' => "Error during event listener registration of $appId: " . $e->getMessage(),
371
+                    'level' => ILogger::ERROR,
372
+                ]);
373
+            }
374
+        }
375
+    }
376
+
377
+    /**
378
+     * @param App[] $apps
379
+     */
380
+    public function delegateContainerRegistrations(array $apps): void {
381
+        while (($registration = array_shift($this->services)) !== null) {
382
+            try {
383
+                /**
384
+                 * Register the service and convert the callable into a \Closure if necessary
385
+                 */
386
+                $apps[$registration['appId']]
387
+                    ->getContainer()
388
+                    ->registerService(
389
+                        $registration['name'],
390
+                        Closure::fromCallable($registration['factory']),
391
+                        $registration['shared'] ?? true
392
+                    );
393
+            } catch (Throwable $e) {
394
+                $appId = $registration['appId'];
395
+                $this->logger->logException($e, [
396
+                    'message' => "Error during service registration of $appId: " . $e->getMessage(),
397
+                    'level' => ILogger::ERROR,
398
+                ]);
399
+            }
400
+        }
401
+
402
+        foreach ($this->aliases as $registration) {
403
+            try {
404
+                $apps[$registration['appId']]
405
+                    ->getContainer()
406
+                    ->registerAlias(
407
+                        $registration['alias'],
408
+                        $registration['target']
409
+                    );
410
+            } catch (Throwable $e) {
411
+                $appId = $registration['appId'];
412
+                $this->logger->logException($e, [
413
+                    'message' => "Error during service alias registration of $appId: " . $e->getMessage(),
414
+                    'level' => ILogger::ERROR,
415
+                ]);
416
+            }
417
+        }
418
+
419
+        foreach ($this->parameters as $registration) {
420
+            try {
421
+                $apps[$registration['appId']]
422
+                    ->getContainer()
423
+                    ->registerParameter(
424
+                        $registration['name'],
425
+                        $registration['value']
426
+                    );
427
+            } catch (Throwable $e) {
428
+                $appId = $registration['appId'];
429
+                $this->logger->logException($e, [
430
+                    'message' => "Error during service alias registration of $appId: " . $e->getMessage(),
431
+                    'level' => ILogger::ERROR,
432
+                ]);
433
+            }
434
+        }
435
+    }
436
+
437
+    /**
438
+     * @param App[] $apps
439
+     */
440
+    public function delegateMiddlewareRegistrations(array $apps): void {
441
+        while (($middleware = array_shift($this->middlewares)) !== null) {
442
+            try {
443
+                $apps[$middleware['appId']]
444
+                    ->getContainer()
445
+                    ->registerMiddleWare($middleware['class']);
446
+            } catch (Throwable $e) {
447
+                $appId = $middleware['appId'];
448
+                $this->logger->logException($e, [
449
+                    'message' => "Error during capability registration of $appId: " . $e->getMessage(),
450
+                    'level' => ILogger::ERROR,
451
+                ]);
452
+            }
453
+        }
454
+    }
455
+
456
+    /**
457
+     * @return array[]
458
+     */
459
+    public function getSearchProviders(): array {
460
+        return $this->searchProviders;
461
+    }
462
+
463
+    /**
464
+     * @return array[]
465
+     */
466
+    public function getAlternativeLogins(): array {
467
+        return $this->alternativeLogins;
468
+    }
469
+
470
+    /**
471
+     * @return array[]
472
+     */
473
+    public function getInitialStates(): array {
474
+        return $this->initialStates;
475
+    }
476
+
477
+    /**
478
+     * @return array[]
479
+     */
480
+    public function getWellKnownHandlers(): array {
481
+        return $this->wellKnownHandlers;
482
+    }
483
+
484
+    public function getTemplateProviders(): array {
485
+        return $this->templateProviders;
486
+    }
487 487
 }
Please login to merge, or discard this patch.
lib/private/Server.php 1 patch
Indentation   +2032 added lines, -2032 removed lines patch added patch discarded remove patch
@@ -252,2041 +252,2041 @@
 block discarded – undo
252 252
  */
253 253
 class Server extends ServerContainer implements IServerContainer {
254 254
 
255
-	/** @var string */
256
-	private $webRoot;
257
-
258
-	/**
259
-	 * @param string $webRoot
260
-	 * @param \OC\Config $config
261
-	 */
262
-	public function __construct($webRoot, \OC\Config $config) {
263
-		parent::__construct();
264
-		$this->webRoot = $webRoot;
265
-
266
-		// To find out if we are running from CLI or not
267
-		$this->registerParameter('isCLI', \OC::$CLI);
268
-		$this->registerParameter('serverRoot', \OC::$SERVERROOT);
269
-
270
-		$this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
271
-			return $c;
272
-		});
273
-		$this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) {
274
-			return $c;
275
-		});
276
-
277
-		$this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
278
-		/** @deprecated 19.0.0 */
279
-		$this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class);
280
-
281
-		$this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
282
-		/** @deprecated 19.0.0 */
283
-		$this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
284
-
285
-		$this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
286
-		/** @deprecated 19.0.0 */
287
-		$this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
288
-
289
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
290
-		/** @deprecated 19.0.0 */
291
-		$this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class);
292
-
293
-		$this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
294
-		$this->registerAlias(ITemplateManager::class, TemplateManager::class);
295
-
296
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
297
-
298
-		$this->registerService(View::class, function (Server $c) {
299
-			return new View();
300
-		}, false);
301
-
302
-		$this->registerService(IPreview::class, function (ContainerInterface $c) {
303
-			return new PreviewManager(
304
-				$c->get(\OCP\IConfig::class),
305
-				$c->get(IRootFolder::class),
306
-				new \OC\Preview\Storage\Root(
307
-					$c->get(IRootFolder::class),
308
-					$c->get(SystemConfig::class)
309
-				),
310
-				$c->get(SymfonyAdapter::class),
311
-				$c->get(GeneratorHelper::class),
312
-				$c->get(ISession::class)->get('user_id')
313
-			);
314
-		});
315
-		/** @deprecated 19.0.0 */
316
-		$this->registerDeprecatedAlias('PreviewManager', IPreview::class);
317
-
318
-		$this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) {
319
-			return new \OC\Preview\Watcher(
320
-				new \OC\Preview\Storage\Root(
321
-					$c->get(IRootFolder::class),
322
-					$c->get(SystemConfig::class)
323
-				)
324
-			);
325
-		});
326
-
327
-		$this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
328
-			$view = new View();
329
-			$util = new Encryption\Util(
330
-				$view,
331
-				$c->get(IUserManager::class),
332
-				$c->get(IGroupManager::class),
333
-				$c->get(\OCP\IConfig::class)
334
-			);
335
-			return new Encryption\Manager(
336
-				$c->get(\OCP\IConfig::class),
337
-				$c->get(ILogger::class),
338
-				$c->getL10N('core'),
339
-				new View(),
340
-				$util,
341
-				new ArrayCache()
342
-			);
343
-		});
344
-		/** @deprecated 19.0.0 */
345
-		$this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class);
346
-
347
-		/** @deprecated 21.0.0 */
348
-		$this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class);
349
-		$this->registerService(IFile::class, function (ContainerInterface $c) {
350
-			$util = new Encryption\Util(
351
-				new View(),
352
-				$c->get(IUserManager::class),
353
-				$c->get(IGroupManager::class),
354
-				$c->get(\OCP\IConfig::class)
355
-			);
356
-			return new Encryption\File(
357
-				$util,
358
-				$c->get(IRootFolder::class),
359
-				$c->get(\OCP\Share\IManager::class)
360
-			);
361
-		});
362
-
363
-		/** @deprecated 21.0.0 */
364
-		$this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class);
365
-		$this->registerService(IStorage::class, function (ContainerInterface $c) {
366
-			$view = new View();
367
-			$util = new Encryption\Util(
368
-				$view,
369
-				$c->get(IUserManager::class),
370
-				$c->get(IGroupManager::class),
371
-				$c->get(\OCP\IConfig::class)
372
-			);
373
-
374
-			return new Encryption\Keys\Storage(
375
-				$view,
376
-				$util,
377
-				$c->get(ICrypto::class),
378
-				$c->get(\OCP\IConfig::class)
379
-			);
380
-		});
381
-		/** @deprecated 20.0.0 */
382
-		$this->registerDeprecatedAlias('TagMapper', TagMapper::class);
383
-
384
-		$this->registerAlias(\OCP\ITagManager::class, TagManager::class);
385
-		/** @deprecated 19.0.0 */
386
-		$this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class);
387
-
388
-		$this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) {
389
-			/** @var \OCP\IConfig $config */
390
-			$config = $c->get(\OCP\IConfig::class);
391
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
392
-			return new $factoryClass($this);
393
-		});
394
-		$this->registerService(ISystemTagManager::class, function (ContainerInterface $c) {
395
-			return $c->get('SystemTagManagerFactory')->getManager();
396
-		});
397
-		/** @deprecated 19.0.0 */
398
-		$this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
399
-
400
-		$this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) {
401
-			return $c->get('SystemTagManagerFactory')->getObjectMapper();
402
-		});
403
-		$this->registerService('RootFolder', function (ContainerInterface $c) {
404
-			$manager = \OC\Files\Filesystem::getMountManager(null);
405
-			$view = new View();
406
-			$root = new Root(
407
-				$manager,
408
-				$view,
409
-				null,
410
-				$c->get(IUserMountCache::class),
411
-				$this->get(ILogger::class),
412
-				$this->get(IUserManager::class)
413
-			);
414
-
415
-			$previewConnector = new \OC\Preview\WatcherConnector(
416
-				$root,
417
-				$c->get(SystemConfig::class)
418
-			);
419
-			$previewConnector->connectWatcher();
420
-
421
-			return $root;
422
-		});
423
-		$this->registerService(HookConnector::class, function (ContainerInterface $c) {
424
-			return new HookConnector(
425
-				$c->get(IRootFolder::class),
426
-				new View(),
427
-				$c->get(\OC\EventDispatcher\SymfonyAdapter::class),
428
-				$c->get(IEventDispatcher::class)
429
-			);
430
-		});
431
-
432
-		/** @deprecated 19.0.0 */
433
-		$this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class);
434
-
435
-		$this->registerService(IRootFolder::class, function (ContainerInterface $c) {
436
-			return new LazyRoot(function () use ($c) {
437
-				return $c->get('RootFolder');
438
-			});
439
-		});
440
-		/** @deprecated 19.0.0 */
441
-		$this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class);
442
-
443
-		/** @deprecated 19.0.0 */
444
-		$this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class);
445
-		$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
446
-
447
-		$this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) {
448
-			$groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class));
449
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
450
-				/** @var IEventDispatcher $dispatcher */
451
-				$dispatcher = $this->get(IEventDispatcher::class);
452
-				$dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid));
453
-			});
454
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) {
455
-				/** @var IEventDispatcher $dispatcher */
456
-				$dispatcher = $this->get(IEventDispatcher::class);
457
-				$dispatcher->dispatchTyped(new GroupCreatedEvent($group));
458
-			});
459
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
460
-				/** @var IEventDispatcher $dispatcher */
461
-				$dispatcher = $this->get(IEventDispatcher::class);
462
-				$dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group));
463
-			});
464
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
465
-				/** @var IEventDispatcher $dispatcher */
466
-				$dispatcher = $this->get(IEventDispatcher::class);
467
-				$dispatcher->dispatchTyped(new GroupDeletedEvent($group));
468
-			});
469
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
470
-				/** @var IEventDispatcher $dispatcher */
471
-				$dispatcher = $this->get(IEventDispatcher::class);
472
-				$dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user));
473
-			});
474
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
475
-				/** @var IEventDispatcher $dispatcher */
476
-				$dispatcher = $this->get(IEventDispatcher::class);
477
-				$dispatcher->dispatchTyped(new UserAddedEvent($group, $user));
478
-			});
479
-			$groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
480
-				/** @var IEventDispatcher $dispatcher */
481
-				$dispatcher = $this->get(IEventDispatcher::class);
482
-				$dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user));
483
-			});
484
-			$groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
485
-				/** @var IEventDispatcher $dispatcher */
486
-				$dispatcher = $this->get(IEventDispatcher::class);
487
-				$dispatcher->dispatchTyped(new UserRemovedEvent($group, $user));
488
-			});
489
-			return $groupManager;
490
-		});
491
-		/** @deprecated 19.0.0 */
492
-		$this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class);
493
-
494
-		$this->registerService(Store::class, function (ContainerInterface $c) {
495
-			$session = $c->get(ISession::class);
496
-			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
497
-				$tokenProvider = $c->get(IProvider::class);
498
-			} else {
499
-				$tokenProvider = null;
500
-			}
501
-			$logger = $c->get(LoggerInterface::class);
502
-			return new Store($session, $logger, $tokenProvider);
503
-		});
504
-		$this->registerAlias(IStore::class, Store::class);
505
-		$this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
506
-
507
-		$this->registerService(\OC\User\Session::class, function (Server $c) {
508
-			$manager = $c->get(IUserManager::class);
509
-			$session = new \OC\Session\Memory('');
510
-			$timeFactory = new TimeFactory();
511
-			// Token providers might require a working database. This code
512
-			// might however be called when ownCloud is not yet setup.
513
-			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
514
-				$defaultTokenProvider = $c->get(IProvider::class);
515
-			} else {
516
-				$defaultTokenProvider = null;
517
-			}
518
-
519
-			$legacyDispatcher = $c->get(SymfonyAdapter::class);
520
-
521
-			$userSession = new \OC\User\Session(
522
-				$manager,
523
-				$session,
524
-				$timeFactory,
525
-				$defaultTokenProvider,
526
-				$c->get(\OCP\IConfig::class),
527
-				$c->get(ISecureRandom::class),
528
-				$c->getLockdownManager(),
529
-				$c->get(ILogger::class),
530
-				$c->get(IEventDispatcher::class)
531
-			);
532
-			/** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */
533
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
534
-				\OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
535
-			});
536
-			/** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */
537
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
538
-				/** @var \OC\User\User $user */
539
-				\OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
540
-			});
541
-			/** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
542
-			$userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) {
543
-				/** @var \OC\User\User $user */
544
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
545
-				$legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
546
-			});
547
-			/** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
548
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
549
-				/** @var \OC\User\User $user */
550
-				\OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
551
-			});
552
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
553
-				/** @var \OC\User\User $user */
554
-				\OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
555
-
556
-				/** @var IEventDispatcher $dispatcher */
557
-				$dispatcher = $this->get(IEventDispatcher::class);
558
-				$dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword));
559
-			});
560
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
561
-				/** @var \OC\User\User $user */
562
-				\OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
563
-
564
-				/** @var IEventDispatcher $dispatcher */
565
-				$dispatcher = $this->get(IEventDispatcher::class);
566
-				$dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword));
567
-			});
568
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
569
-				\OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
570
-
571
-				/** @var IEventDispatcher $dispatcher */
572
-				$dispatcher = $this->get(IEventDispatcher::class);
573
-				$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
574
-			});
575
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) {
576
-				/** @var \OC\User\User $user */
577
-				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
578
-
579
-				/** @var IEventDispatcher $dispatcher */
580
-				$dispatcher = $this->get(IEventDispatcher::class);
581
-				$dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin));
582
-			});
583
-			$userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
584
-				/** @var IEventDispatcher $dispatcher */
585
-				$dispatcher = $this->get(IEventDispatcher::class);
586
-				$dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
587
-			});
588
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
589
-				/** @var \OC\User\User $user */
590
-				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
591
-
592
-				/** @var IEventDispatcher $dispatcher */
593
-				$dispatcher = $this->get(IEventDispatcher::class);
594
-				$dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
595
-			});
596
-			$userSession->listen('\OC\User', 'logout', function ($user) {
597
-				\OC_Hook::emit('OC_User', 'logout', []);
598
-
599
-				/** @var IEventDispatcher $dispatcher */
600
-				$dispatcher = $this->get(IEventDispatcher::class);
601
-				$dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
602
-			});
603
-			$userSession->listen('\OC\User', 'postLogout', function ($user) {
604
-				/** @var IEventDispatcher $dispatcher */
605
-				$dispatcher = $this->get(IEventDispatcher::class);
606
-				$dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
607
-			});
608
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
609
-				/** @var \OC\User\User $user */
610
-				\OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
611
-
612
-				/** @var IEventDispatcher $dispatcher */
613
-				$dispatcher = $this->get(IEventDispatcher::class);
614
-				$dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue));
615
-			});
616
-			return $userSession;
617
-		});
618
-		$this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
619
-		/** @deprecated 19.0.0 */
620
-		$this->registerDeprecatedAlias('UserSession', \OC\User\Session::class);
621
-
622
-		$this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
623
-
624
-		$this->registerAlias(INavigationManager::class, \OC\NavigationManager::class);
625
-		/** @deprecated 19.0.0 */
626
-		$this->registerDeprecatedAlias('NavigationManager', INavigationManager::class);
627
-
628
-		/** @deprecated 19.0.0 */
629
-		$this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class);
630
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
631
-
632
-		$this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
633
-			return new \OC\SystemConfig($config);
634
-		});
635
-		/** @deprecated 19.0.0 */
636
-		$this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class);
637
-
638
-		/** @deprecated 19.0.0 */
639
-		$this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class);
640
-		$this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
641
-
642
-		$this->registerService(IFactory::class, function (Server $c) {
643
-			return new \OC\L10N\Factory(
644
-				$c->get(\OCP\IConfig::class),
645
-				$c->getRequest(),
646
-				$c->get(IUserSession::class),
647
-				\OC::$SERVERROOT
648
-			);
649
-		});
650
-		/** @deprecated 19.0.0 */
651
-		$this->registerDeprecatedAlias('L10NFactory', IFactory::class);
652
-
653
-		$this->registerAlias(IURLGenerator::class, URLGenerator::class);
654
-		/** @deprecated 19.0.0 */
655
-		$this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class);
656
-
657
-		/** @deprecated 19.0.0 */
658
-		$this->registerDeprecatedAlias('AppFetcher', AppFetcher::class);
659
-		/** @deprecated 19.0.0 */
660
-		$this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class);
661
-
662
-		$this->registerService(ICache::class, function ($c) {
663
-			return new Cache\File();
664
-		});
665
-		/** @deprecated 19.0.0 */
666
-		$this->registerDeprecatedAlias('UserCache', ICache::class);
667
-
668
-		$this->registerService(Factory::class, function (Server $c) {
669
-			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class),
670
-				ArrayCache::class,
671
-				ArrayCache::class,
672
-				ArrayCache::class
673
-			);
674
-			/** @var \OCP\IConfig $config */
675
-			$config = $c->get(\OCP\IConfig::class);
676
-
677
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
678
-				$v = \OC_App::getAppVersions();
679
-				$v['core'] = implode(',', \OC_Util::getVersion());
680
-				$version = implode(',', $v);
681
-				$instanceId = \OC_Util::getInstanceId();
682
-				$path = \OC::$SERVERROOT;
683
-				$prefix = md5($instanceId . '-' . $version . '-' . $path);
684
-				return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class),
685
-					$config->getSystemValue('memcache.local', null),
686
-					$config->getSystemValue('memcache.distributed', null),
687
-					$config->getSystemValue('memcache.locking', null)
688
-				);
689
-			}
690
-			return $arrayCacheFactory;
691
-		});
692
-		/** @deprecated 19.0.0 */
693
-		$this->registerDeprecatedAlias('MemCacheFactory', Factory::class);
694
-		$this->registerAlias(ICacheFactory::class, Factory::class);
695
-
696
-		$this->registerService('RedisFactory', function (Server $c) {
697
-			$systemConfig = $c->get(SystemConfig::class);
698
-			return new RedisFactory($systemConfig);
699
-		});
700
-
701
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
702
-			$l10n = $this->get(IFactory::class)->get('lib');
703
-			return new \OC\Activity\Manager(
704
-				$c->getRequest(),
705
-				$c->get(IUserSession::class),
706
-				$c->get(\OCP\IConfig::class),
707
-				$c->get(IValidator::class),
708
-				$l10n
709
-			);
710
-		});
711
-		/** @deprecated 19.0.0 */
712
-		$this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class);
713
-
714
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
715
-			return new \OC\Activity\EventMerger(
716
-				$c->getL10N('lib')
717
-			);
718
-		});
719
-		$this->registerAlias(IValidator::class, Validator::class);
720
-
721
-		$this->registerService(AvatarManager::class, function (Server $c) {
722
-			return new AvatarManager(
723
-				$c->get(\OC\User\Manager::class),
724
-				$c->getAppDataDir('avatar'),
725
-				$c->getL10N('lib'),
726
-				$c->get(ILogger::class),
727
-				$c->get(\OCP\IConfig::class)
728
-			);
729
-		});
730
-		$this->registerAlias(IAvatarManager::class, AvatarManager::class);
731
-		/** @deprecated 19.0.0 */
732
-		$this->registerDeprecatedAlias('AvatarManager', AvatarManager::class);
733
-
734
-		$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
735
-		$this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
736
-
737
-		$this->registerService(\OC\Log::class, function (Server $c) {
738
-			$logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file');
739
-			$factory = new LogFactory($c, $this->get(SystemConfig::class));
740
-			$logger = $factory->get($logType);
741
-			$registry = $c->get(\OCP\Support\CrashReport\IRegistry::class);
742
-
743
-			return new Log($logger, $this->get(SystemConfig::class), null, $registry);
744
-		});
745
-		$this->registerAlias(ILogger::class, \OC\Log::class);
746
-		/** @deprecated 19.0.0 */
747
-		$this->registerDeprecatedAlias('Logger', \OC\Log::class);
748
-		// PSR-3 logger
749
-		$this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
750
-
751
-		$this->registerService(ILogFactory::class, function (Server $c) {
752
-			return new LogFactory($c, $this->get(SystemConfig::class));
753
-		});
754
-
755
-		$this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class);
756
-		/** @deprecated 19.0.0 */
757
-		$this->registerDeprecatedAlias('JobList', IJobList::class);
758
-
759
-		$this->registerService(Router::class, function (Server $c) {
760
-			$cacheFactory = $c->get(ICacheFactory::class);
761
-			$logger = $c->get(ILogger::class);
762
-			if ($cacheFactory->isLocalCacheAvailable()) {
763
-				$router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
764
-			} else {
765
-				$router = new \OC\Route\Router($logger);
766
-			}
767
-			return $router;
768
-		});
769
-		$this->registerAlias(IRouter::class, Router::class);
770
-		/** @deprecated 19.0.0 */
771
-		$this->registerDeprecatedAlias('Router', IRouter::class);
772
-
773
-		$this->registerAlias(ISearch::class, Search::class);
774
-		/** @deprecated 19.0.0 */
775
-		$this->registerDeprecatedAlias('Search', ISearch::class);
776
-
777
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
778
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
779
-				$this->get(ICacheFactory::class),
780
-				new \OC\AppFramework\Utility\TimeFactory()
781
-			);
782
-		});
783
-
784
-		$this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class);
785
-		/** @deprecated 19.0.0 */
786
-		$this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
787
-
788
-		$this->registerAlias(ICrypto::class, Crypto::class);
789
-		/** @deprecated 19.0.0 */
790
-		$this->registerDeprecatedAlias('Crypto', ICrypto::class);
791
-
792
-		$this->registerAlias(IHasher::class, Hasher::class);
793
-		/** @deprecated 19.0.0 */
794
-		$this->registerDeprecatedAlias('Hasher', IHasher::class);
795
-
796
-		$this->registerAlias(ICredentialsManager::class, CredentialsManager::class);
797
-		/** @deprecated 19.0.0 */
798
-		$this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class);
799
-
800
-		$this->registerAlias(IDBConnection::class, ConnectionAdapter::class);
801
-		$this->registerService(Connection::class, function (Server $c) {
802
-			$systemConfig = $c->get(SystemConfig::class);
803
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
804
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
805
-			if (!$factory->isValidType($type)) {
806
-				throw new \OC\DatabaseException('Invalid database type');
807
-			}
808
-			$connectionParams = $factory->createConnectionParams();
809
-			$connection = $factory->getConnection($type, $connectionParams);
810
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
811
-			return $connection;
812
-		});
813
-		/** @deprecated 19.0.0 */
814
-		$this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class);
815
-
816
-		$this->registerAlias(ICertificateManager::class, CertificateManager::class);
817
-		$this->registerAlias(IClientService::class, ClientService::class);
818
-		$this->registerDeprecatedAlias('HttpClientService', IClientService::class);
819
-		$this->registerService(IEventLogger::class, function (ContainerInterface $c) {
820
-			$eventLogger = new EventLogger();
821
-			if ($c->get(SystemConfig::class)->getValue('debug', false)) {
822
-				// In debug mode, module is being activated by default
823
-				$eventLogger->activate();
824
-			}
825
-			return $eventLogger;
826
-		});
827
-		/** @deprecated 19.0.0 */
828
-		$this->registerDeprecatedAlias('EventLogger', IEventLogger::class);
829
-
830
-		$this->registerService(IQueryLogger::class, function (ContainerInterface $c) {
831
-			$queryLogger = new QueryLogger();
832
-			if ($c->get(SystemConfig::class)->getValue('debug', false)) {
833
-				// In debug mode, module is being activated by default
834
-				$queryLogger->activate();
835
-			}
836
-			return $queryLogger;
837
-		});
838
-		/** @deprecated 19.0.0 */
839
-		$this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class);
840
-
841
-		/** @deprecated 19.0.0 */
842
-		$this->registerDeprecatedAlias('TempManager', TempManager::class);
843
-		$this->registerAlias(ITempManager::class, TempManager::class);
844
-
845
-		$this->registerService(AppManager::class, function (ContainerInterface $c) {
846
-			// TODO: use auto-wiring
847
-			return new \OC\App\AppManager(
848
-				$c->get(IUserSession::class),
849
-				$c->get(\OCP\IConfig::class),
850
-				$c->get(\OC\AppConfig::class),
851
-				$c->get(IGroupManager::class),
852
-				$c->get(ICacheFactory::class),
853
-				$c->get(SymfonyAdapter::class),
854
-				$c->get(ILogger::class)
855
-			);
856
-		});
857
-		/** @deprecated 19.0.0 */
858
-		$this->registerDeprecatedAlias('AppManager', AppManager::class);
859
-		$this->registerAlias(IAppManager::class, AppManager::class);
860
-
861
-		$this->registerAlias(IDateTimeZone::class, DateTimeZone::class);
862
-		/** @deprecated 19.0.0 */
863
-		$this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class);
864
-
865
-		$this->registerService(IDateTimeFormatter::class, function (Server $c) {
866
-			$language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null);
867
-
868
-			return new DateTimeFormatter(
869
-				$c->get(IDateTimeZone::class)->getTimeZone(),
870
-				$c->getL10N('lib', $language)
871
-			);
872
-		});
873
-		/** @deprecated 19.0.0 */
874
-		$this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class);
875
-
876
-		$this->registerService(IUserMountCache::class, function (ContainerInterface $c) {
877
-			$mountCache = new UserMountCache(
878
-				$c->get(IDBConnection::class),
879
-				$c->get(IUserManager::class),
880
-				$c->get(ILogger::class)
881
-			);
882
-			$listener = new UserMountCacheListener($mountCache);
883
-			$listener->listen($c->get(IUserManager::class));
884
-			return $mountCache;
885
-		});
886
-		/** @deprecated 19.0.0 */
887
-		$this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class);
888
-
889
-		$this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) {
890
-			$loader = \OC\Files\Filesystem::getLoader();
891
-			$mountCache = $c->get(IUserMountCache::class);
892
-			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
893
-
894
-			// builtin providers
895
-
896
-			$config = $c->get(\OCP\IConfig::class);
897
-			$logger = $c->get(ILogger::class);
898
-			$manager->registerProvider(new CacheMountProvider($config));
899
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
900
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
901
-			$manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config));
902
-
903
-			return $manager;
904
-		});
905
-		/** @deprecated 19.0.0 */
906
-		$this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class);
907
-
908
-		/** @deprecated 20.0.0 */
909
-		$this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class);
910
-		$this->registerService(IBus::class, function (ContainerInterface $c) {
911
-			$busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus');
912
-			if ($busClass) {
913
-				[$app, $class] = explode('::', $busClass, 2);
914
-				if ($c->get(IAppManager::class)->isInstalled($app)) {
915
-					\OC_App::loadApp($app);
916
-					return $c->get($class);
917
-				} else {
918
-					throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
919
-				}
920
-			} else {
921
-				$jobList = $c->get(IJobList::class);
922
-				return new CronBus($jobList);
923
-			}
924
-		});
925
-		$this->registerDeprecatedAlias('AsyncCommandBus', IBus::class);
926
-		/** @deprecated 20.0.0 */
927
-		$this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class);
928
-		/** @deprecated 19.0.0 */
929
-		$this->registerDeprecatedAlias('Throttler', Throttler::class);
930
-		$this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) {
931
-			// IConfig and IAppManager requires a working database. This code
932
-			// might however be called when ownCloud is not yet setup.
933
-			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
934
-				$config = $c->get(\OCP\IConfig::class);
935
-				$appManager = $c->get(IAppManager::class);
936
-			} else {
937
-				$config = null;
938
-				$appManager = null;
939
-			}
940
-
941
-			return new Checker(
942
-				new EnvironmentHelper(),
943
-				new FileAccessHelper(),
944
-				new AppLocator(),
945
-				$config,
946
-				$c->get(ICacheFactory::class),
947
-				$appManager,
948
-				$c->get(IMimeTypeDetector::class)
949
-			);
950
-		});
951
-		$this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) {
952
-			if (isset($this['urlParams'])) {
953
-				$urlParams = $this['urlParams'];
954
-			} else {
955
-				$urlParams = [];
956
-			}
957
-
958
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
959
-				&& in_array('fakeinput', stream_get_wrappers())
960
-			) {
961
-				$stream = 'fakeinput://data';
962
-			} else {
963
-				$stream = 'php://input';
964
-			}
965
-
966
-			return new Request(
967
-				[
968
-					'get' => $_GET,
969
-					'post' => $_POST,
970
-					'files' => $_FILES,
971
-					'server' => $_SERVER,
972
-					'env' => $_ENV,
973
-					'cookies' => $_COOKIE,
974
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
975
-						? $_SERVER['REQUEST_METHOD']
976
-						: '',
977
-					'urlParams' => $urlParams,
978
-				],
979
-				$this->get(ISecureRandom::class),
980
-				$this->get(\OCP\IConfig::class),
981
-				$this->get(CsrfTokenManager::class),
982
-				$stream
983
-			);
984
-		});
985
-		/** @deprecated 19.0.0 */
986
-		$this->registerDeprecatedAlias('Request', \OCP\IRequest::class);
987
-
988
-		$this->registerService(IMailer::class, function (Server $c) {
989
-			return new Mailer(
990
-				$c->get(\OCP\IConfig::class),
991
-				$c->get(ILogger::class),
992
-				$c->get(Defaults::class),
993
-				$c->get(IURLGenerator::class),
994
-				$c->getL10N('lib'),
995
-				$c->get(IEventDispatcher::class),
996
-				$c->get(IFactory::class)
997
-			);
998
-		});
999
-		/** @deprecated 19.0.0 */
1000
-		$this->registerDeprecatedAlias('Mailer', IMailer::class);
1001
-
1002
-		$this->registerService('LDAPProvider', function (ContainerInterface $c) {
1003
-			$config = $c->get(\OCP\IConfig::class);
1004
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
1005
-			if (is_null($factoryClass)) {
1006
-				throw new \Exception('ldapProviderFactory not set');
1007
-			}
1008
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
1009
-			$factory = new $factoryClass($this);
1010
-			return $factory->getLDAPProvider();
1011
-		});
1012
-		$this->registerService(ILockingProvider::class, function (ContainerInterface $c) {
1013
-			$ini = $c->get(IniGetWrapper::class);
1014
-			$config = $c->get(\OCP\IConfig::class);
1015
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
1016
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
1017
-				/** @var \OC\Memcache\Factory $memcacheFactory */
1018
-				$memcacheFactory = $c->get(ICacheFactory::class);
1019
-				$memcache = $memcacheFactory->createLocking('lock');
1020
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
1021
-					return new MemcacheLockingProvider($memcache, $ttl);
1022
-				}
1023
-				return new DBLockingProvider(
1024
-					$c->get(IDBConnection::class),
1025
-					$c->get(ILogger::class),
1026
-					new TimeFactory(),
1027
-					$ttl,
1028
-					!\OC::$CLI
1029
-				);
1030
-			}
1031
-			return new NoopLockingProvider();
1032
-		});
1033
-		/** @deprecated 19.0.0 */
1034
-		$this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class);
1035
-
1036
-		$this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class);
1037
-		/** @deprecated 19.0.0 */
1038
-		$this->registerDeprecatedAlias('MountManager', IMountManager::class);
1039
-
1040
-		$this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) {
1041
-			return new \OC\Files\Type\Detection(
1042
-				$c->get(IURLGenerator::class),
1043
-				$c->get(ILogger::class),
1044
-				\OC::$configDir,
1045
-				\OC::$SERVERROOT . '/resources/config/'
1046
-			);
1047
-		});
1048
-		/** @deprecated 19.0.0 */
1049
-		$this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class);
1050
-
1051
-		$this->registerAlias(IMimeTypeLoader::class, Loader::class);
1052
-		/** @deprecated 19.0.0 */
1053
-		$this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class);
1054
-		$this->registerService(BundleFetcher::class, function () {
1055
-			return new BundleFetcher($this->getL10N('lib'));
1056
-		});
1057
-		$this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
1058
-		/** @deprecated 19.0.0 */
1059
-		$this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class);
1060
-
1061
-		$this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) {
1062
-			$manager = new CapabilitiesManager($c->get(ILogger::class));
1063
-			$manager->registerCapability(function () use ($c) {
1064
-				return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class));
1065
-			});
1066
-			$manager->registerCapability(function () use ($c) {
1067
-				return $c->get(\OC\Security\Bruteforce\Capabilities::class);
1068
-			});
1069
-			return $manager;
1070
-		});
1071
-		/** @deprecated 19.0.0 */
1072
-		$this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class);
1073
-
1074
-		$this->registerService(ICommentsManager::class, function (Server $c) {
1075
-			$config = $c->get(\OCP\IConfig::class);
1076
-			$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
1077
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
1078
-			$factory = new $factoryClass($this);
1079
-			$manager = $factory->getManager();
1080
-
1081
-			$manager->registerDisplayNameResolver('user', function ($id) use ($c) {
1082
-				$manager = $c->get(IUserManager::class);
1083
-				$user = $manager->get($id);
1084
-				if (is_null($user)) {
1085
-					$l = $c->getL10N('core');
1086
-					$displayName = $l->t('Unknown user');
1087
-				} else {
1088
-					$displayName = $user->getDisplayName();
1089
-				}
1090
-				return $displayName;
1091
-			});
1092
-
1093
-			return $manager;
1094
-		});
1095
-		/** @deprecated 19.0.0 */
1096
-		$this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class);
1097
-
1098
-		$this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
1099
-		$this->registerService('ThemingDefaults', function (Server $c) {
1100
-			/*
255
+    /** @var string */
256
+    private $webRoot;
257
+
258
+    /**
259
+     * @param string $webRoot
260
+     * @param \OC\Config $config
261
+     */
262
+    public function __construct($webRoot, \OC\Config $config) {
263
+        parent::__construct();
264
+        $this->webRoot = $webRoot;
265
+
266
+        // To find out if we are running from CLI or not
267
+        $this->registerParameter('isCLI', \OC::$CLI);
268
+        $this->registerParameter('serverRoot', \OC::$SERVERROOT);
269
+
270
+        $this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
271
+            return $c;
272
+        });
273
+        $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) {
274
+            return $c;
275
+        });
276
+
277
+        $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
278
+        /** @deprecated 19.0.0 */
279
+        $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class);
280
+
281
+        $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
282
+        /** @deprecated 19.0.0 */
283
+        $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
284
+
285
+        $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
286
+        /** @deprecated 19.0.0 */
287
+        $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
288
+
289
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
290
+        /** @deprecated 19.0.0 */
291
+        $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class);
292
+
293
+        $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
294
+        $this->registerAlias(ITemplateManager::class, TemplateManager::class);
295
+
296
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
297
+
298
+        $this->registerService(View::class, function (Server $c) {
299
+            return new View();
300
+        }, false);
301
+
302
+        $this->registerService(IPreview::class, function (ContainerInterface $c) {
303
+            return new PreviewManager(
304
+                $c->get(\OCP\IConfig::class),
305
+                $c->get(IRootFolder::class),
306
+                new \OC\Preview\Storage\Root(
307
+                    $c->get(IRootFolder::class),
308
+                    $c->get(SystemConfig::class)
309
+                ),
310
+                $c->get(SymfonyAdapter::class),
311
+                $c->get(GeneratorHelper::class),
312
+                $c->get(ISession::class)->get('user_id')
313
+            );
314
+        });
315
+        /** @deprecated 19.0.0 */
316
+        $this->registerDeprecatedAlias('PreviewManager', IPreview::class);
317
+
318
+        $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) {
319
+            return new \OC\Preview\Watcher(
320
+                new \OC\Preview\Storage\Root(
321
+                    $c->get(IRootFolder::class),
322
+                    $c->get(SystemConfig::class)
323
+                )
324
+            );
325
+        });
326
+
327
+        $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
328
+            $view = new View();
329
+            $util = new Encryption\Util(
330
+                $view,
331
+                $c->get(IUserManager::class),
332
+                $c->get(IGroupManager::class),
333
+                $c->get(\OCP\IConfig::class)
334
+            );
335
+            return new Encryption\Manager(
336
+                $c->get(\OCP\IConfig::class),
337
+                $c->get(ILogger::class),
338
+                $c->getL10N('core'),
339
+                new View(),
340
+                $util,
341
+                new ArrayCache()
342
+            );
343
+        });
344
+        /** @deprecated 19.0.0 */
345
+        $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class);
346
+
347
+        /** @deprecated 21.0.0 */
348
+        $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class);
349
+        $this->registerService(IFile::class, function (ContainerInterface $c) {
350
+            $util = new Encryption\Util(
351
+                new View(),
352
+                $c->get(IUserManager::class),
353
+                $c->get(IGroupManager::class),
354
+                $c->get(\OCP\IConfig::class)
355
+            );
356
+            return new Encryption\File(
357
+                $util,
358
+                $c->get(IRootFolder::class),
359
+                $c->get(\OCP\Share\IManager::class)
360
+            );
361
+        });
362
+
363
+        /** @deprecated 21.0.0 */
364
+        $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class);
365
+        $this->registerService(IStorage::class, function (ContainerInterface $c) {
366
+            $view = new View();
367
+            $util = new Encryption\Util(
368
+                $view,
369
+                $c->get(IUserManager::class),
370
+                $c->get(IGroupManager::class),
371
+                $c->get(\OCP\IConfig::class)
372
+            );
373
+
374
+            return new Encryption\Keys\Storage(
375
+                $view,
376
+                $util,
377
+                $c->get(ICrypto::class),
378
+                $c->get(\OCP\IConfig::class)
379
+            );
380
+        });
381
+        /** @deprecated 20.0.0 */
382
+        $this->registerDeprecatedAlias('TagMapper', TagMapper::class);
383
+
384
+        $this->registerAlias(\OCP\ITagManager::class, TagManager::class);
385
+        /** @deprecated 19.0.0 */
386
+        $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class);
387
+
388
+        $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) {
389
+            /** @var \OCP\IConfig $config */
390
+            $config = $c->get(\OCP\IConfig::class);
391
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
392
+            return new $factoryClass($this);
393
+        });
394
+        $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) {
395
+            return $c->get('SystemTagManagerFactory')->getManager();
396
+        });
397
+        /** @deprecated 19.0.0 */
398
+        $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
399
+
400
+        $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) {
401
+            return $c->get('SystemTagManagerFactory')->getObjectMapper();
402
+        });
403
+        $this->registerService('RootFolder', function (ContainerInterface $c) {
404
+            $manager = \OC\Files\Filesystem::getMountManager(null);
405
+            $view = new View();
406
+            $root = new Root(
407
+                $manager,
408
+                $view,
409
+                null,
410
+                $c->get(IUserMountCache::class),
411
+                $this->get(ILogger::class),
412
+                $this->get(IUserManager::class)
413
+            );
414
+
415
+            $previewConnector = new \OC\Preview\WatcherConnector(
416
+                $root,
417
+                $c->get(SystemConfig::class)
418
+            );
419
+            $previewConnector->connectWatcher();
420
+
421
+            return $root;
422
+        });
423
+        $this->registerService(HookConnector::class, function (ContainerInterface $c) {
424
+            return new HookConnector(
425
+                $c->get(IRootFolder::class),
426
+                new View(),
427
+                $c->get(\OC\EventDispatcher\SymfonyAdapter::class),
428
+                $c->get(IEventDispatcher::class)
429
+            );
430
+        });
431
+
432
+        /** @deprecated 19.0.0 */
433
+        $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class);
434
+
435
+        $this->registerService(IRootFolder::class, function (ContainerInterface $c) {
436
+            return new LazyRoot(function () use ($c) {
437
+                return $c->get('RootFolder');
438
+            });
439
+        });
440
+        /** @deprecated 19.0.0 */
441
+        $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class);
442
+
443
+        /** @deprecated 19.0.0 */
444
+        $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class);
445
+        $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
446
+
447
+        $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) {
448
+            $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class));
449
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
450
+                /** @var IEventDispatcher $dispatcher */
451
+                $dispatcher = $this->get(IEventDispatcher::class);
452
+                $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid));
453
+            });
454
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) {
455
+                /** @var IEventDispatcher $dispatcher */
456
+                $dispatcher = $this->get(IEventDispatcher::class);
457
+                $dispatcher->dispatchTyped(new GroupCreatedEvent($group));
458
+            });
459
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
460
+                /** @var IEventDispatcher $dispatcher */
461
+                $dispatcher = $this->get(IEventDispatcher::class);
462
+                $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group));
463
+            });
464
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
465
+                /** @var IEventDispatcher $dispatcher */
466
+                $dispatcher = $this->get(IEventDispatcher::class);
467
+                $dispatcher->dispatchTyped(new GroupDeletedEvent($group));
468
+            });
469
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
470
+                /** @var IEventDispatcher $dispatcher */
471
+                $dispatcher = $this->get(IEventDispatcher::class);
472
+                $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user));
473
+            });
474
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
475
+                /** @var IEventDispatcher $dispatcher */
476
+                $dispatcher = $this->get(IEventDispatcher::class);
477
+                $dispatcher->dispatchTyped(new UserAddedEvent($group, $user));
478
+            });
479
+            $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
480
+                /** @var IEventDispatcher $dispatcher */
481
+                $dispatcher = $this->get(IEventDispatcher::class);
482
+                $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user));
483
+            });
484
+            $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
485
+                /** @var IEventDispatcher $dispatcher */
486
+                $dispatcher = $this->get(IEventDispatcher::class);
487
+                $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user));
488
+            });
489
+            return $groupManager;
490
+        });
491
+        /** @deprecated 19.0.0 */
492
+        $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class);
493
+
494
+        $this->registerService(Store::class, function (ContainerInterface $c) {
495
+            $session = $c->get(ISession::class);
496
+            if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
497
+                $tokenProvider = $c->get(IProvider::class);
498
+            } else {
499
+                $tokenProvider = null;
500
+            }
501
+            $logger = $c->get(LoggerInterface::class);
502
+            return new Store($session, $logger, $tokenProvider);
503
+        });
504
+        $this->registerAlias(IStore::class, Store::class);
505
+        $this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
506
+
507
+        $this->registerService(\OC\User\Session::class, function (Server $c) {
508
+            $manager = $c->get(IUserManager::class);
509
+            $session = new \OC\Session\Memory('');
510
+            $timeFactory = new TimeFactory();
511
+            // Token providers might require a working database. This code
512
+            // might however be called when ownCloud is not yet setup.
513
+            if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
514
+                $defaultTokenProvider = $c->get(IProvider::class);
515
+            } else {
516
+                $defaultTokenProvider = null;
517
+            }
518
+
519
+            $legacyDispatcher = $c->get(SymfonyAdapter::class);
520
+
521
+            $userSession = new \OC\User\Session(
522
+                $manager,
523
+                $session,
524
+                $timeFactory,
525
+                $defaultTokenProvider,
526
+                $c->get(\OCP\IConfig::class),
527
+                $c->get(ISecureRandom::class),
528
+                $c->getLockdownManager(),
529
+                $c->get(ILogger::class),
530
+                $c->get(IEventDispatcher::class)
531
+            );
532
+            /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */
533
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
534
+                \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
535
+            });
536
+            /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */
537
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
538
+                /** @var \OC\User\User $user */
539
+                \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
540
+            });
541
+            /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
542
+            $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) {
543
+                /** @var \OC\User\User $user */
544
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
545
+                $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
546
+            });
547
+            /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
548
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
549
+                /** @var \OC\User\User $user */
550
+                \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
551
+            });
552
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
553
+                /** @var \OC\User\User $user */
554
+                \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
555
+
556
+                /** @var IEventDispatcher $dispatcher */
557
+                $dispatcher = $this->get(IEventDispatcher::class);
558
+                $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword));
559
+            });
560
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
561
+                /** @var \OC\User\User $user */
562
+                \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
563
+
564
+                /** @var IEventDispatcher $dispatcher */
565
+                $dispatcher = $this->get(IEventDispatcher::class);
566
+                $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword));
567
+            });
568
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
569
+                \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
570
+
571
+                /** @var IEventDispatcher $dispatcher */
572
+                $dispatcher = $this->get(IEventDispatcher::class);
573
+                $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
574
+            });
575
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) {
576
+                /** @var \OC\User\User $user */
577
+                \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
578
+
579
+                /** @var IEventDispatcher $dispatcher */
580
+                $dispatcher = $this->get(IEventDispatcher::class);
581
+                $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin));
582
+            });
583
+            $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
584
+                /** @var IEventDispatcher $dispatcher */
585
+                $dispatcher = $this->get(IEventDispatcher::class);
586
+                $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
587
+            });
588
+            $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
589
+                /** @var \OC\User\User $user */
590
+                \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
591
+
592
+                /** @var IEventDispatcher $dispatcher */
593
+                $dispatcher = $this->get(IEventDispatcher::class);
594
+                $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
595
+            });
596
+            $userSession->listen('\OC\User', 'logout', function ($user) {
597
+                \OC_Hook::emit('OC_User', 'logout', []);
598
+
599
+                /** @var IEventDispatcher $dispatcher */
600
+                $dispatcher = $this->get(IEventDispatcher::class);
601
+                $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
602
+            });
603
+            $userSession->listen('\OC\User', 'postLogout', function ($user) {
604
+                /** @var IEventDispatcher $dispatcher */
605
+                $dispatcher = $this->get(IEventDispatcher::class);
606
+                $dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
607
+            });
608
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
609
+                /** @var \OC\User\User $user */
610
+                \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
611
+
612
+                /** @var IEventDispatcher $dispatcher */
613
+                $dispatcher = $this->get(IEventDispatcher::class);
614
+                $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue));
615
+            });
616
+            return $userSession;
617
+        });
618
+        $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
619
+        /** @deprecated 19.0.0 */
620
+        $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class);
621
+
622
+        $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
623
+
624
+        $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class);
625
+        /** @deprecated 19.0.0 */
626
+        $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class);
627
+
628
+        /** @deprecated 19.0.0 */
629
+        $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class);
630
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
631
+
632
+        $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
633
+            return new \OC\SystemConfig($config);
634
+        });
635
+        /** @deprecated 19.0.0 */
636
+        $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class);
637
+
638
+        /** @deprecated 19.0.0 */
639
+        $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class);
640
+        $this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
641
+
642
+        $this->registerService(IFactory::class, function (Server $c) {
643
+            return new \OC\L10N\Factory(
644
+                $c->get(\OCP\IConfig::class),
645
+                $c->getRequest(),
646
+                $c->get(IUserSession::class),
647
+                \OC::$SERVERROOT
648
+            );
649
+        });
650
+        /** @deprecated 19.0.0 */
651
+        $this->registerDeprecatedAlias('L10NFactory', IFactory::class);
652
+
653
+        $this->registerAlias(IURLGenerator::class, URLGenerator::class);
654
+        /** @deprecated 19.0.0 */
655
+        $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class);
656
+
657
+        /** @deprecated 19.0.0 */
658
+        $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class);
659
+        /** @deprecated 19.0.0 */
660
+        $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class);
661
+
662
+        $this->registerService(ICache::class, function ($c) {
663
+            return new Cache\File();
664
+        });
665
+        /** @deprecated 19.0.0 */
666
+        $this->registerDeprecatedAlias('UserCache', ICache::class);
667
+
668
+        $this->registerService(Factory::class, function (Server $c) {
669
+            $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class),
670
+                ArrayCache::class,
671
+                ArrayCache::class,
672
+                ArrayCache::class
673
+            );
674
+            /** @var \OCP\IConfig $config */
675
+            $config = $c->get(\OCP\IConfig::class);
676
+
677
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
678
+                $v = \OC_App::getAppVersions();
679
+                $v['core'] = implode(',', \OC_Util::getVersion());
680
+                $version = implode(',', $v);
681
+                $instanceId = \OC_Util::getInstanceId();
682
+                $path = \OC::$SERVERROOT;
683
+                $prefix = md5($instanceId . '-' . $version . '-' . $path);
684
+                return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class),
685
+                    $config->getSystemValue('memcache.local', null),
686
+                    $config->getSystemValue('memcache.distributed', null),
687
+                    $config->getSystemValue('memcache.locking', null)
688
+                );
689
+            }
690
+            return $arrayCacheFactory;
691
+        });
692
+        /** @deprecated 19.0.0 */
693
+        $this->registerDeprecatedAlias('MemCacheFactory', Factory::class);
694
+        $this->registerAlias(ICacheFactory::class, Factory::class);
695
+
696
+        $this->registerService('RedisFactory', function (Server $c) {
697
+            $systemConfig = $c->get(SystemConfig::class);
698
+            return new RedisFactory($systemConfig);
699
+        });
700
+
701
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
702
+            $l10n = $this->get(IFactory::class)->get('lib');
703
+            return new \OC\Activity\Manager(
704
+                $c->getRequest(),
705
+                $c->get(IUserSession::class),
706
+                $c->get(\OCP\IConfig::class),
707
+                $c->get(IValidator::class),
708
+                $l10n
709
+            );
710
+        });
711
+        /** @deprecated 19.0.0 */
712
+        $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class);
713
+
714
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
715
+            return new \OC\Activity\EventMerger(
716
+                $c->getL10N('lib')
717
+            );
718
+        });
719
+        $this->registerAlias(IValidator::class, Validator::class);
720
+
721
+        $this->registerService(AvatarManager::class, function (Server $c) {
722
+            return new AvatarManager(
723
+                $c->get(\OC\User\Manager::class),
724
+                $c->getAppDataDir('avatar'),
725
+                $c->getL10N('lib'),
726
+                $c->get(ILogger::class),
727
+                $c->get(\OCP\IConfig::class)
728
+            );
729
+        });
730
+        $this->registerAlias(IAvatarManager::class, AvatarManager::class);
731
+        /** @deprecated 19.0.0 */
732
+        $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class);
733
+
734
+        $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
735
+        $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
736
+
737
+        $this->registerService(\OC\Log::class, function (Server $c) {
738
+            $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file');
739
+            $factory = new LogFactory($c, $this->get(SystemConfig::class));
740
+            $logger = $factory->get($logType);
741
+            $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class);
742
+
743
+            return new Log($logger, $this->get(SystemConfig::class), null, $registry);
744
+        });
745
+        $this->registerAlias(ILogger::class, \OC\Log::class);
746
+        /** @deprecated 19.0.0 */
747
+        $this->registerDeprecatedAlias('Logger', \OC\Log::class);
748
+        // PSR-3 logger
749
+        $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
750
+
751
+        $this->registerService(ILogFactory::class, function (Server $c) {
752
+            return new LogFactory($c, $this->get(SystemConfig::class));
753
+        });
754
+
755
+        $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class);
756
+        /** @deprecated 19.0.0 */
757
+        $this->registerDeprecatedAlias('JobList', IJobList::class);
758
+
759
+        $this->registerService(Router::class, function (Server $c) {
760
+            $cacheFactory = $c->get(ICacheFactory::class);
761
+            $logger = $c->get(ILogger::class);
762
+            if ($cacheFactory->isLocalCacheAvailable()) {
763
+                $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
764
+            } else {
765
+                $router = new \OC\Route\Router($logger);
766
+            }
767
+            return $router;
768
+        });
769
+        $this->registerAlias(IRouter::class, Router::class);
770
+        /** @deprecated 19.0.0 */
771
+        $this->registerDeprecatedAlias('Router', IRouter::class);
772
+
773
+        $this->registerAlias(ISearch::class, Search::class);
774
+        /** @deprecated 19.0.0 */
775
+        $this->registerDeprecatedAlias('Search', ISearch::class);
776
+
777
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
778
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
779
+                $this->get(ICacheFactory::class),
780
+                new \OC\AppFramework\Utility\TimeFactory()
781
+            );
782
+        });
783
+
784
+        $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class);
785
+        /** @deprecated 19.0.0 */
786
+        $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
787
+
788
+        $this->registerAlias(ICrypto::class, Crypto::class);
789
+        /** @deprecated 19.0.0 */
790
+        $this->registerDeprecatedAlias('Crypto', ICrypto::class);
791
+
792
+        $this->registerAlias(IHasher::class, Hasher::class);
793
+        /** @deprecated 19.0.0 */
794
+        $this->registerDeprecatedAlias('Hasher', IHasher::class);
795
+
796
+        $this->registerAlias(ICredentialsManager::class, CredentialsManager::class);
797
+        /** @deprecated 19.0.0 */
798
+        $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class);
799
+
800
+        $this->registerAlias(IDBConnection::class, ConnectionAdapter::class);
801
+        $this->registerService(Connection::class, function (Server $c) {
802
+            $systemConfig = $c->get(SystemConfig::class);
803
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
804
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
805
+            if (!$factory->isValidType($type)) {
806
+                throw new \OC\DatabaseException('Invalid database type');
807
+            }
808
+            $connectionParams = $factory->createConnectionParams();
809
+            $connection = $factory->getConnection($type, $connectionParams);
810
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
811
+            return $connection;
812
+        });
813
+        /** @deprecated 19.0.0 */
814
+        $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class);
815
+
816
+        $this->registerAlias(ICertificateManager::class, CertificateManager::class);
817
+        $this->registerAlias(IClientService::class, ClientService::class);
818
+        $this->registerDeprecatedAlias('HttpClientService', IClientService::class);
819
+        $this->registerService(IEventLogger::class, function (ContainerInterface $c) {
820
+            $eventLogger = new EventLogger();
821
+            if ($c->get(SystemConfig::class)->getValue('debug', false)) {
822
+                // In debug mode, module is being activated by default
823
+                $eventLogger->activate();
824
+            }
825
+            return $eventLogger;
826
+        });
827
+        /** @deprecated 19.0.0 */
828
+        $this->registerDeprecatedAlias('EventLogger', IEventLogger::class);
829
+
830
+        $this->registerService(IQueryLogger::class, function (ContainerInterface $c) {
831
+            $queryLogger = new QueryLogger();
832
+            if ($c->get(SystemConfig::class)->getValue('debug', false)) {
833
+                // In debug mode, module is being activated by default
834
+                $queryLogger->activate();
835
+            }
836
+            return $queryLogger;
837
+        });
838
+        /** @deprecated 19.0.0 */
839
+        $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class);
840
+
841
+        /** @deprecated 19.0.0 */
842
+        $this->registerDeprecatedAlias('TempManager', TempManager::class);
843
+        $this->registerAlias(ITempManager::class, TempManager::class);
844
+
845
+        $this->registerService(AppManager::class, function (ContainerInterface $c) {
846
+            // TODO: use auto-wiring
847
+            return new \OC\App\AppManager(
848
+                $c->get(IUserSession::class),
849
+                $c->get(\OCP\IConfig::class),
850
+                $c->get(\OC\AppConfig::class),
851
+                $c->get(IGroupManager::class),
852
+                $c->get(ICacheFactory::class),
853
+                $c->get(SymfonyAdapter::class),
854
+                $c->get(ILogger::class)
855
+            );
856
+        });
857
+        /** @deprecated 19.0.0 */
858
+        $this->registerDeprecatedAlias('AppManager', AppManager::class);
859
+        $this->registerAlias(IAppManager::class, AppManager::class);
860
+
861
+        $this->registerAlias(IDateTimeZone::class, DateTimeZone::class);
862
+        /** @deprecated 19.0.0 */
863
+        $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class);
864
+
865
+        $this->registerService(IDateTimeFormatter::class, function (Server $c) {
866
+            $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null);
867
+
868
+            return new DateTimeFormatter(
869
+                $c->get(IDateTimeZone::class)->getTimeZone(),
870
+                $c->getL10N('lib', $language)
871
+            );
872
+        });
873
+        /** @deprecated 19.0.0 */
874
+        $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class);
875
+
876
+        $this->registerService(IUserMountCache::class, function (ContainerInterface $c) {
877
+            $mountCache = new UserMountCache(
878
+                $c->get(IDBConnection::class),
879
+                $c->get(IUserManager::class),
880
+                $c->get(ILogger::class)
881
+            );
882
+            $listener = new UserMountCacheListener($mountCache);
883
+            $listener->listen($c->get(IUserManager::class));
884
+            return $mountCache;
885
+        });
886
+        /** @deprecated 19.0.0 */
887
+        $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class);
888
+
889
+        $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) {
890
+            $loader = \OC\Files\Filesystem::getLoader();
891
+            $mountCache = $c->get(IUserMountCache::class);
892
+            $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
893
+
894
+            // builtin providers
895
+
896
+            $config = $c->get(\OCP\IConfig::class);
897
+            $logger = $c->get(ILogger::class);
898
+            $manager->registerProvider(new CacheMountProvider($config));
899
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
900
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
901
+            $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config));
902
+
903
+            return $manager;
904
+        });
905
+        /** @deprecated 19.0.0 */
906
+        $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class);
907
+
908
+        /** @deprecated 20.0.0 */
909
+        $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class);
910
+        $this->registerService(IBus::class, function (ContainerInterface $c) {
911
+            $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus');
912
+            if ($busClass) {
913
+                [$app, $class] = explode('::', $busClass, 2);
914
+                if ($c->get(IAppManager::class)->isInstalled($app)) {
915
+                    \OC_App::loadApp($app);
916
+                    return $c->get($class);
917
+                } else {
918
+                    throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
919
+                }
920
+            } else {
921
+                $jobList = $c->get(IJobList::class);
922
+                return new CronBus($jobList);
923
+            }
924
+        });
925
+        $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class);
926
+        /** @deprecated 20.0.0 */
927
+        $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class);
928
+        /** @deprecated 19.0.0 */
929
+        $this->registerDeprecatedAlias('Throttler', Throttler::class);
930
+        $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) {
931
+            // IConfig and IAppManager requires a working database. This code
932
+            // might however be called when ownCloud is not yet setup.
933
+            if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
934
+                $config = $c->get(\OCP\IConfig::class);
935
+                $appManager = $c->get(IAppManager::class);
936
+            } else {
937
+                $config = null;
938
+                $appManager = null;
939
+            }
940
+
941
+            return new Checker(
942
+                new EnvironmentHelper(),
943
+                new FileAccessHelper(),
944
+                new AppLocator(),
945
+                $config,
946
+                $c->get(ICacheFactory::class),
947
+                $appManager,
948
+                $c->get(IMimeTypeDetector::class)
949
+            );
950
+        });
951
+        $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) {
952
+            if (isset($this['urlParams'])) {
953
+                $urlParams = $this['urlParams'];
954
+            } else {
955
+                $urlParams = [];
956
+            }
957
+
958
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
959
+                && in_array('fakeinput', stream_get_wrappers())
960
+            ) {
961
+                $stream = 'fakeinput://data';
962
+            } else {
963
+                $stream = 'php://input';
964
+            }
965
+
966
+            return new Request(
967
+                [
968
+                    'get' => $_GET,
969
+                    'post' => $_POST,
970
+                    'files' => $_FILES,
971
+                    'server' => $_SERVER,
972
+                    'env' => $_ENV,
973
+                    'cookies' => $_COOKIE,
974
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
975
+                        ? $_SERVER['REQUEST_METHOD']
976
+                        : '',
977
+                    'urlParams' => $urlParams,
978
+                ],
979
+                $this->get(ISecureRandom::class),
980
+                $this->get(\OCP\IConfig::class),
981
+                $this->get(CsrfTokenManager::class),
982
+                $stream
983
+            );
984
+        });
985
+        /** @deprecated 19.0.0 */
986
+        $this->registerDeprecatedAlias('Request', \OCP\IRequest::class);
987
+
988
+        $this->registerService(IMailer::class, function (Server $c) {
989
+            return new Mailer(
990
+                $c->get(\OCP\IConfig::class),
991
+                $c->get(ILogger::class),
992
+                $c->get(Defaults::class),
993
+                $c->get(IURLGenerator::class),
994
+                $c->getL10N('lib'),
995
+                $c->get(IEventDispatcher::class),
996
+                $c->get(IFactory::class)
997
+            );
998
+        });
999
+        /** @deprecated 19.0.0 */
1000
+        $this->registerDeprecatedAlias('Mailer', IMailer::class);
1001
+
1002
+        $this->registerService('LDAPProvider', function (ContainerInterface $c) {
1003
+            $config = $c->get(\OCP\IConfig::class);
1004
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
1005
+            if (is_null($factoryClass)) {
1006
+                throw new \Exception('ldapProviderFactory not set');
1007
+            }
1008
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
1009
+            $factory = new $factoryClass($this);
1010
+            return $factory->getLDAPProvider();
1011
+        });
1012
+        $this->registerService(ILockingProvider::class, function (ContainerInterface $c) {
1013
+            $ini = $c->get(IniGetWrapper::class);
1014
+            $config = $c->get(\OCP\IConfig::class);
1015
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
1016
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
1017
+                /** @var \OC\Memcache\Factory $memcacheFactory */
1018
+                $memcacheFactory = $c->get(ICacheFactory::class);
1019
+                $memcache = $memcacheFactory->createLocking('lock');
1020
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
1021
+                    return new MemcacheLockingProvider($memcache, $ttl);
1022
+                }
1023
+                return new DBLockingProvider(
1024
+                    $c->get(IDBConnection::class),
1025
+                    $c->get(ILogger::class),
1026
+                    new TimeFactory(),
1027
+                    $ttl,
1028
+                    !\OC::$CLI
1029
+                );
1030
+            }
1031
+            return new NoopLockingProvider();
1032
+        });
1033
+        /** @deprecated 19.0.0 */
1034
+        $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class);
1035
+
1036
+        $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class);
1037
+        /** @deprecated 19.0.0 */
1038
+        $this->registerDeprecatedAlias('MountManager', IMountManager::class);
1039
+
1040
+        $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) {
1041
+            return new \OC\Files\Type\Detection(
1042
+                $c->get(IURLGenerator::class),
1043
+                $c->get(ILogger::class),
1044
+                \OC::$configDir,
1045
+                \OC::$SERVERROOT . '/resources/config/'
1046
+            );
1047
+        });
1048
+        /** @deprecated 19.0.0 */
1049
+        $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class);
1050
+
1051
+        $this->registerAlias(IMimeTypeLoader::class, Loader::class);
1052
+        /** @deprecated 19.0.0 */
1053
+        $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class);
1054
+        $this->registerService(BundleFetcher::class, function () {
1055
+            return new BundleFetcher($this->getL10N('lib'));
1056
+        });
1057
+        $this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
1058
+        /** @deprecated 19.0.0 */
1059
+        $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class);
1060
+
1061
+        $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) {
1062
+            $manager = new CapabilitiesManager($c->get(ILogger::class));
1063
+            $manager->registerCapability(function () use ($c) {
1064
+                return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class));
1065
+            });
1066
+            $manager->registerCapability(function () use ($c) {
1067
+                return $c->get(\OC\Security\Bruteforce\Capabilities::class);
1068
+            });
1069
+            return $manager;
1070
+        });
1071
+        /** @deprecated 19.0.0 */
1072
+        $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class);
1073
+
1074
+        $this->registerService(ICommentsManager::class, function (Server $c) {
1075
+            $config = $c->get(\OCP\IConfig::class);
1076
+            $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
1077
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
1078
+            $factory = new $factoryClass($this);
1079
+            $manager = $factory->getManager();
1080
+
1081
+            $manager->registerDisplayNameResolver('user', function ($id) use ($c) {
1082
+                $manager = $c->get(IUserManager::class);
1083
+                $user = $manager->get($id);
1084
+                if (is_null($user)) {
1085
+                    $l = $c->getL10N('core');
1086
+                    $displayName = $l->t('Unknown user');
1087
+                } else {
1088
+                    $displayName = $user->getDisplayName();
1089
+                }
1090
+                return $displayName;
1091
+            });
1092
+
1093
+            return $manager;
1094
+        });
1095
+        /** @deprecated 19.0.0 */
1096
+        $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class);
1097
+
1098
+        $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
1099
+        $this->registerService('ThemingDefaults', function (Server $c) {
1100
+            /*
1101 1101
 			 * Dark magic for autoloader.
1102 1102
 			 * If we do a class_exists it will try to load the class which will
1103 1103
 			 * make composer cache the result. Resulting in errors when enabling
1104 1104
 			 * the theming app.
1105 1105
 			 */
1106
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
1107
-			if (isset($prefixes['OCA\\Theming\\'])) {
1108
-				$classExists = true;
1109
-			} else {
1110
-				$classExists = false;
1111
-			}
1112
-
1113
-			if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
1114
-				return new ThemingDefaults(
1115
-					$c->get(\OCP\IConfig::class),
1116
-					$c->getL10N('theming'),
1117
-					$c->get(IURLGenerator::class),
1118
-					$c->get(ICacheFactory::class),
1119
-					new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')),
1120
-					new ImageManager(
1121
-						$c->get(\OCP\IConfig::class),
1122
-						$c->getAppDataDir('theming'),
1123
-						$c->get(IURLGenerator::class),
1124
-						$this->get(ICacheFactory::class),
1125
-						$this->get(ILogger::class),
1126
-						$this->get(ITempManager::class)
1127
-					),
1128
-					$c->get(IAppManager::class),
1129
-					$c->get(INavigationManager::class)
1130
-				);
1131
-			}
1132
-			return new \OC_Defaults();
1133
-		});
1134
-		$this->registerService(JSCombiner::class, function (Server $c) {
1135
-			return new JSCombiner(
1136
-				$c->getAppDataDir('js'),
1137
-				$c->get(IURLGenerator::class),
1138
-				$this->get(ICacheFactory::class),
1139
-				$c->get(SystemConfig::class),
1140
-				$c->get(ILogger::class)
1141
-			);
1142
-		});
1143
-		$this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
1144
-		/** @deprecated 19.0.0 */
1145
-		$this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
1146
-		$this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
1147
-
1148
-		$this->registerService('CryptoWrapper', function (ContainerInterface $c) {
1149
-			// FIXME: Instantiiated here due to cyclic dependency
1150
-			$request = new Request(
1151
-				[
1152
-					'get' => $_GET,
1153
-					'post' => $_POST,
1154
-					'files' => $_FILES,
1155
-					'server' => $_SERVER,
1156
-					'env' => $_ENV,
1157
-					'cookies' => $_COOKIE,
1158
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1159
-						? $_SERVER['REQUEST_METHOD']
1160
-						: null,
1161
-				],
1162
-				$c->get(ISecureRandom::class),
1163
-				$c->get(\OCP\IConfig::class)
1164
-			);
1165
-
1166
-			return new CryptoWrapper(
1167
-				$c->get(\OCP\IConfig::class),
1168
-				$c->get(ICrypto::class),
1169
-				$c->get(ISecureRandom::class),
1170
-				$request
1171
-			);
1172
-		});
1173
-		/** @deprecated 19.0.0 */
1174
-		$this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class);
1175
-		$this->registerService(SessionStorage::class, function (ContainerInterface $c) {
1176
-			return new SessionStorage($c->get(ISession::class));
1177
-		});
1178
-		$this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
1179
-		/** @deprecated 19.0.0 */
1180
-		$this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);
1181
-
1182
-		$this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) {
1183
-			$config = $c->get(\OCP\IConfig::class);
1184
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1185
-			/** @var \OCP\Share\IProviderFactory $factory */
1186
-			$factory = new $factoryClass($this);
1187
-
1188
-			$manager = new \OC\Share20\Manager(
1189
-				$c->get(ILogger::class),
1190
-				$c->get(\OCP\IConfig::class),
1191
-				$c->get(ISecureRandom::class),
1192
-				$c->get(IHasher::class),
1193
-				$c->get(IMountManager::class),
1194
-				$c->get(IGroupManager::class),
1195
-				$c->getL10N('lib'),
1196
-				$c->get(IFactory::class),
1197
-				$factory,
1198
-				$c->get(IUserManager::class),
1199
-				$c->get(IRootFolder::class),
1200
-				$c->get(SymfonyAdapter::class),
1201
-				$c->get(IMailer::class),
1202
-				$c->get(IURLGenerator::class),
1203
-				$c->get('ThemingDefaults'),
1204
-				$c->get(IEventDispatcher::class)
1205
-			);
1206
-
1207
-			return $manager;
1208
-		});
1209
-		/** @deprecated 19.0.0 */
1210
-		$this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);
1211
-
1212
-		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
1213
-			$instance = new Collaboration\Collaborators\Search($c);
1214
-
1215
-			// register default plugins
1216
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1217
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1218
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1219
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1220
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1221
-
1222
-			return $instance;
1223
-		});
1224
-		/** @deprecated 19.0.0 */
1225
-		$this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1226
-		$this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1227
-
1228
-		$this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1229
-
1230
-		$this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
1231
-		$this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
1232
-
1233
-		$this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class);
1234
-		$this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class);
1235
-		$this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) {
1236
-			return new \OC\Files\AppData\Factory(
1237
-				$c->get(IRootFolder::class),
1238
-				$c->get(SystemConfig::class)
1239
-			);
1240
-		});
1241
-
1242
-		$this->registerService('LockdownManager', function (ContainerInterface $c) {
1243
-			return new LockdownManager(function () use ($c) {
1244
-				return $c->get(ISession::class);
1245
-			});
1246
-		});
1247
-
1248
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) {
1249
-			return new DiscoveryService(
1250
-				$c->get(ICacheFactory::class),
1251
-				$c->get(IClientService::class)
1252
-			);
1253
-		});
1254
-
1255
-		$this->registerService(ICloudIdManager::class, function (ContainerInterface $c) {
1256
-			return new CloudIdManager($c->get(\OCP\Contacts\IManager::class));
1257
-		});
1258
-
1259
-		$this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
1260
-
1261
-		$this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) {
1262
-			return new CloudFederationProviderManager(
1263
-				$c->get(IAppManager::class),
1264
-				$c->get(IClientService::class),
1265
-				$c->get(ICloudIdManager::class),
1266
-				$c->get(ILogger::class)
1267
-			);
1268
-		});
1269
-
1270
-		$this->registerService(ICloudFederationFactory::class, function (Server $c) {
1271
-			return new CloudFederationFactory();
1272
-		});
1273
-
1274
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1275
-		/** @deprecated 19.0.0 */
1276
-		$this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1277
-
1278
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1279
-		/** @deprecated 19.0.0 */
1280
-		$this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1281
-
1282
-		$this->registerService(Defaults::class, function (Server $c) {
1283
-			return new Defaults(
1284
-				$c->getThemingDefaults()
1285
-			);
1286
-		});
1287
-		/** @deprecated 19.0.0 */
1288
-		$this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class);
1289
-
1290
-		$this->registerService(\OCP\ISession::class, function (ContainerInterface $c) {
1291
-			return $c->get(\OCP\IUserSession::class)->getSession();
1292
-		}, false);
1293
-
1294
-		$this->registerService(IShareHelper::class, function (ContainerInterface $c) {
1295
-			return new ShareHelper(
1296
-				$c->get(\OCP\Share\IManager::class)
1297
-			);
1298
-		});
1299
-
1300
-		$this->registerService(Installer::class, function (ContainerInterface $c) {
1301
-			return new Installer(
1302
-				$c->get(AppFetcher::class),
1303
-				$c->get(IClientService::class),
1304
-				$c->get(ITempManager::class),
1305
-				$c->get(ILogger::class),
1306
-				$c->get(\OCP\IConfig::class),
1307
-				\OC::$CLI
1308
-			);
1309
-		});
1310
-
1311
-		$this->registerService(IApiFactory::class, function (ContainerInterface $c) {
1312
-			return new ApiFactory($c->get(IClientService::class));
1313
-		});
1314
-
1315
-		$this->registerService(IInstanceFactory::class, function (ContainerInterface $c) {
1316
-			$memcacheFactory = $c->get(ICacheFactory::class);
1317
-			return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class));
1318
-		});
1319
-
1320
-		$this->registerAlias(IContactsStore::class, ContactsStore::class);
1321
-		$this->registerAlias(IAccountManager::class, AccountManager::class);
1322
-
1323
-		$this->registerAlias(IStorageFactory::class, StorageFactory::class);
1324
-
1325
-		$this->registerAlias(IDashboardManager::class, DashboardManager::class);
1326
-		$this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class);
1327
-		$this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1328
-
1329
-		$this->registerAlias(ISubAdmin::class, SubAdmin::class);
1330
-
1331
-		$this->registerAlias(IInitialStateService::class, InitialStateService::class);
1332
-
1333
-		$this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class);
1334
-
1335
-		$this->connectDispatcher();
1336
-	}
1337
-
1338
-	public function boot() {
1339
-		/** @var HookConnector $hookConnector */
1340
-		$hookConnector = $this->get(HookConnector::class);
1341
-		$hookConnector->viewToNode();
1342
-	}
1343
-
1344
-	/**
1345
-	 * @return \OCP\Calendar\IManager
1346
-	 * @deprecated 20.0.0
1347
-	 */
1348
-	public function getCalendarManager() {
1349
-		return $this->get(\OC\Calendar\Manager::class);
1350
-	}
1351
-
1352
-	/**
1353
-	 * @return \OCP\Calendar\Resource\IManager
1354
-	 * @deprecated 20.0.0
1355
-	 */
1356
-	public function getCalendarResourceBackendManager() {
1357
-		return $this->get(\OC\Calendar\Resource\Manager::class);
1358
-	}
1359
-
1360
-	/**
1361
-	 * @return \OCP\Calendar\Room\IManager
1362
-	 * @deprecated 20.0.0
1363
-	 */
1364
-	public function getCalendarRoomBackendManager() {
1365
-		return $this->get(\OC\Calendar\Room\Manager::class);
1366
-	}
1367
-
1368
-	private function connectDispatcher() {
1369
-		$dispatcher = $this->get(SymfonyAdapter::class);
1370
-
1371
-		// Delete avatar on user deletion
1372
-		$dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) {
1373
-			$logger = $this->get(ILogger::class);
1374
-			$manager = $this->getAvatarManager();
1375
-			/** @var IUser $user */
1376
-			$user = $e->getSubject();
1377
-
1378
-			try {
1379
-				$avatar = $manager->getAvatar($user->getUID());
1380
-				$avatar->remove();
1381
-			} catch (NotFoundException $e) {
1382
-				// no avatar to remove
1383
-			} catch (\Exception $e) {
1384
-				// Ignore exceptions
1385
-				$logger->info('Could not cleanup avatar of ' . $user->getUID());
1386
-			}
1387
-		});
1388
-
1389
-		$dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1390
-			$manager = $this->getAvatarManager();
1391
-			/** @var IUser $user */
1392
-			$user = $e->getSubject();
1393
-			$feature = $e->getArgument('feature');
1394
-			$oldValue = $e->getArgument('oldValue');
1395
-			$value = $e->getArgument('value');
1396
-
1397
-			// We only change the avatar on display name changes
1398
-			if ($feature !== 'displayName') {
1399
-				return;
1400
-			}
1401
-
1402
-			try {
1403
-				$avatar = $manager->getAvatar($user->getUID());
1404
-				$avatar->userChanged($feature, $oldValue, $value);
1405
-			} catch (NotFoundException $e) {
1406
-				// no avatar to remove
1407
-			}
1408
-		});
1409
-
1410
-		/** @var IEventDispatcher $eventDispatched */
1411
-		$eventDispatched = $this->get(IEventDispatcher::class);
1412
-		$eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class);
1413
-		$eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
1414
-	}
1415
-
1416
-	/**
1417
-	 * @return \OCP\Contacts\IManager
1418
-	 * @deprecated 20.0.0
1419
-	 */
1420
-	public function getContactsManager() {
1421
-		return $this->get(\OCP\Contacts\IManager::class);
1422
-	}
1423
-
1424
-	/**
1425
-	 * @return \OC\Encryption\Manager
1426
-	 * @deprecated 20.0.0
1427
-	 */
1428
-	public function getEncryptionManager() {
1429
-		return $this->get(\OCP\Encryption\IManager::class);
1430
-	}
1431
-
1432
-	/**
1433
-	 * @return \OC\Encryption\File
1434
-	 * @deprecated 20.0.0
1435
-	 */
1436
-	public function getEncryptionFilesHelper() {
1437
-		return $this->get(IFile::class);
1438
-	}
1439
-
1440
-	/**
1441
-	 * @return \OCP\Encryption\Keys\IStorage
1442
-	 * @deprecated 20.0.0
1443
-	 */
1444
-	public function getEncryptionKeyStorage() {
1445
-		return $this->get(IStorage::class);
1446
-	}
1447
-
1448
-	/**
1449
-	 * The current request object holding all information about the request
1450
-	 * currently being processed is returned from this method.
1451
-	 * In case the current execution was not initiated by a web request null is returned
1452
-	 *
1453
-	 * @return \OCP\IRequest
1454
-	 * @deprecated 20.0.0
1455
-	 */
1456
-	public function getRequest() {
1457
-		return $this->get(IRequest::class);
1458
-	}
1459
-
1460
-	/**
1461
-	 * Returns the preview manager which can create preview images for a given file
1462
-	 *
1463
-	 * @return IPreview
1464
-	 * @deprecated 20.0.0
1465
-	 */
1466
-	public function getPreviewManager() {
1467
-		return $this->get(IPreview::class);
1468
-	}
1469
-
1470
-	/**
1471
-	 * Returns the tag manager which can get and set tags for different object types
1472
-	 *
1473
-	 * @see \OCP\ITagManager::load()
1474
-	 * @return ITagManager
1475
-	 * @deprecated 20.0.0
1476
-	 */
1477
-	public function getTagManager() {
1478
-		return $this->get(ITagManager::class);
1479
-	}
1480
-
1481
-	/**
1482
-	 * Returns the system-tag manager
1483
-	 *
1484
-	 * @return ISystemTagManager
1485
-	 *
1486
-	 * @since 9.0.0
1487
-	 * @deprecated 20.0.0
1488
-	 */
1489
-	public function getSystemTagManager() {
1490
-		return $this->get(ISystemTagManager::class);
1491
-	}
1492
-
1493
-	/**
1494
-	 * Returns the system-tag object mapper
1495
-	 *
1496
-	 * @return ISystemTagObjectMapper
1497
-	 *
1498
-	 * @since 9.0.0
1499
-	 * @deprecated 20.0.0
1500
-	 */
1501
-	public function getSystemTagObjectMapper() {
1502
-		return $this->get(ISystemTagObjectMapper::class);
1503
-	}
1504
-
1505
-	/**
1506
-	 * Returns the avatar manager, used for avatar functionality
1507
-	 *
1508
-	 * @return IAvatarManager
1509
-	 * @deprecated 20.0.0
1510
-	 */
1511
-	public function getAvatarManager() {
1512
-		return $this->get(IAvatarManager::class);
1513
-	}
1514
-
1515
-	/**
1516
-	 * Returns the root folder of ownCloud's data directory
1517
-	 *
1518
-	 * @return IRootFolder
1519
-	 * @deprecated 20.0.0
1520
-	 */
1521
-	public function getRootFolder() {
1522
-		return $this->get(IRootFolder::class);
1523
-	}
1524
-
1525
-	/**
1526
-	 * Returns the root folder of ownCloud's data directory
1527
-	 * This is the lazy variant so this gets only initialized once it
1528
-	 * is actually used.
1529
-	 *
1530
-	 * @return IRootFolder
1531
-	 * @deprecated 20.0.0
1532
-	 */
1533
-	public function getLazyRootFolder() {
1534
-		return $this->get(IRootFolder::class);
1535
-	}
1536
-
1537
-	/**
1538
-	 * Returns a view to ownCloud's files folder
1539
-	 *
1540
-	 * @param string $userId user ID
1541
-	 * @return \OCP\Files\Folder|null
1542
-	 * @deprecated 20.0.0
1543
-	 */
1544
-	public function getUserFolder($userId = null) {
1545
-		if ($userId === null) {
1546
-			$user = $this->get(IUserSession::class)->getUser();
1547
-			if (!$user) {
1548
-				return null;
1549
-			}
1550
-			$userId = $user->getUID();
1551
-		}
1552
-		$root = $this->get(IRootFolder::class);
1553
-		return $root->getUserFolder($userId);
1554
-	}
1555
-
1556
-	/**
1557
-	 * @return \OC\User\Manager
1558
-	 * @deprecated 20.0.0
1559
-	 */
1560
-	public function getUserManager() {
1561
-		return $this->get(IUserManager::class);
1562
-	}
1563
-
1564
-	/**
1565
-	 * @return \OC\Group\Manager
1566
-	 * @deprecated 20.0.0
1567
-	 */
1568
-	public function getGroupManager() {
1569
-		return $this->get(IGroupManager::class);
1570
-	}
1571
-
1572
-	/**
1573
-	 * @return \OC\User\Session
1574
-	 * @deprecated 20.0.0
1575
-	 */
1576
-	public function getUserSession() {
1577
-		return $this->get(IUserSession::class);
1578
-	}
1579
-
1580
-	/**
1581
-	 * @return \OCP\ISession
1582
-	 * @deprecated 20.0.0
1583
-	 */
1584
-	public function getSession() {
1585
-		return $this->get(IUserSession::class)->getSession();
1586
-	}
1587
-
1588
-	/**
1589
-	 * @param \OCP\ISession $session
1590
-	 */
1591
-	public function setSession(\OCP\ISession $session) {
1592
-		$this->get(SessionStorage::class)->setSession($session);
1593
-		$this->get(IUserSession::class)->setSession($session);
1594
-		$this->get(Store::class)->setSession($session);
1595
-	}
1596
-
1597
-	/**
1598
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1599
-	 * @deprecated 20.0.0
1600
-	 */
1601
-	public function getTwoFactorAuthManager() {
1602
-		return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class);
1603
-	}
1604
-
1605
-	/**
1606
-	 * @return \OC\NavigationManager
1607
-	 * @deprecated 20.0.0
1608
-	 */
1609
-	public function getNavigationManager() {
1610
-		return $this->get(INavigationManager::class);
1611
-	}
1612
-
1613
-	/**
1614
-	 * @return \OCP\IConfig
1615
-	 * @deprecated 20.0.0
1616
-	 */
1617
-	public function getConfig() {
1618
-		return $this->get(AllConfig::class);
1619
-	}
1620
-
1621
-	/**
1622
-	 * @return \OC\SystemConfig
1623
-	 * @deprecated 20.0.0
1624
-	 */
1625
-	public function getSystemConfig() {
1626
-		return $this->get(SystemConfig::class);
1627
-	}
1628
-
1629
-	/**
1630
-	 * Returns the app config manager
1631
-	 *
1632
-	 * @return IAppConfig
1633
-	 * @deprecated 20.0.0
1634
-	 */
1635
-	public function getAppConfig() {
1636
-		return $this->get(IAppConfig::class);
1637
-	}
1638
-
1639
-	/**
1640
-	 * @return IFactory
1641
-	 * @deprecated 20.0.0
1642
-	 */
1643
-	public function getL10NFactory() {
1644
-		return $this->get(IFactory::class);
1645
-	}
1646
-
1647
-	/**
1648
-	 * get an L10N instance
1649
-	 *
1650
-	 * @param string $app appid
1651
-	 * @param string $lang
1652
-	 * @return IL10N
1653
-	 * @deprecated 20.0.0
1654
-	 */
1655
-	public function getL10N($app, $lang = null) {
1656
-		return $this->get(IFactory::class)->get($app, $lang);
1657
-	}
1658
-
1659
-	/**
1660
-	 * @return IURLGenerator
1661
-	 * @deprecated 20.0.0
1662
-	 */
1663
-	public function getURLGenerator() {
1664
-		return $this->get(IURLGenerator::class);
1665
-	}
1666
-
1667
-	/**
1668
-	 * @return AppFetcher
1669
-	 * @deprecated 20.0.0
1670
-	 */
1671
-	public function getAppFetcher() {
1672
-		return $this->get(AppFetcher::class);
1673
-	}
1674
-
1675
-	/**
1676
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1677
-	 * getMemCacheFactory() instead.
1678
-	 *
1679
-	 * @return ICache
1680
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1681
-	 */
1682
-	public function getCache() {
1683
-		return $this->get(ICache::class);
1684
-	}
1685
-
1686
-	/**
1687
-	 * Returns an \OCP\CacheFactory instance
1688
-	 *
1689
-	 * @return \OCP\ICacheFactory
1690
-	 * @deprecated 20.0.0
1691
-	 */
1692
-	public function getMemCacheFactory() {
1693
-		return $this->get(ICacheFactory::class);
1694
-	}
1695
-
1696
-	/**
1697
-	 * Returns an \OC\RedisFactory instance
1698
-	 *
1699
-	 * @return \OC\RedisFactory
1700
-	 * @deprecated 20.0.0
1701
-	 */
1702
-	public function getGetRedisFactory() {
1703
-		return $this->get('RedisFactory');
1704
-	}
1705
-
1706
-
1707
-	/**
1708
-	 * Returns the current session
1709
-	 *
1710
-	 * @return \OCP\IDBConnection
1711
-	 * @deprecated 20.0.0
1712
-	 */
1713
-	public function getDatabaseConnection() {
1714
-		return $this->get(IDBConnection::class);
1715
-	}
1716
-
1717
-	/**
1718
-	 * Returns the activity manager
1719
-	 *
1720
-	 * @return \OCP\Activity\IManager
1721
-	 * @deprecated 20.0.0
1722
-	 */
1723
-	public function getActivityManager() {
1724
-		return $this->get(\OCP\Activity\IManager::class);
1725
-	}
1726
-
1727
-	/**
1728
-	 * Returns an job list for controlling background jobs
1729
-	 *
1730
-	 * @return IJobList
1731
-	 * @deprecated 20.0.0
1732
-	 */
1733
-	public function getJobList() {
1734
-		return $this->get(IJobList::class);
1735
-	}
1736
-
1737
-	/**
1738
-	 * Returns a logger instance
1739
-	 *
1740
-	 * @return ILogger
1741
-	 * @deprecated 20.0.0
1742
-	 */
1743
-	public function getLogger() {
1744
-		return $this->get(ILogger::class);
1745
-	}
1746
-
1747
-	/**
1748
-	 * @return ILogFactory
1749
-	 * @throws \OCP\AppFramework\QueryException
1750
-	 * @deprecated 20.0.0
1751
-	 */
1752
-	public function getLogFactory() {
1753
-		return $this->get(ILogFactory::class);
1754
-	}
1755
-
1756
-	/**
1757
-	 * Returns a router for generating and matching urls
1758
-	 *
1759
-	 * @return IRouter
1760
-	 * @deprecated 20.0.0
1761
-	 */
1762
-	public function getRouter() {
1763
-		return $this->get(IRouter::class);
1764
-	}
1765
-
1766
-	/**
1767
-	 * Returns a search instance
1768
-	 *
1769
-	 * @return ISearch
1770
-	 * @deprecated 20.0.0
1771
-	 */
1772
-	public function getSearch() {
1773
-		return $this->get(ISearch::class);
1774
-	}
1775
-
1776
-	/**
1777
-	 * Returns a SecureRandom instance
1778
-	 *
1779
-	 * @return \OCP\Security\ISecureRandom
1780
-	 * @deprecated 20.0.0
1781
-	 */
1782
-	public function getSecureRandom() {
1783
-		return $this->get(ISecureRandom::class);
1784
-	}
1785
-
1786
-	/**
1787
-	 * Returns a Crypto instance
1788
-	 *
1789
-	 * @return ICrypto
1790
-	 * @deprecated 20.0.0
1791
-	 */
1792
-	public function getCrypto() {
1793
-		return $this->get(ICrypto::class);
1794
-	}
1795
-
1796
-	/**
1797
-	 * Returns a Hasher instance
1798
-	 *
1799
-	 * @return IHasher
1800
-	 * @deprecated 20.0.0
1801
-	 */
1802
-	public function getHasher() {
1803
-		return $this->get(IHasher::class);
1804
-	}
1805
-
1806
-	/**
1807
-	 * Returns a CredentialsManager instance
1808
-	 *
1809
-	 * @return ICredentialsManager
1810
-	 * @deprecated 20.0.0
1811
-	 */
1812
-	public function getCredentialsManager() {
1813
-		return $this->get(ICredentialsManager::class);
1814
-	}
1815
-
1816
-	/**
1817
-	 * Get the certificate manager
1818
-	 *
1819
-	 * @return \OCP\ICertificateManager
1820
-	 */
1821
-	public function getCertificateManager() {
1822
-		return $this->get(ICertificateManager::class);
1823
-	}
1824
-
1825
-	/**
1826
-	 * Returns an instance of the HTTP client service
1827
-	 *
1828
-	 * @return IClientService
1829
-	 * @deprecated 20.0.0
1830
-	 */
1831
-	public function getHTTPClientService() {
1832
-		return $this->get(IClientService::class);
1833
-	}
1834
-
1835
-	/**
1836
-	 * Create a new event source
1837
-	 *
1838
-	 * @return \OCP\IEventSource
1839
-	 * @deprecated 20.0.0
1840
-	 */
1841
-	public function createEventSource() {
1842
-		return new \OC_EventSource();
1843
-	}
1844
-
1845
-	/**
1846
-	 * Get the active event logger
1847
-	 *
1848
-	 * The returned logger only logs data when debug mode is enabled
1849
-	 *
1850
-	 * @return IEventLogger
1851
-	 * @deprecated 20.0.0
1852
-	 */
1853
-	public function getEventLogger() {
1854
-		return $this->get(IEventLogger::class);
1855
-	}
1856
-
1857
-	/**
1858
-	 * Get the active query logger
1859
-	 *
1860
-	 * The returned logger only logs data when debug mode is enabled
1861
-	 *
1862
-	 * @return IQueryLogger
1863
-	 * @deprecated 20.0.0
1864
-	 */
1865
-	public function getQueryLogger() {
1866
-		return $this->get(IQueryLogger::class);
1867
-	}
1868
-
1869
-	/**
1870
-	 * Get the manager for temporary files and folders
1871
-	 *
1872
-	 * @return \OCP\ITempManager
1873
-	 * @deprecated 20.0.0
1874
-	 */
1875
-	public function getTempManager() {
1876
-		return $this->get(ITempManager::class);
1877
-	}
1878
-
1879
-	/**
1880
-	 * Get the app manager
1881
-	 *
1882
-	 * @return \OCP\App\IAppManager
1883
-	 * @deprecated 20.0.0
1884
-	 */
1885
-	public function getAppManager() {
1886
-		return $this->get(IAppManager::class);
1887
-	}
1888
-
1889
-	/**
1890
-	 * Creates a new mailer
1891
-	 *
1892
-	 * @return IMailer
1893
-	 * @deprecated 20.0.0
1894
-	 */
1895
-	public function getMailer() {
1896
-		return $this->get(IMailer::class);
1897
-	}
1898
-
1899
-	/**
1900
-	 * Get the webroot
1901
-	 *
1902
-	 * @return string
1903
-	 * @deprecated 20.0.0
1904
-	 */
1905
-	public function getWebRoot() {
1906
-		return $this->webRoot;
1907
-	}
1908
-
1909
-	/**
1910
-	 * @return \OC\OCSClient
1911
-	 * @deprecated 20.0.0
1912
-	 */
1913
-	public function getOcsClient() {
1914
-		return $this->get('OcsClient');
1915
-	}
1916
-
1917
-	/**
1918
-	 * @return IDateTimeZone
1919
-	 * @deprecated 20.0.0
1920
-	 */
1921
-	public function getDateTimeZone() {
1922
-		return $this->get(IDateTimeZone::class);
1923
-	}
1924
-
1925
-	/**
1926
-	 * @return IDateTimeFormatter
1927
-	 * @deprecated 20.0.0
1928
-	 */
1929
-	public function getDateTimeFormatter() {
1930
-		return $this->get(IDateTimeFormatter::class);
1931
-	}
1932
-
1933
-	/**
1934
-	 * @return IMountProviderCollection
1935
-	 * @deprecated 20.0.0
1936
-	 */
1937
-	public function getMountProviderCollection() {
1938
-		return $this->get(IMountProviderCollection::class);
1939
-	}
1940
-
1941
-	/**
1942
-	 * Get the IniWrapper
1943
-	 *
1944
-	 * @return IniGetWrapper
1945
-	 * @deprecated 20.0.0
1946
-	 */
1947
-	public function getIniWrapper() {
1948
-		return $this->get(IniGetWrapper::class);
1949
-	}
1950
-
1951
-	/**
1952
-	 * @return \OCP\Command\IBus
1953
-	 * @deprecated 20.0.0
1954
-	 */
1955
-	public function getCommandBus() {
1956
-		return $this->get(IBus::class);
1957
-	}
1958
-
1959
-	/**
1960
-	 * Get the trusted domain helper
1961
-	 *
1962
-	 * @return TrustedDomainHelper
1963
-	 * @deprecated 20.0.0
1964
-	 */
1965
-	public function getTrustedDomainHelper() {
1966
-		return $this->get(TrustedDomainHelper::class);
1967
-	}
1968
-
1969
-	/**
1970
-	 * Get the locking provider
1971
-	 *
1972
-	 * @return ILockingProvider
1973
-	 * @since 8.1.0
1974
-	 * @deprecated 20.0.0
1975
-	 */
1976
-	public function getLockingProvider() {
1977
-		return $this->get(ILockingProvider::class);
1978
-	}
1979
-
1980
-	/**
1981
-	 * @return IMountManager
1982
-	 * @deprecated 20.0.0
1983
-	 **/
1984
-	public function getMountManager() {
1985
-		return $this->get(IMountManager::class);
1986
-	}
1987
-
1988
-	/**
1989
-	 * @return IUserMountCache
1990
-	 * @deprecated 20.0.0
1991
-	 */
1992
-	public function getUserMountCache() {
1993
-		return $this->get(IUserMountCache::class);
1994
-	}
1995
-
1996
-	/**
1997
-	 * Get the MimeTypeDetector
1998
-	 *
1999
-	 * @return IMimeTypeDetector
2000
-	 * @deprecated 20.0.0
2001
-	 */
2002
-	public function getMimeTypeDetector() {
2003
-		return $this->get(IMimeTypeDetector::class);
2004
-	}
2005
-
2006
-	/**
2007
-	 * Get the MimeTypeLoader
2008
-	 *
2009
-	 * @return IMimeTypeLoader
2010
-	 * @deprecated 20.0.0
2011
-	 */
2012
-	public function getMimeTypeLoader() {
2013
-		return $this->get(IMimeTypeLoader::class);
2014
-	}
2015
-
2016
-	/**
2017
-	 * Get the manager of all the capabilities
2018
-	 *
2019
-	 * @return CapabilitiesManager
2020
-	 * @deprecated 20.0.0
2021
-	 */
2022
-	public function getCapabilitiesManager() {
2023
-		return $this->get(CapabilitiesManager::class);
2024
-	}
2025
-
2026
-	/**
2027
-	 * Get the EventDispatcher
2028
-	 *
2029
-	 * @return EventDispatcherInterface
2030
-	 * @since 8.2.0
2031
-	 * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher
2032
-	 */
2033
-	public function getEventDispatcher() {
2034
-		return $this->get(\OC\EventDispatcher\SymfonyAdapter::class);
2035
-	}
2036
-
2037
-	/**
2038
-	 * Get the Notification Manager
2039
-	 *
2040
-	 * @return \OCP\Notification\IManager
2041
-	 * @since 8.2.0
2042
-	 * @deprecated 20.0.0
2043
-	 */
2044
-	public function getNotificationManager() {
2045
-		return $this->get(\OCP\Notification\IManager::class);
2046
-	}
2047
-
2048
-	/**
2049
-	 * @return ICommentsManager
2050
-	 * @deprecated 20.0.0
2051
-	 */
2052
-	public function getCommentsManager() {
2053
-		return $this->get(ICommentsManager::class);
2054
-	}
2055
-
2056
-	/**
2057
-	 * @return \OCA\Theming\ThemingDefaults
2058
-	 * @deprecated 20.0.0
2059
-	 */
2060
-	public function getThemingDefaults() {
2061
-		return $this->get('ThemingDefaults');
2062
-	}
2063
-
2064
-	/**
2065
-	 * @return \OC\IntegrityCheck\Checker
2066
-	 * @deprecated 20.0.0
2067
-	 */
2068
-	public function getIntegrityCodeChecker() {
2069
-		return $this->get('IntegrityCodeChecker');
2070
-	}
2071
-
2072
-	/**
2073
-	 * @return \OC\Session\CryptoWrapper
2074
-	 * @deprecated 20.0.0
2075
-	 */
2076
-	public function getSessionCryptoWrapper() {
2077
-		return $this->get('CryptoWrapper');
2078
-	}
2079
-
2080
-	/**
2081
-	 * @return CsrfTokenManager
2082
-	 * @deprecated 20.0.0
2083
-	 */
2084
-	public function getCsrfTokenManager() {
2085
-		return $this->get(CsrfTokenManager::class);
2086
-	}
2087
-
2088
-	/**
2089
-	 * @return Throttler
2090
-	 * @deprecated 20.0.0
2091
-	 */
2092
-	public function getBruteForceThrottler() {
2093
-		return $this->get(Throttler::class);
2094
-	}
2095
-
2096
-	/**
2097
-	 * @return IContentSecurityPolicyManager
2098
-	 * @deprecated 20.0.0
2099
-	 */
2100
-	public function getContentSecurityPolicyManager() {
2101
-		return $this->get(ContentSecurityPolicyManager::class);
2102
-	}
2103
-
2104
-	/**
2105
-	 * @return ContentSecurityPolicyNonceManager
2106
-	 * @deprecated 20.0.0
2107
-	 */
2108
-	public function getContentSecurityPolicyNonceManager() {
2109
-		return $this->get(ContentSecurityPolicyNonceManager::class);
2110
-	}
2111
-
2112
-	/**
2113
-	 * Not a public API as of 8.2, wait for 9.0
2114
-	 *
2115
-	 * @return \OCA\Files_External\Service\BackendService
2116
-	 * @deprecated 20.0.0
2117
-	 */
2118
-	public function getStoragesBackendService() {
2119
-		return $this->get(BackendService::class);
2120
-	}
2121
-
2122
-	/**
2123
-	 * Not a public API as of 8.2, wait for 9.0
2124
-	 *
2125
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
2126
-	 * @deprecated 20.0.0
2127
-	 */
2128
-	public function getGlobalStoragesService() {
2129
-		return $this->get(GlobalStoragesService::class);
2130
-	}
2131
-
2132
-	/**
2133
-	 * Not a public API as of 8.2, wait for 9.0
2134
-	 *
2135
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
2136
-	 * @deprecated 20.0.0
2137
-	 */
2138
-	public function getUserGlobalStoragesService() {
2139
-		return $this->get(UserGlobalStoragesService::class);
2140
-	}
2141
-
2142
-	/**
2143
-	 * Not a public API as of 8.2, wait for 9.0
2144
-	 *
2145
-	 * @return \OCA\Files_External\Service\UserStoragesService
2146
-	 * @deprecated 20.0.0
2147
-	 */
2148
-	public function getUserStoragesService() {
2149
-		return $this->get(UserStoragesService::class);
2150
-	}
2151
-
2152
-	/**
2153
-	 * @return \OCP\Share\IManager
2154
-	 * @deprecated 20.0.0
2155
-	 */
2156
-	public function getShareManager() {
2157
-		return $this->get(\OCP\Share\IManager::class);
2158
-	}
2159
-
2160
-	/**
2161
-	 * @return \OCP\Collaboration\Collaborators\ISearch
2162
-	 * @deprecated 20.0.0
2163
-	 */
2164
-	public function getCollaboratorSearch() {
2165
-		return $this->get(\OCP\Collaboration\Collaborators\ISearch::class);
2166
-	}
2167
-
2168
-	/**
2169
-	 * @return \OCP\Collaboration\AutoComplete\IManager
2170
-	 * @deprecated 20.0.0
2171
-	 */
2172
-	public function getAutoCompleteManager() {
2173
-		return $this->get(IManager::class);
2174
-	}
2175
-
2176
-	/**
2177
-	 * Returns the LDAP Provider
2178
-	 *
2179
-	 * @return \OCP\LDAP\ILDAPProvider
2180
-	 * @deprecated 20.0.0
2181
-	 */
2182
-	public function getLDAPProvider() {
2183
-		return $this->get('LDAPProvider');
2184
-	}
2185
-
2186
-	/**
2187
-	 * @return \OCP\Settings\IManager
2188
-	 * @deprecated 20.0.0
2189
-	 */
2190
-	public function getSettingsManager() {
2191
-		return $this->get(\OC\Settings\Manager::class);
2192
-	}
2193
-
2194
-	/**
2195
-	 * @return \OCP\Files\IAppData
2196
-	 * @deprecated 20.0.0
2197
-	 */
2198
-	public function getAppDataDir($app) {
2199
-		/** @var \OC\Files\AppData\Factory $factory */
2200
-		$factory = $this->get(\OC\Files\AppData\Factory::class);
2201
-		return $factory->get($app);
2202
-	}
2203
-
2204
-	/**
2205
-	 * @return \OCP\Lockdown\ILockdownManager
2206
-	 * @deprecated 20.0.0
2207
-	 */
2208
-	public function getLockdownManager() {
2209
-		return $this->get('LockdownManager');
2210
-	}
2211
-
2212
-	/**
2213
-	 * @return \OCP\Federation\ICloudIdManager
2214
-	 * @deprecated 20.0.0
2215
-	 */
2216
-	public function getCloudIdManager() {
2217
-		return $this->get(ICloudIdManager::class);
2218
-	}
2219
-
2220
-	/**
2221
-	 * @return \OCP\GlobalScale\IConfig
2222
-	 * @deprecated 20.0.0
2223
-	 */
2224
-	public function getGlobalScaleConfig() {
2225
-		return $this->get(IConfig::class);
2226
-	}
2227
-
2228
-	/**
2229
-	 * @return \OCP\Federation\ICloudFederationProviderManager
2230
-	 * @deprecated 20.0.0
2231
-	 */
2232
-	public function getCloudFederationProviderManager() {
2233
-		return $this->get(ICloudFederationProviderManager::class);
2234
-	}
2235
-
2236
-	/**
2237
-	 * @return \OCP\Remote\Api\IApiFactory
2238
-	 * @deprecated 20.0.0
2239
-	 */
2240
-	public function getRemoteApiFactory() {
2241
-		return $this->get(IApiFactory::class);
2242
-	}
2243
-
2244
-	/**
2245
-	 * @return \OCP\Federation\ICloudFederationFactory
2246
-	 * @deprecated 20.0.0
2247
-	 */
2248
-	public function getCloudFederationFactory() {
2249
-		return $this->get(ICloudFederationFactory::class);
2250
-	}
2251
-
2252
-	/**
2253
-	 * @return \OCP\Remote\IInstanceFactory
2254
-	 * @deprecated 20.0.0
2255
-	 */
2256
-	public function getRemoteInstanceFactory() {
2257
-		return $this->get(IInstanceFactory::class);
2258
-	}
2259
-
2260
-	/**
2261
-	 * @return IStorageFactory
2262
-	 * @deprecated 20.0.0
2263
-	 */
2264
-	public function getStorageFactory() {
2265
-		return $this->get(IStorageFactory::class);
2266
-	}
2267
-
2268
-	/**
2269
-	 * Get the Preview GeneratorHelper
2270
-	 *
2271
-	 * @return GeneratorHelper
2272
-	 * @since 17.0.0
2273
-	 * @deprecated 20.0.0
2274
-	 */
2275
-	public function getGeneratorHelper() {
2276
-		return $this->get(\OC\Preview\GeneratorHelper::class);
2277
-	}
2278
-
2279
-	private function registerDeprecatedAlias(string $alias, string $target) {
2280
-		$this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) {
2281
-			try {
2282
-				/** @var ILogger $logger */
2283
-				$logger = $container->get(ILogger::class);
2284
-				$logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
2285
-			} catch (ContainerExceptionInterface $e) {
2286
-				// Could not get logger. Continue
2287
-			}
2288
-
2289
-			return $container->get($target);
2290
-		}, false);
2291
-	}
1106
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
1107
+            if (isset($prefixes['OCA\\Theming\\'])) {
1108
+                $classExists = true;
1109
+            } else {
1110
+                $classExists = false;
1111
+            }
1112
+
1113
+            if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
1114
+                return new ThemingDefaults(
1115
+                    $c->get(\OCP\IConfig::class),
1116
+                    $c->getL10N('theming'),
1117
+                    $c->get(IURLGenerator::class),
1118
+                    $c->get(ICacheFactory::class),
1119
+                    new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')),
1120
+                    new ImageManager(
1121
+                        $c->get(\OCP\IConfig::class),
1122
+                        $c->getAppDataDir('theming'),
1123
+                        $c->get(IURLGenerator::class),
1124
+                        $this->get(ICacheFactory::class),
1125
+                        $this->get(ILogger::class),
1126
+                        $this->get(ITempManager::class)
1127
+                    ),
1128
+                    $c->get(IAppManager::class),
1129
+                    $c->get(INavigationManager::class)
1130
+                );
1131
+            }
1132
+            return new \OC_Defaults();
1133
+        });
1134
+        $this->registerService(JSCombiner::class, function (Server $c) {
1135
+            return new JSCombiner(
1136
+                $c->getAppDataDir('js'),
1137
+                $c->get(IURLGenerator::class),
1138
+                $this->get(ICacheFactory::class),
1139
+                $c->get(SystemConfig::class),
1140
+                $c->get(ILogger::class)
1141
+            );
1142
+        });
1143
+        $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
1144
+        /** @deprecated 19.0.0 */
1145
+        $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
1146
+        $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
1147
+
1148
+        $this->registerService('CryptoWrapper', function (ContainerInterface $c) {
1149
+            // FIXME: Instantiiated here due to cyclic dependency
1150
+            $request = new Request(
1151
+                [
1152
+                    'get' => $_GET,
1153
+                    'post' => $_POST,
1154
+                    'files' => $_FILES,
1155
+                    'server' => $_SERVER,
1156
+                    'env' => $_ENV,
1157
+                    'cookies' => $_COOKIE,
1158
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1159
+                        ? $_SERVER['REQUEST_METHOD']
1160
+                        : null,
1161
+                ],
1162
+                $c->get(ISecureRandom::class),
1163
+                $c->get(\OCP\IConfig::class)
1164
+            );
1165
+
1166
+            return new CryptoWrapper(
1167
+                $c->get(\OCP\IConfig::class),
1168
+                $c->get(ICrypto::class),
1169
+                $c->get(ISecureRandom::class),
1170
+                $request
1171
+            );
1172
+        });
1173
+        /** @deprecated 19.0.0 */
1174
+        $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class);
1175
+        $this->registerService(SessionStorage::class, function (ContainerInterface $c) {
1176
+            return new SessionStorage($c->get(ISession::class));
1177
+        });
1178
+        $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
1179
+        /** @deprecated 19.0.0 */
1180
+        $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);
1181
+
1182
+        $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) {
1183
+            $config = $c->get(\OCP\IConfig::class);
1184
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1185
+            /** @var \OCP\Share\IProviderFactory $factory */
1186
+            $factory = new $factoryClass($this);
1187
+
1188
+            $manager = new \OC\Share20\Manager(
1189
+                $c->get(ILogger::class),
1190
+                $c->get(\OCP\IConfig::class),
1191
+                $c->get(ISecureRandom::class),
1192
+                $c->get(IHasher::class),
1193
+                $c->get(IMountManager::class),
1194
+                $c->get(IGroupManager::class),
1195
+                $c->getL10N('lib'),
1196
+                $c->get(IFactory::class),
1197
+                $factory,
1198
+                $c->get(IUserManager::class),
1199
+                $c->get(IRootFolder::class),
1200
+                $c->get(SymfonyAdapter::class),
1201
+                $c->get(IMailer::class),
1202
+                $c->get(IURLGenerator::class),
1203
+                $c->get('ThemingDefaults'),
1204
+                $c->get(IEventDispatcher::class)
1205
+            );
1206
+
1207
+            return $manager;
1208
+        });
1209
+        /** @deprecated 19.0.0 */
1210
+        $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);
1211
+
1212
+        $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
1213
+            $instance = new Collaboration\Collaborators\Search($c);
1214
+
1215
+            // register default plugins
1216
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1217
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1218
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1219
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1220
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1221
+
1222
+            return $instance;
1223
+        });
1224
+        /** @deprecated 19.0.0 */
1225
+        $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1226
+        $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1227
+
1228
+        $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1229
+
1230
+        $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
1231
+        $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
1232
+
1233
+        $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class);
1234
+        $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class);
1235
+        $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) {
1236
+            return new \OC\Files\AppData\Factory(
1237
+                $c->get(IRootFolder::class),
1238
+                $c->get(SystemConfig::class)
1239
+            );
1240
+        });
1241
+
1242
+        $this->registerService('LockdownManager', function (ContainerInterface $c) {
1243
+            return new LockdownManager(function () use ($c) {
1244
+                return $c->get(ISession::class);
1245
+            });
1246
+        });
1247
+
1248
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) {
1249
+            return new DiscoveryService(
1250
+                $c->get(ICacheFactory::class),
1251
+                $c->get(IClientService::class)
1252
+            );
1253
+        });
1254
+
1255
+        $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) {
1256
+            return new CloudIdManager($c->get(\OCP\Contacts\IManager::class));
1257
+        });
1258
+
1259
+        $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
1260
+
1261
+        $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) {
1262
+            return new CloudFederationProviderManager(
1263
+                $c->get(IAppManager::class),
1264
+                $c->get(IClientService::class),
1265
+                $c->get(ICloudIdManager::class),
1266
+                $c->get(ILogger::class)
1267
+            );
1268
+        });
1269
+
1270
+        $this->registerService(ICloudFederationFactory::class, function (Server $c) {
1271
+            return new CloudFederationFactory();
1272
+        });
1273
+
1274
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1275
+        /** @deprecated 19.0.0 */
1276
+        $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1277
+
1278
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1279
+        /** @deprecated 19.0.0 */
1280
+        $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1281
+
1282
+        $this->registerService(Defaults::class, function (Server $c) {
1283
+            return new Defaults(
1284
+                $c->getThemingDefaults()
1285
+            );
1286
+        });
1287
+        /** @deprecated 19.0.0 */
1288
+        $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class);
1289
+
1290
+        $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) {
1291
+            return $c->get(\OCP\IUserSession::class)->getSession();
1292
+        }, false);
1293
+
1294
+        $this->registerService(IShareHelper::class, function (ContainerInterface $c) {
1295
+            return new ShareHelper(
1296
+                $c->get(\OCP\Share\IManager::class)
1297
+            );
1298
+        });
1299
+
1300
+        $this->registerService(Installer::class, function (ContainerInterface $c) {
1301
+            return new Installer(
1302
+                $c->get(AppFetcher::class),
1303
+                $c->get(IClientService::class),
1304
+                $c->get(ITempManager::class),
1305
+                $c->get(ILogger::class),
1306
+                $c->get(\OCP\IConfig::class),
1307
+                \OC::$CLI
1308
+            );
1309
+        });
1310
+
1311
+        $this->registerService(IApiFactory::class, function (ContainerInterface $c) {
1312
+            return new ApiFactory($c->get(IClientService::class));
1313
+        });
1314
+
1315
+        $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) {
1316
+            $memcacheFactory = $c->get(ICacheFactory::class);
1317
+            return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class));
1318
+        });
1319
+
1320
+        $this->registerAlias(IContactsStore::class, ContactsStore::class);
1321
+        $this->registerAlias(IAccountManager::class, AccountManager::class);
1322
+
1323
+        $this->registerAlias(IStorageFactory::class, StorageFactory::class);
1324
+
1325
+        $this->registerAlias(IDashboardManager::class, DashboardManager::class);
1326
+        $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class);
1327
+        $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1328
+
1329
+        $this->registerAlias(ISubAdmin::class, SubAdmin::class);
1330
+
1331
+        $this->registerAlias(IInitialStateService::class, InitialStateService::class);
1332
+
1333
+        $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class);
1334
+
1335
+        $this->connectDispatcher();
1336
+    }
1337
+
1338
+    public function boot() {
1339
+        /** @var HookConnector $hookConnector */
1340
+        $hookConnector = $this->get(HookConnector::class);
1341
+        $hookConnector->viewToNode();
1342
+    }
1343
+
1344
+    /**
1345
+     * @return \OCP\Calendar\IManager
1346
+     * @deprecated 20.0.0
1347
+     */
1348
+    public function getCalendarManager() {
1349
+        return $this->get(\OC\Calendar\Manager::class);
1350
+    }
1351
+
1352
+    /**
1353
+     * @return \OCP\Calendar\Resource\IManager
1354
+     * @deprecated 20.0.0
1355
+     */
1356
+    public function getCalendarResourceBackendManager() {
1357
+        return $this->get(\OC\Calendar\Resource\Manager::class);
1358
+    }
1359
+
1360
+    /**
1361
+     * @return \OCP\Calendar\Room\IManager
1362
+     * @deprecated 20.0.0
1363
+     */
1364
+    public function getCalendarRoomBackendManager() {
1365
+        return $this->get(\OC\Calendar\Room\Manager::class);
1366
+    }
1367
+
1368
+    private function connectDispatcher() {
1369
+        $dispatcher = $this->get(SymfonyAdapter::class);
1370
+
1371
+        // Delete avatar on user deletion
1372
+        $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) {
1373
+            $logger = $this->get(ILogger::class);
1374
+            $manager = $this->getAvatarManager();
1375
+            /** @var IUser $user */
1376
+            $user = $e->getSubject();
1377
+
1378
+            try {
1379
+                $avatar = $manager->getAvatar($user->getUID());
1380
+                $avatar->remove();
1381
+            } catch (NotFoundException $e) {
1382
+                // no avatar to remove
1383
+            } catch (\Exception $e) {
1384
+                // Ignore exceptions
1385
+                $logger->info('Could not cleanup avatar of ' . $user->getUID());
1386
+            }
1387
+        });
1388
+
1389
+        $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1390
+            $manager = $this->getAvatarManager();
1391
+            /** @var IUser $user */
1392
+            $user = $e->getSubject();
1393
+            $feature = $e->getArgument('feature');
1394
+            $oldValue = $e->getArgument('oldValue');
1395
+            $value = $e->getArgument('value');
1396
+
1397
+            // We only change the avatar on display name changes
1398
+            if ($feature !== 'displayName') {
1399
+                return;
1400
+            }
1401
+
1402
+            try {
1403
+                $avatar = $manager->getAvatar($user->getUID());
1404
+                $avatar->userChanged($feature, $oldValue, $value);
1405
+            } catch (NotFoundException $e) {
1406
+                // no avatar to remove
1407
+            }
1408
+        });
1409
+
1410
+        /** @var IEventDispatcher $eventDispatched */
1411
+        $eventDispatched = $this->get(IEventDispatcher::class);
1412
+        $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class);
1413
+        $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
1414
+    }
1415
+
1416
+    /**
1417
+     * @return \OCP\Contacts\IManager
1418
+     * @deprecated 20.0.0
1419
+     */
1420
+    public function getContactsManager() {
1421
+        return $this->get(\OCP\Contacts\IManager::class);
1422
+    }
1423
+
1424
+    /**
1425
+     * @return \OC\Encryption\Manager
1426
+     * @deprecated 20.0.0
1427
+     */
1428
+    public function getEncryptionManager() {
1429
+        return $this->get(\OCP\Encryption\IManager::class);
1430
+    }
1431
+
1432
+    /**
1433
+     * @return \OC\Encryption\File
1434
+     * @deprecated 20.0.0
1435
+     */
1436
+    public function getEncryptionFilesHelper() {
1437
+        return $this->get(IFile::class);
1438
+    }
1439
+
1440
+    /**
1441
+     * @return \OCP\Encryption\Keys\IStorage
1442
+     * @deprecated 20.0.0
1443
+     */
1444
+    public function getEncryptionKeyStorage() {
1445
+        return $this->get(IStorage::class);
1446
+    }
1447
+
1448
+    /**
1449
+     * The current request object holding all information about the request
1450
+     * currently being processed is returned from this method.
1451
+     * In case the current execution was not initiated by a web request null is returned
1452
+     *
1453
+     * @return \OCP\IRequest
1454
+     * @deprecated 20.0.0
1455
+     */
1456
+    public function getRequest() {
1457
+        return $this->get(IRequest::class);
1458
+    }
1459
+
1460
+    /**
1461
+     * Returns the preview manager which can create preview images for a given file
1462
+     *
1463
+     * @return IPreview
1464
+     * @deprecated 20.0.0
1465
+     */
1466
+    public function getPreviewManager() {
1467
+        return $this->get(IPreview::class);
1468
+    }
1469
+
1470
+    /**
1471
+     * Returns the tag manager which can get and set tags for different object types
1472
+     *
1473
+     * @see \OCP\ITagManager::load()
1474
+     * @return ITagManager
1475
+     * @deprecated 20.0.0
1476
+     */
1477
+    public function getTagManager() {
1478
+        return $this->get(ITagManager::class);
1479
+    }
1480
+
1481
+    /**
1482
+     * Returns the system-tag manager
1483
+     *
1484
+     * @return ISystemTagManager
1485
+     *
1486
+     * @since 9.0.0
1487
+     * @deprecated 20.0.0
1488
+     */
1489
+    public function getSystemTagManager() {
1490
+        return $this->get(ISystemTagManager::class);
1491
+    }
1492
+
1493
+    /**
1494
+     * Returns the system-tag object mapper
1495
+     *
1496
+     * @return ISystemTagObjectMapper
1497
+     *
1498
+     * @since 9.0.0
1499
+     * @deprecated 20.0.0
1500
+     */
1501
+    public function getSystemTagObjectMapper() {
1502
+        return $this->get(ISystemTagObjectMapper::class);
1503
+    }
1504
+
1505
+    /**
1506
+     * Returns the avatar manager, used for avatar functionality
1507
+     *
1508
+     * @return IAvatarManager
1509
+     * @deprecated 20.0.0
1510
+     */
1511
+    public function getAvatarManager() {
1512
+        return $this->get(IAvatarManager::class);
1513
+    }
1514
+
1515
+    /**
1516
+     * Returns the root folder of ownCloud's data directory
1517
+     *
1518
+     * @return IRootFolder
1519
+     * @deprecated 20.0.0
1520
+     */
1521
+    public function getRootFolder() {
1522
+        return $this->get(IRootFolder::class);
1523
+    }
1524
+
1525
+    /**
1526
+     * Returns the root folder of ownCloud's data directory
1527
+     * This is the lazy variant so this gets only initialized once it
1528
+     * is actually used.
1529
+     *
1530
+     * @return IRootFolder
1531
+     * @deprecated 20.0.0
1532
+     */
1533
+    public function getLazyRootFolder() {
1534
+        return $this->get(IRootFolder::class);
1535
+    }
1536
+
1537
+    /**
1538
+     * Returns a view to ownCloud's files folder
1539
+     *
1540
+     * @param string $userId user ID
1541
+     * @return \OCP\Files\Folder|null
1542
+     * @deprecated 20.0.0
1543
+     */
1544
+    public function getUserFolder($userId = null) {
1545
+        if ($userId === null) {
1546
+            $user = $this->get(IUserSession::class)->getUser();
1547
+            if (!$user) {
1548
+                return null;
1549
+            }
1550
+            $userId = $user->getUID();
1551
+        }
1552
+        $root = $this->get(IRootFolder::class);
1553
+        return $root->getUserFolder($userId);
1554
+    }
1555
+
1556
+    /**
1557
+     * @return \OC\User\Manager
1558
+     * @deprecated 20.0.0
1559
+     */
1560
+    public function getUserManager() {
1561
+        return $this->get(IUserManager::class);
1562
+    }
1563
+
1564
+    /**
1565
+     * @return \OC\Group\Manager
1566
+     * @deprecated 20.0.0
1567
+     */
1568
+    public function getGroupManager() {
1569
+        return $this->get(IGroupManager::class);
1570
+    }
1571
+
1572
+    /**
1573
+     * @return \OC\User\Session
1574
+     * @deprecated 20.0.0
1575
+     */
1576
+    public function getUserSession() {
1577
+        return $this->get(IUserSession::class);
1578
+    }
1579
+
1580
+    /**
1581
+     * @return \OCP\ISession
1582
+     * @deprecated 20.0.0
1583
+     */
1584
+    public function getSession() {
1585
+        return $this->get(IUserSession::class)->getSession();
1586
+    }
1587
+
1588
+    /**
1589
+     * @param \OCP\ISession $session
1590
+     */
1591
+    public function setSession(\OCP\ISession $session) {
1592
+        $this->get(SessionStorage::class)->setSession($session);
1593
+        $this->get(IUserSession::class)->setSession($session);
1594
+        $this->get(Store::class)->setSession($session);
1595
+    }
1596
+
1597
+    /**
1598
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1599
+     * @deprecated 20.0.0
1600
+     */
1601
+    public function getTwoFactorAuthManager() {
1602
+        return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class);
1603
+    }
1604
+
1605
+    /**
1606
+     * @return \OC\NavigationManager
1607
+     * @deprecated 20.0.0
1608
+     */
1609
+    public function getNavigationManager() {
1610
+        return $this->get(INavigationManager::class);
1611
+    }
1612
+
1613
+    /**
1614
+     * @return \OCP\IConfig
1615
+     * @deprecated 20.0.0
1616
+     */
1617
+    public function getConfig() {
1618
+        return $this->get(AllConfig::class);
1619
+    }
1620
+
1621
+    /**
1622
+     * @return \OC\SystemConfig
1623
+     * @deprecated 20.0.0
1624
+     */
1625
+    public function getSystemConfig() {
1626
+        return $this->get(SystemConfig::class);
1627
+    }
1628
+
1629
+    /**
1630
+     * Returns the app config manager
1631
+     *
1632
+     * @return IAppConfig
1633
+     * @deprecated 20.0.0
1634
+     */
1635
+    public function getAppConfig() {
1636
+        return $this->get(IAppConfig::class);
1637
+    }
1638
+
1639
+    /**
1640
+     * @return IFactory
1641
+     * @deprecated 20.0.0
1642
+     */
1643
+    public function getL10NFactory() {
1644
+        return $this->get(IFactory::class);
1645
+    }
1646
+
1647
+    /**
1648
+     * get an L10N instance
1649
+     *
1650
+     * @param string $app appid
1651
+     * @param string $lang
1652
+     * @return IL10N
1653
+     * @deprecated 20.0.0
1654
+     */
1655
+    public function getL10N($app, $lang = null) {
1656
+        return $this->get(IFactory::class)->get($app, $lang);
1657
+    }
1658
+
1659
+    /**
1660
+     * @return IURLGenerator
1661
+     * @deprecated 20.0.0
1662
+     */
1663
+    public function getURLGenerator() {
1664
+        return $this->get(IURLGenerator::class);
1665
+    }
1666
+
1667
+    /**
1668
+     * @return AppFetcher
1669
+     * @deprecated 20.0.0
1670
+     */
1671
+    public function getAppFetcher() {
1672
+        return $this->get(AppFetcher::class);
1673
+    }
1674
+
1675
+    /**
1676
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1677
+     * getMemCacheFactory() instead.
1678
+     *
1679
+     * @return ICache
1680
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1681
+     */
1682
+    public function getCache() {
1683
+        return $this->get(ICache::class);
1684
+    }
1685
+
1686
+    /**
1687
+     * Returns an \OCP\CacheFactory instance
1688
+     *
1689
+     * @return \OCP\ICacheFactory
1690
+     * @deprecated 20.0.0
1691
+     */
1692
+    public function getMemCacheFactory() {
1693
+        return $this->get(ICacheFactory::class);
1694
+    }
1695
+
1696
+    /**
1697
+     * Returns an \OC\RedisFactory instance
1698
+     *
1699
+     * @return \OC\RedisFactory
1700
+     * @deprecated 20.0.0
1701
+     */
1702
+    public function getGetRedisFactory() {
1703
+        return $this->get('RedisFactory');
1704
+    }
1705
+
1706
+
1707
+    /**
1708
+     * Returns the current session
1709
+     *
1710
+     * @return \OCP\IDBConnection
1711
+     * @deprecated 20.0.0
1712
+     */
1713
+    public function getDatabaseConnection() {
1714
+        return $this->get(IDBConnection::class);
1715
+    }
1716
+
1717
+    /**
1718
+     * Returns the activity manager
1719
+     *
1720
+     * @return \OCP\Activity\IManager
1721
+     * @deprecated 20.0.0
1722
+     */
1723
+    public function getActivityManager() {
1724
+        return $this->get(\OCP\Activity\IManager::class);
1725
+    }
1726
+
1727
+    /**
1728
+     * Returns an job list for controlling background jobs
1729
+     *
1730
+     * @return IJobList
1731
+     * @deprecated 20.0.0
1732
+     */
1733
+    public function getJobList() {
1734
+        return $this->get(IJobList::class);
1735
+    }
1736
+
1737
+    /**
1738
+     * Returns a logger instance
1739
+     *
1740
+     * @return ILogger
1741
+     * @deprecated 20.0.0
1742
+     */
1743
+    public function getLogger() {
1744
+        return $this->get(ILogger::class);
1745
+    }
1746
+
1747
+    /**
1748
+     * @return ILogFactory
1749
+     * @throws \OCP\AppFramework\QueryException
1750
+     * @deprecated 20.0.0
1751
+     */
1752
+    public function getLogFactory() {
1753
+        return $this->get(ILogFactory::class);
1754
+    }
1755
+
1756
+    /**
1757
+     * Returns a router for generating and matching urls
1758
+     *
1759
+     * @return IRouter
1760
+     * @deprecated 20.0.0
1761
+     */
1762
+    public function getRouter() {
1763
+        return $this->get(IRouter::class);
1764
+    }
1765
+
1766
+    /**
1767
+     * Returns a search instance
1768
+     *
1769
+     * @return ISearch
1770
+     * @deprecated 20.0.0
1771
+     */
1772
+    public function getSearch() {
1773
+        return $this->get(ISearch::class);
1774
+    }
1775
+
1776
+    /**
1777
+     * Returns a SecureRandom instance
1778
+     *
1779
+     * @return \OCP\Security\ISecureRandom
1780
+     * @deprecated 20.0.0
1781
+     */
1782
+    public function getSecureRandom() {
1783
+        return $this->get(ISecureRandom::class);
1784
+    }
1785
+
1786
+    /**
1787
+     * Returns a Crypto instance
1788
+     *
1789
+     * @return ICrypto
1790
+     * @deprecated 20.0.0
1791
+     */
1792
+    public function getCrypto() {
1793
+        return $this->get(ICrypto::class);
1794
+    }
1795
+
1796
+    /**
1797
+     * Returns a Hasher instance
1798
+     *
1799
+     * @return IHasher
1800
+     * @deprecated 20.0.0
1801
+     */
1802
+    public function getHasher() {
1803
+        return $this->get(IHasher::class);
1804
+    }
1805
+
1806
+    /**
1807
+     * Returns a CredentialsManager instance
1808
+     *
1809
+     * @return ICredentialsManager
1810
+     * @deprecated 20.0.0
1811
+     */
1812
+    public function getCredentialsManager() {
1813
+        return $this->get(ICredentialsManager::class);
1814
+    }
1815
+
1816
+    /**
1817
+     * Get the certificate manager
1818
+     *
1819
+     * @return \OCP\ICertificateManager
1820
+     */
1821
+    public function getCertificateManager() {
1822
+        return $this->get(ICertificateManager::class);
1823
+    }
1824
+
1825
+    /**
1826
+     * Returns an instance of the HTTP client service
1827
+     *
1828
+     * @return IClientService
1829
+     * @deprecated 20.0.0
1830
+     */
1831
+    public function getHTTPClientService() {
1832
+        return $this->get(IClientService::class);
1833
+    }
1834
+
1835
+    /**
1836
+     * Create a new event source
1837
+     *
1838
+     * @return \OCP\IEventSource
1839
+     * @deprecated 20.0.0
1840
+     */
1841
+    public function createEventSource() {
1842
+        return new \OC_EventSource();
1843
+    }
1844
+
1845
+    /**
1846
+     * Get the active event logger
1847
+     *
1848
+     * The returned logger only logs data when debug mode is enabled
1849
+     *
1850
+     * @return IEventLogger
1851
+     * @deprecated 20.0.0
1852
+     */
1853
+    public function getEventLogger() {
1854
+        return $this->get(IEventLogger::class);
1855
+    }
1856
+
1857
+    /**
1858
+     * Get the active query logger
1859
+     *
1860
+     * The returned logger only logs data when debug mode is enabled
1861
+     *
1862
+     * @return IQueryLogger
1863
+     * @deprecated 20.0.0
1864
+     */
1865
+    public function getQueryLogger() {
1866
+        return $this->get(IQueryLogger::class);
1867
+    }
1868
+
1869
+    /**
1870
+     * Get the manager for temporary files and folders
1871
+     *
1872
+     * @return \OCP\ITempManager
1873
+     * @deprecated 20.0.0
1874
+     */
1875
+    public function getTempManager() {
1876
+        return $this->get(ITempManager::class);
1877
+    }
1878
+
1879
+    /**
1880
+     * Get the app manager
1881
+     *
1882
+     * @return \OCP\App\IAppManager
1883
+     * @deprecated 20.0.0
1884
+     */
1885
+    public function getAppManager() {
1886
+        return $this->get(IAppManager::class);
1887
+    }
1888
+
1889
+    /**
1890
+     * Creates a new mailer
1891
+     *
1892
+     * @return IMailer
1893
+     * @deprecated 20.0.0
1894
+     */
1895
+    public function getMailer() {
1896
+        return $this->get(IMailer::class);
1897
+    }
1898
+
1899
+    /**
1900
+     * Get the webroot
1901
+     *
1902
+     * @return string
1903
+     * @deprecated 20.0.0
1904
+     */
1905
+    public function getWebRoot() {
1906
+        return $this->webRoot;
1907
+    }
1908
+
1909
+    /**
1910
+     * @return \OC\OCSClient
1911
+     * @deprecated 20.0.0
1912
+     */
1913
+    public function getOcsClient() {
1914
+        return $this->get('OcsClient');
1915
+    }
1916
+
1917
+    /**
1918
+     * @return IDateTimeZone
1919
+     * @deprecated 20.0.0
1920
+     */
1921
+    public function getDateTimeZone() {
1922
+        return $this->get(IDateTimeZone::class);
1923
+    }
1924
+
1925
+    /**
1926
+     * @return IDateTimeFormatter
1927
+     * @deprecated 20.0.0
1928
+     */
1929
+    public function getDateTimeFormatter() {
1930
+        return $this->get(IDateTimeFormatter::class);
1931
+    }
1932
+
1933
+    /**
1934
+     * @return IMountProviderCollection
1935
+     * @deprecated 20.0.0
1936
+     */
1937
+    public function getMountProviderCollection() {
1938
+        return $this->get(IMountProviderCollection::class);
1939
+    }
1940
+
1941
+    /**
1942
+     * Get the IniWrapper
1943
+     *
1944
+     * @return IniGetWrapper
1945
+     * @deprecated 20.0.0
1946
+     */
1947
+    public function getIniWrapper() {
1948
+        return $this->get(IniGetWrapper::class);
1949
+    }
1950
+
1951
+    /**
1952
+     * @return \OCP\Command\IBus
1953
+     * @deprecated 20.0.0
1954
+     */
1955
+    public function getCommandBus() {
1956
+        return $this->get(IBus::class);
1957
+    }
1958
+
1959
+    /**
1960
+     * Get the trusted domain helper
1961
+     *
1962
+     * @return TrustedDomainHelper
1963
+     * @deprecated 20.0.0
1964
+     */
1965
+    public function getTrustedDomainHelper() {
1966
+        return $this->get(TrustedDomainHelper::class);
1967
+    }
1968
+
1969
+    /**
1970
+     * Get the locking provider
1971
+     *
1972
+     * @return ILockingProvider
1973
+     * @since 8.1.0
1974
+     * @deprecated 20.0.0
1975
+     */
1976
+    public function getLockingProvider() {
1977
+        return $this->get(ILockingProvider::class);
1978
+    }
1979
+
1980
+    /**
1981
+     * @return IMountManager
1982
+     * @deprecated 20.0.0
1983
+     **/
1984
+    public function getMountManager() {
1985
+        return $this->get(IMountManager::class);
1986
+    }
1987
+
1988
+    /**
1989
+     * @return IUserMountCache
1990
+     * @deprecated 20.0.0
1991
+     */
1992
+    public function getUserMountCache() {
1993
+        return $this->get(IUserMountCache::class);
1994
+    }
1995
+
1996
+    /**
1997
+     * Get the MimeTypeDetector
1998
+     *
1999
+     * @return IMimeTypeDetector
2000
+     * @deprecated 20.0.0
2001
+     */
2002
+    public function getMimeTypeDetector() {
2003
+        return $this->get(IMimeTypeDetector::class);
2004
+    }
2005
+
2006
+    /**
2007
+     * Get the MimeTypeLoader
2008
+     *
2009
+     * @return IMimeTypeLoader
2010
+     * @deprecated 20.0.0
2011
+     */
2012
+    public function getMimeTypeLoader() {
2013
+        return $this->get(IMimeTypeLoader::class);
2014
+    }
2015
+
2016
+    /**
2017
+     * Get the manager of all the capabilities
2018
+     *
2019
+     * @return CapabilitiesManager
2020
+     * @deprecated 20.0.0
2021
+     */
2022
+    public function getCapabilitiesManager() {
2023
+        return $this->get(CapabilitiesManager::class);
2024
+    }
2025
+
2026
+    /**
2027
+     * Get the EventDispatcher
2028
+     *
2029
+     * @return EventDispatcherInterface
2030
+     * @since 8.2.0
2031
+     * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher
2032
+     */
2033
+    public function getEventDispatcher() {
2034
+        return $this->get(\OC\EventDispatcher\SymfonyAdapter::class);
2035
+    }
2036
+
2037
+    /**
2038
+     * Get the Notification Manager
2039
+     *
2040
+     * @return \OCP\Notification\IManager
2041
+     * @since 8.2.0
2042
+     * @deprecated 20.0.0
2043
+     */
2044
+    public function getNotificationManager() {
2045
+        return $this->get(\OCP\Notification\IManager::class);
2046
+    }
2047
+
2048
+    /**
2049
+     * @return ICommentsManager
2050
+     * @deprecated 20.0.0
2051
+     */
2052
+    public function getCommentsManager() {
2053
+        return $this->get(ICommentsManager::class);
2054
+    }
2055
+
2056
+    /**
2057
+     * @return \OCA\Theming\ThemingDefaults
2058
+     * @deprecated 20.0.0
2059
+     */
2060
+    public function getThemingDefaults() {
2061
+        return $this->get('ThemingDefaults');
2062
+    }
2063
+
2064
+    /**
2065
+     * @return \OC\IntegrityCheck\Checker
2066
+     * @deprecated 20.0.0
2067
+     */
2068
+    public function getIntegrityCodeChecker() {
2069
+        return $this->get('IntegrityCodeChecker');
2070
+    }
2071
+
2072
+    /**
2073
+     * @return \OC\Session\CryptoWrapper
2074
+     * @deprecated 20.0.0
2075
+     */
2076
+    public function getSessionCryptoWrapper() {
2077
+        return $this->get('CryptoWrapper');
2078
+    }
2079
+
2080
+    /**
2081
+     * @return CsrfTokenManager
2082
+     * @deprecated 20.0.0
2083
+     */
2084
+    public function getCsrfTokenManager() {
2085
+        return $this->get(CsrfTokenManager::class);
2086
+    }
2087
+
2088
+    /**
2089
+     * @return Throttler
2090
+     * @deprecated 20.0.0
2091
+     */
2092
+    public function getBruteForceThrottler() {
2093
+        return $this->get(Throttler::class);
2094
+    }
2095
+
2096
+    /**
2097
+     * @return IContentSecurityPolicyManager
2098
+     * @deprecated 20.0.0
2099
+     */
2100
+    public function getContentSecurityPolicyManager() {
2101
+        return $this->get(ContentSecurityPolicyManager::class);
2102
+    }
2103
+
2104
+    /**
2105
+     * @return ContentSecurityPolicyNonceManager
2106
+     * @deprecated 20.0.0
2107
+     */
2108
+    public function getContentSecurityPolicyNonceManager() {
2109
+        return $this->get(ContentSecurityPolicyNonceManager::class);
2110
+    }
2111
+
2112
+    /**
2113
+     * Not a public API as of 8.2, wait for 9.0
2114
+     *
2115
+     * @return \OCA\Files_External\Service\BackendService
2116
+     * @deprecated 20.0.0
2117
+     */
2118
+    public function getStoragesBackendService() {
2119
+        return $this->get(BackendService::class);
2120
+    }
2121
+
2122
+    /**
2123
+     * Not a public API as of 8.2, wait for 9.0
2124
+     *
2125
+     * @return \OCA\Files_External\Service\GlobalStoragesService
2126
+     * @deprecated 20.0.0
2127
+     */
2128
+    public function getGlobalStoragesService() {
2129
+        return $this->get(GlobalStoragesService::class);
2130
+    }
2131
+
2132
+    /**
2133
+     * Not a public API as of 8.2, wait for 9.0
2134
+     *
2135
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
2136
+     * @deprecated 20.0.0
2137
+     */
2138
+    public function getUserGlobalStoragesService() {
2139
+        return $this->get(UserGlobalStoragesService::class);
2140
+    }
2141
+
2142
+    /**
2143
+     * Not a public API as of 8.2, wait for 9.0
2144
+     *
2145
+     * @return \OCA\Files_External\Service\UserStoragesService
2146
+     * @deprecated 20.0.0
2147
+     */
2148
+    public function getUserStoragesService() {
2149
+        return $this->get(UserStoragesService::class);
2150
+    }
2151
+
2152
+    /**
2153
+     * @return \OCP\Share\IManager
2154
+     * @deprecated 20.0.0
2155
+     */
2156
+    public function getShareManager() {
2157
+        return $this->get(\OCP\Share\IManager::class);
2158
+    }
2159
+
2160
+    /**
2161
+     * @return \OCP\Collaboration\Collaborators\ISearch
2162
+     * @deprecated 20.0.0
2163
+     */
2164
+    public function getCollaboratorSearch() {
2165
+        return $this->get(\OCP\Collaboration\Collaborators\ISearch::class);
2166
+    }
2167
+
2168
+    /**
2169
+     * @return \OCP\Collaboration\AutoComplete\IManager
2170
+     * @deprecated 20.0.0
2171
+     */
2172
+    public function getAutoCompleteManager() {
2173
+        return $this->get(IManager::class);
2174
+    }
2175
+
2176
+    /**
2177
+     * Returns the LDAP Provider
2178
+     *
2179
+     * @return \OCP\LDAP\ILDAPProvider
2180
+     * @deprecated 20.0.0
2181
+     */
2182
+    public function getLDAPProvider() {
2183
+        return $this->get('LDAPProvider');
2184
+    }
2185
+
2186
+    /**
2187
+     * @return \OCP\Settings\IManager
2188
+     * @deprecated 20.0.0
2189
+     */
2190
+    public function getSettingsManager() {
2191
+        return $this->get(\OC\Settings\Manager::class);
2192
+    }
2193
+
2194
+    /**
2195
+     * @return \OCP\Files\IAppData
2196
+     * @deprecated 20.0.0
2197
+     */
2198
+    public function getAppDataDir($app) {
2199
+        /** @var \OC\Files\AppData\Factory $factory */
2200
+        $factory = $this->get(\OC\Files\AppData\Factory::class);
2201
+        return $factory->get($app);
2202
+    }
2203
+
2204
+    /**
2205
+     * @return \OCP\Lockdown\ILockdownManager
2206
+     * @deprecated 20.0.0
2207
+     */
2208
+    public function getLockdownManager() {
2209
+        return $this->get('LockdownManager');
2210
+    }
2211
+
2212
+    /**
2213
+     * @return \OCP\Federation\ICloudIdManager
2214
+     * @deprecated 20.0.0
2215
+     */
2216
+    public function getCloudIdManager() {
2217
+        return $this->get(ICloudIdManager::class);
2218
+    }
2219
+
2220
+    /**
2221
+     * @return \OCP\GlobalScale\IConfig
2222
+     * @deprecated 20.0.0
2223
+     */
2224
+    public function getGlobalScaleConfig() {
2225
+        return $this->get(IConfig::class);
2226
+    }
2227
+
2228
+    /**
2229
+     * @return \OCP\Federation\ICloudFederationProviderManager
2230
+     * @deprecated 20.0.0
2231
+     */
2232
+    public function getCloudFederationProviderManager() {
2233
+        return $this->get(ICloudFederationProviderManager::class);
2234
+    }
2235
+
2236
+    /**
2237
+     * @return \OCP\Remote\Api\IApiFactory
2238
+     * @deprecated 20.0.0
2239
+     */
2240
+    public function getRemoteApiFactory() {
2241
+        return $this->get(IApiFactory::class);
2242
+    }
2243
+
2244
+    /**
2245
+     * @return \OCP\Federation\ICloudFederationFactory
2246
+     * @deprecated 20.0.0
2247
+     */
2248
+    public function getCloudFederationFactory() {
2249
+        return $this->get(ICloudFederationFactory::class);
2250
+    }
2251
+
2252
+    /**
2253
+     * @return \OCP\Remote\IInstanceFactory
2254
+     * @deprecated 20.0.0
2255
+     */
2256
+    public function getRemoteInstanceFactory() {
2257
+        return $this->get(IInstanceFactory::class);
2258
+    }
2259
+
2260
+    /**
2261
+     * @return IStorageFactory
2262
+     * @deprecated 20.0.0
2263
+     */
2264
+    public function getStorageFactory() {
2265
+        return $this->get(IStorageFactory::class);
2266
+    }
2267
+
2268
+    /**
2269
+     * Get the Preview GeneratorHelper
2270
+     *
2271
+     * @return GeneratorHelper
2272
+     * @since 17.0.0
2273
+     * @deprecated 20.0.0
2274
+     */
2275
+    public function getGeneratorHelper() {
2276
+        return $this->get(\OC\Preview\GeneratorHelper::class);
2277
+    }
2278
+
2279
+    private function registerDeprecatedAlias(string $alias, string $target) {
2280
+        $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) {
2281
+            try {
2282
+                /** @var ILogger $logger */
2283
+                $logger = $container->get(ILogger::class);
2284
+                $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
2285
+            } catch (ContainerExceptionInterface $e) {
2286
+                // Could not get logger. Continue
2287
+            }
2288
+
2289
+            return $container->get($target);
2290
+        }, false);
2291
+    }
2292 2292
 }
Please login to merge, or discard this patch.