1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @copyright 2020 Christoph Wurst <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @author Christoph Wurst <[email protected]> |
9
|
|
|
* @author Joas Schilling <[email protected]> |
10
|
|
|
* @author Julius Härtl <[email protected]> |
11
|
|
|
* @author Roeland Jago Douma <[email protected]> |
12
|
|
|
* |
13
|
|
|
* @license GNU AGPL version 3 or any later version |
14
|
|
|
* |
15
|
|
|
* This program is free software: you can redistribute it and/or modify |
16
|
|
|
* it under the terms of the GNU Affero General Public License as |
17
|
|
|
* published by the Free Software Foundation, either version 3 of the |
18
|
|
|
* License, or (at your option) any later version. |
19
|
|
|
* |
20
|
|
|
* This program is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU Affero General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* You should have received a copy of the GNU Affero General Public License |
26
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
27
|
|
|
* |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
namespace OC\AppFramework\Bootstrap; |
31
|
|
|
|
32
|
|
|
use Closure; |
33
|
|
|
use OCP\Calendar\Resource\IBackend as IResourceBackend; |
34
|
|
|
use OCP\Calendar\Room\IBackend as IRoomBackend; |
35
|
|
|
use OCP\Collaboration\Reference\IReferenceProvider; |
36
|
|
|
use OCP\SpeechToText\ISpeechToTextProvider; |
37
|
|
|
use OCP\Talk\ITalkBackend; |
38
|
|
|
use OCP\Translation\ITranslationProvider; |
39
|
|
|
use RuntimeException; |
40
|
|
|
use function array_shift; |
41
|
|
|
use OC\Support\CrashReport\Registry; |
42
|
|
|
use OCP\AppFramework\App; |
43
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext; |
44
|
|
|
use OCP\AppFramework\Middleware; |
45
|
|
|
use OCP\AppFramework\Services\InitialStateProvider; |
46
|
|
|
use OCP\Authentication\IAlternativeLogin; |
47
|
|
|
use OCP\Calendar\ICalendarProvider; |
48
|
|
|
use OCP\Capabilities\ICapability; |
49
|
|
|
use OCP\Dashboard\IManager; |
50
|
|
|
use OCP\Dashboard\IWidget; |
51
|
|
|
use OCP\EventDispatcher\IEventDispatcher; |
52
|
|
|
use OCP\Files\Template\ICustomTemplateProvider; |
53
|
|
|
use OCP\Http\WellKnown\IHandler; |
54
|
|
|
use OCP\Notification\INotifier; |
55
|
|
|
use OCP\Profile\ILinkAction; |
56
|
|
|
use OCP\Search\IProvider; |
57
|
|
|
use OCP\Share\IPublicShareTemplateProvider; |
58
|
|
|
use OCP\Support\CrashReport\IReporter; |
59
|
|
|
use OCP\UserMigration\IMigrator as IUserMigrator; |
60
|
|
|
use Psr\Log\LoggerInterface; |
61
|
|
|
use Throwable; |
62
|
|
|
|
63
|
|
|
class RegistrationContext { |
64
|
|
|
/** @var ServiceRegistration<ICapability>[] */ |
65
|
|
|
private $capabilities = []; |
66
|
|
|
|
67
|
|
|
/** @var ServiceRegistration<IReporter>[] */ |
68
|
|
|
private $crashReporters = []; |
69
|
|
|
|
70
|
|
|
/** @var ServiceRegistration<IWidget>[] */ |
71
|
|
|
private $dashboardPanels = []; |
72
|
|
|
|
73
|
|
|
/** @var ServiceRegistration<ILinkAction>[] */ |
74
|
|
|
private $profileLinkActions = []; |
75
|
|
|
|
76
|
|
|
/** @var null|ServiceRegistration<ITalkBackend> */ |
77
|
|
|
private $talkBackendRegistration = null; |
78
|
|
|
|
79
|
|
|
/** @var ServiceRegistration<IResourceBackend>[] */ |
80
|
|
|
private $calendarResourceBackendRegistrations = []; |
81
|
|
|
|
82
|
|
|
/** @var ServiceRegistration<IRoomBackend>[] */ |
83
|
|
|
private $calendarRoomBackendRegistrations = []; |
84
|
|
|
|
85
|
|
|
/** @var ServiceRegistration<IUserMigrator>[] */ |
86
|
|
|
private $userMigrators = []; |
87
|
|
|
|
88
|
|
|
/** @var ServiceFactoryRegistration[] */ |
89
|
|
|
private $services = []; |
90
|
|
|
|
91
|
|
|
/** @var ServiceAliasRegistration[] */ |
92
|
|
|
private $aliases = []; |
93
|
|
|
|
94
|
|
|
/** @var ParameterRegistration[] */ |
95
|
|
|
private $parameters = []; |
96
|
|
|
|
97
|
|
|
/** @var EventListenerRegistration[] */ |
98
|
|
|
private $eventListeners = []; |
99
|
|
|
|
100
|
|
|
/** @var MiddlewareRegistration[] */ |
101
|
|
|
private $middlewares = []; |
102
|
|
|
|
103
|
|
|
/** @var ServiceRegistration<IProvider>[] */ |
104
|
|
|
private $searchProviders = []; |
105
|
|
|
|
106
|
|
|
/** @var ServiceRegistration<IAlternativeLogin>[] */ |
107
|
|
|
private $alternativeLogins = []; |
108
|
|
|
|
109
|
|
|
/** @var ServiceRegistration<InitialStateProvider>[] */ |
110
|
|
|
private $initialStates = []; |
111
|
|
|
|
112
|
|
|
/** @var ServiceRegistration<IHandler>[] */ |
113
|
|
|
private $wellKnownHandlers = []; |
114
|
|
|
|
115
|
|
|
/** @var ServiceRegistration<ISpeechToTextProvider>[] */ |
116
|
|
|
private $speechToTextProviders = []; |
117
|
|
|
|
118
|
|
|
/** @var ServiceRegistration<ICustomTemplateProvider>[] */ |
119
|
|
|
private $templateProviders = []; |
120
|
|
|
|
121
|
|
|
/** @var ServiceRegistration<ITranslationProvider>[] */ |
122
|
|
|
private $translationProviders = []; |
123
|
|
|
|
124
|
|
|
/** @var ServiceRegistration<INotifier>[] */ |
125
|
|
|
private $notifierServices = []; |
126
|
|
|
|
127
|
|
|
/** @var ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] */ |
128
|
|
|
private $twoFactorProviders = []; |
129
|
|
|
|
130
|
|
|
/** @var ServiceRegistration<ICalendarProvider>[] */ |
131
|
|
|
private $calendarProviders = []; |
132
|
|
|
|
133
|
|
|
/** @var ServiceRegistration<IReferenceProvider>[] */ |
134
|
|
|
private array $referenceProviders = []; |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
|
138
|
|
|
|
139
|
|
|
/** @var ParameterRegistration[] */ |
140
|
|
|
private $sensitiveMethods = []; |
141
|
|
|
|
142
|
|
|
/** @var ServiceRegistration<IPublicShareTemplateProvider>[] */ |
143
|
|
|
private $publicShareTemplateProviders = []; |
144
|
|
|
|
145
|
|
|
/** @var LoggerInterface */ |
146
|
|
|
private $logger; |
147
|
|
|
|
148
|
|
|
/** @var PreviewProviderRegistration[] */ |
149
|
|
|
private $previewProviders = []; |
150
|
|
|
|
151
|
|
|
public function __construct(LoggerInterface $logger) { |
152
|
|
|
$this->logger = $logger; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function for(string $appId): IRegistrationContext { |
156
|
|
|
return new class($appId, $this) implements IRegistrationContext { |
157
|
|
|
/** @var string */ |
158
|
|
|
private $appId; |
159
|
|
|
|
160
|
|
|
/** @var RegistrationContext */ |
161
|
|
|
private $context; |
162
|
|
|
|
163
|
|
|
public function __construct(string $appId, RegistrationContext $context) { |
164
|
|
|
$this->appId = $appId; |
165
|
|
|
$this->context = $context; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function registerCapability(string $capability): void { |
169
|
|
|
$this->context->registerCapability( |
170
|
|
|
$this->appId, |
171
|
|
|
$capability |
172
|
|
|
); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function registerCrashReporter(string $reporterClass): void { |
176
|
|
|
$this->context->registerCrashReporter( |
177
|
|
|
$this->appId, |
178
|
|
|
$reporterClass |
179
|
|
|
); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function registerDashboardWidget(string $widgetClass): void { |
183
|
|
|
$this->context->registerDashboardPanel( |
184
|
|
|
$this->appId, |
185
|
|
|
$widgetClass |
186
|
|
|
); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function registerService(string $name, callable $factory, bool $shared = true): void { |
190
|
|
|
$this->context->registerService( |
191
|
|
|
$this->appId, |
192
|
|
|
$name, |
193
|
|
|
$factory, |
194
|
|
|
$shared |
195
|
|
|
); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function registerServiceAlias(string $alias, string $target): void { |
199
|
|
|
$this->context->registerServiceAlias( |
200
|
|
|
$this->appId, |
201
|
|
|
$alias, |
202
|
|
|
$target |
203
|
|
|
); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function registerParameter(string $name, $value): void { |
207
|
|
|
$this->context->registerParameter( |
208
|
|
|
$this->appId, |
209
|
|
|
$name, |
210
|
|
|
$value |
211
|
|
|
); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
public function registerEventListener(string $event, string $listener, int $priority = 0): void { |
215
|
|
|
$this->context->registerEventListener( |
216
|
|
|
$this->appId, |
217
|
|
|
$event, |
218
|
|
|
$listener, |
219
|
|
|
$priority |
220
|
|
|
); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public function registerMiddleware(string $class, bool $global = false): void { |
224
|
|
|
$this->context->registerMiddleware( |
225
|
|
|
$this->appId, |
226
|
|
|
$class, |
227
|
|
|
$global, |
228
|
|
|
); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
public function registerSearchProvider(string $class): void { |
232
|
|
|
$this->context->registerSearchProvider( |
233
|
|
|
$this->appId, |
234
|
|
|
$class |
235
|
|
|
); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
public function registerAlternativeLogin(string $class): void { |
239
|
|
|
$this->context->registerAlternativeLogin( |
240
|
|
|
$this->appId, |
241
|
|
|
$class |
242
|
|
|
); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
public function registerInitialStateProvider(string $class): void { |
246
|
|
|
$this->context->registerInitialState( |
247
|
|
|
$this->appId, |
248
|
|
|
$class |
249
|
|
|
); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
public function registerWellKnownHandler(string $class): void { |
253
|
|
|
$this->context->registerWellKnown( |
254
|
|
|
$this->appId, |
255
|
|
|
$class |
256
|
|
|
); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
public function registerSpeechToTextProvider(string $providerClass): void { |
260
|
|
|
$this->context->registerSpeechToTextProvider( |
261
|
|
|
$this->appId, |
262
|
|
|
$providerClass |
263
|
|
|
); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
public function registerTemplateProvider(string $providerClass): void { |
267
|
|
|
$this->context->registerTemplateProvider( |
268
|
|
|
$this->appId, |
269
|
|
|
$providerClass |
270
|
|
|
); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
public function registerTranslationProvider(string $providerClass): void { |
274
|
|
|
$this->context->registerTranslationProvider( |
275
|
|
|
$this->appId, |
276
|
|
|
$providerClass |
277
|
|
|
); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
public function registerNotifierService(string $notifierClass): void { |
281
|
|
|
$this->context->registerNotifierService( |
282
|
|
|
$this->appId, |
283
|
|
|
$notifierClass |
284
|
|
|
); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
public function registerTwoFactorProvider(string $twoFactorProviderClass): void { |
288
|
|
|
$this->context->registerTwoFactorProvider( |
289
|
|
|
$this->appId, |
290
|
|
|
$twoFactorProviderClass |
291
|
|
|
); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
public function registerPreviewProvider(string $previewProviderClass, string $mimeTypeRegex): void { |
295
|
|
|
$this->context->registerPreviewProvider( |
296
|
|
|
$this->appId, |
297
|
|
|
$previewProviderClass, |
298
|
|
|
$mimeTypeRegex |
299
|
|
|
); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
public function registerCalendarProvider(string $class): void { |
303
|
|
|
$this->context->registerCalendarProvider( |
304
|
|
|
$this->appId, |
305
|
|
|
$class |
306
|
|
|
); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
public function registerReferenceProvider(string $class): void { |
310
|
|
|
$this->context->registerReferenceProvider( |
311
|
|
|
$this->appId, |
312
|
|
|
$class |
313
|
|
|
); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
public function registerProfileLinkAction(string $actionClass): void { |
317
|
|
|
$this->context->registerProfileLinkAction( |
318
|
|
|
$this->appId, |
319
|
|
|
$actionClass |
320
|
|
|
); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
public function registerTalkBackend(string $backend): void { |
324
|
|
|
$this->context->registerTalkBackend( |
325
|
|
|
$this->appId, |
326
|
|
|
$backend |
327
|
|
|
); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
public function registerCalendarResourceBackend(string $class): void { |
331
|
|
|
$this->context->registerCalendarResourceBackend( |
332
|
|
|
$this->appId, |
333
|
|
|
$class |
334
|
|
|
); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
public function registerCalendarRoomBackend(string $class): void { |
338
|
|
|
$this->context->registerCalendarRoomBackend( |
339
|
|
|
$this->appId, |
340
|
|
|
$class |
341
|
|
|
); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
public function registerUserMigrator(string $migratorClass): void { |
345
|
|
|
$this->context->registerUserMigrator( |
346
|
|
|
$this->appId, |
347
|
|
|
$migratorClass |
348
|
|
|
); |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
public function registerSensitiveMethods(string $class, array $methods): void { |
352
|
|
|
$this->context->registerSensitiveMethods( |
353
|
|
|
$this->appId, |
354
|
|
|
$class, |
355
|
|
|
$methods |
356
|
|
|
); |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
public function registerPublicShareTemplateProvider(string $class): void { |
360
|
|
|
$this->context->registerPublicShareTemplateProvider( |
361
|
|
|
$this->appId, |
362
|
|
|
$class |
363
|
|
|
); |
364
|
|
|
} |
365
|
|
|
}; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* @psalm-param class-string<ICapability> $capability |
370
|
|
|
*/ |
371
|
|
|
public function registerCapability(string $appId, string $capability): void { |
372
|
|
|
$this->capabilities[] = new ServiceRegistration($appId, $capability); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* @psalm-param class-string<IReporter> $capability |
377
|
|
|
*/ |
378
|
|
|
public function registerCrashReporter(string $appId, string $reporterClass): void { |
379
|
|
|
$this->crashReporters[] = new ServiceRegistration($appId, $reporterClass); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* @psalm-param class-string<IWidget> $capability |
384
|
|
|
*/ |
385
|
|
|
public function registerDashboardPanel(string $appId, string $panelClass): void { |
386
|
|
|
$this->dashboardPanels[] = new ServiceRegistration($appId, $panelClass); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void { |
390
|
|
|
$this->services[] = new ServiceFactoryRegistration($appId, $name, $factory, $shared); |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
public function registerServiceAlias(string $appId, string $alias, string $target): void { |
394
|
|
|
$this->aliases[] = new ServiceAliasRegistration($appId, $alias, $target); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
public function registerParameter(string $appId, string $name, $value): void { |
398
|
|
|
$this->parameters[] = new ParameterRegistration($appId, $name, $value); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
public function registerEventListener(string $appId, string $event, string $listener, int $priority = 0): void { |
402
|
|
|
$this->eventListeners[] = new EventListenerRegistration($appId, $event, $listener, $priority); |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* @psalm-param class-string<Middleware> $class |
407
|
|
|
*/ |
408
|
|
|
public function registerMiddleware(string $appId, string $class, bool $global): void { |
409
|
|
|
$this->middlewares[] = new MiddlewareRegistration($appId, $class, $global); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
public function registerSearchProvider(string $appId, string $class) { |
413
|
|
|
$this->searchProviders[] = new ServiceRegistration($appId, $class); |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
public function registerAlternativeLogin(string $appId, string $class): void { |
417
|
|
|
$this->alternativeLogins[] = new ServiceRegistration($appId, $class); |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
public function registerInitialState(string $appId, string $class): void { |
421
|
|
|
$this->initialStates[] = new ServiceRegistration($appId, $class); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
public function registerWellKnown(string $appId, string $class): void { |
425
|
|
|
$this->wellKnownHandlers[] = new ServiceRegistration($appId, $class); |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
public function registerSpeechToTextProvider(string $appId, string $class): void { |
429
|
|
|
$this->speechToTextProviders[] = new ServiceRegistration($appId, $class); |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
public function registerTemplateProvider(string $appId, string $class): void { |
433
|
|
|
$this->templateProviders[] = new ServiceRegistration($appId, $class); |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
public function registerTranslationProvider(string $appId, string $class): void { |
437
|
|
|
$this->translationProviders[] = new ServiceRegistration($appId, $class); |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
public function registerNotifierService(string $appId, string $class): void { |
441
|
|
|
$this->notifierServices[] = new ServiceRegistration($appId, $class); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
public function registerTwoFactorProvider(string $appId, string $class): void { |
445
|
|
|
$this->twoFactorProviders[] = new ServiceRegistration($appId, $class); |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
public function registerPreviewProvider(string $appId, string $class, string $mimeTypeRegex): void { |
449
|
|
|
$this->previewProviders[] = new PreviewProviderRegistration($appId, $class, $mimeTypeRegex); |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
public function registerCalendarProvider(string $appId, string $class): void { |
453
|
|
|
$this->calendarProviders[] = new ServiceRegistration($appId, $class); |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
public function registerReferenceProvider(string $appId, string $class): void { |
457
|
|
|
$this->referenceProviders[] = new ServiceRegistration($appId, $class); |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
/** |
461
|
|
|
* @psalm-param class-string<ILinkAction> $actionClass |
462
|
|
|
*/ |
463
|
|
|
public function registerProfileLinkAction(string $appId, string $actionClass): void { |
464
|
|
|
$this->profileLinkActions[] = new ServiceRegistration($appId, $actionClass); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
/** |
468
|
|
|
* @psalm-param class-string<ITalkBackend> $backend |
469
|
|
|
*/ |
470
|
|
|
public function registerTalkBackend(string $appId, string $backend) { |
471
|
|
|
// Some safeguards for invalid registrations |
472
|
|
|
if ($appId !== 'spreed') { |
473
|
|
|
throw new RuntimeException("Only the Talk app is allowed to register a Talk backend"); |
474
|
|
|
} |
475
|
|
|
if ($this->talkBackendRegistration !== null) { |
476
|
|
|
throw new RuntimeException("There can only be one Talk backend"); |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
$this->talkBackendRegistration = new ServiceRegistration($appId, $backend); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
public function registerCalendarResourceBackend(string $appId, string $class) { |
483
|
|
|
$this->calendarResourceBackendRegistrations[] = new ServiceRegistration( |
484
|
|
|
$appId, |
485
|
|
|
$class, |
486
|
|
|
); |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
public function registerCalendarRoomBackend(string $appId, string $class) { |
490
|
|
|
$this->calendarRoomBackendRegistrations[] = new ServiceRegistration( |
491
|
|
|
$appId, |
492
|
|
|
$class, |
493
|
|
|
); |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
/** |
497
|
|
|
* @psalm-param class-string<IUserMigrator> $migratorClass |
498
|
|
|
*/ |
499
|
|
|
public function registerUserMigrator(string $appId, string $migratorClass): void { |
500
|
|
|
$this->userMigrators[] = new ServiceRegistration($appId, $migratorClass); |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
public function registerSensitiveMethods(string $appId, string $class, array $methods): void { |
504
|
|
|
$methods = array_filter($methods, 'is_string'); |
505
|
|
|
$this->sensitiveMethods[] = new ParameterRegistration($appId, $class, $methods); |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
public function registerPublicShareTemplateProvider(string $appId, string $class): void { |
509
|
|
|
$this->publicShareTemplateProviders[] = new ServiceRegistration($appId, $class); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* @param App[] $apps |
514
|
|
|
*/ |
515
|
|
|
public function delegateCapabilityRegistrations(array $apps): void { |
516
|
|
|
while (($registration = array_shift($this->capabilities)) !== null) { |
|
|
|
|
517
|
|
|
$appId = $registration->getAppId(); |
518
|
|
|
if (!isset($apps[$appId])) { |
519
|
|
|
// If we land here something really isn't right. But at least we caught the |
520
|
|
|
// notice that is otherwise emitted for the undefined index |
521
|
|
|
$this->logger->error("App $appId not loaded for the capability registration"); |
522
|
|
|
|
523
|
|
|
continue; |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
try { |
527
|
|
|
$apps[$appId] |
528
|
|
|
->getContainer() |
529
|
|
|
->registerCapability($registration->getService()); |
530
|
|
|
} catch (Throwable $e) { |
531
|
|
|
$this->logger->error("Error during capability registration of $appId: " . $e->getMessage(), [ |
532
|
|
|
'exception' => $e, |
533
|
|
|
]); |
534
|
|
|
} |
535
|
|
|
} |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
/** |
539
|
|
|
* @param App[] $apps |
540
|
|
|
*/ |
541
|
|
|
public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void { |
|
|
|
|
542
|
|
|
while (($registration = array_shift($this->crashReporters)) !== null) { |
|
|
|
|
543
|
|
|
try { |
544
|
|
|
$registry->registerLazy($registration->getService()); |
545
|
|
|
} catch (Throwable $e) { |
546
|
|
|
$appId = $registration->getAppId(); |
547
|
|
|
$this->logger->error("Error during crash reporter registration of $appId: " . $e->getMessage(), [ |
548
|
|
|
'exception' => $e, |
549
|
|
|
]); |
550
|
|
|
} |
551
|
|
|
} |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
/** |
555
|
|
|
* @param App[] $apps |
556
|
|
|
*/ |
557
|
|
|
public function delegateDashboardPanelRegistrations(IManager $dashboardManager): void { |
558
|
|
|
while (($panel = array_shift($this->dashboardPanels)) !== null) { |
|
|
|
|
559
|
|
|
try { |
560
|
|
|
$dashboardManager->lazyRegisterWidget($panel->getService(), $panel->getAppId()); |
561
|
|
|
} catch (Throwable $e) { |
562
|
|
|
$appId = $panel->getAppId(); |
563
|
|
|
$this->logger->error("Error during dashboard registration of $appId: " . $e->getMessage(), [ |
564
|
|
|
'exception' => $e, |
565
|
|
|
]); |
566
|
|
|
} |
567
|
|
|
} |
568
|
|
|
} |
569
|
|
|
|
570
|
|
|
public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void { |
571
|
|
|
while (($registration = array_shift($this->eventListeners)) !== null) { |
572
|
|
|
try { |
573
|
|
|
$eventDispatcher->addServiceListener( |
574
|
|
|
$registration->getEvent(), |
575
|
|
|
$registration->getService(), |
576
|
|
|
$registration->getPriority() |
577
|
|
|
); |
578
|
|
|
} catch (Throwable $e) { |
579
|
|
|
$appId = $registration->getAppId(); |
580
|
|
|
$this->logger->error("Error during event listener registration of $appId: " . $e->getMessage(), [ |
581
|
|
|
'exception' => $e, |
582
|
|
|
]); |
583
|
|
|
} |
584
|
|
|
} |
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
/** |
588
|
|
|
* @param App[] $apps |
589
|
|
|
*/ |
590
|
|
|
public function delegateContainerRegistrations(array $apps): void { |
591
|
|
|
while (($registration = array_shift($this->services)) !== null) { |
592
|
|
|
$appId = $registration->getAppId(); |
593
|
|
|
if (!isset($apps[$appId])) { |
594
|
|
|
// If we land here something really isn't right. But at least we caught the |
595
|
|
|
// notice that is otherwise emitted for the undefined index |
596
|
|
|
$this->logger->error("App $appId not loaded for the container service registration"); |
597
|
|
|
|
598
|
|
|
continue; |
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
try { |
602
|
|
|
/** |
603
|
|
|
* Register the service and convert the callable into a \Closure if necessary |
604
|
|
|
*/ |
605
|
|
|
$apps[$appId] |
606
|
|
|
->getContainer() |
607
|
|
|
->registerService( |
608
|
|
|
$registration->getName(), |
609
|
|
|
Closure::fromCallable($registration->getFactory()), |
610
|
|
|
$registration->isShared() |
611
|
|
|
); |
612
|
|
|
} catch (Throwable $e) { |
613
|
|
|
$this->logger->error("Error during service registration of $appId: " . $e->getMessage(), [ |
614
|
|
|
'exception' => $e, |
615
|
|
|
]); |
616
|
|
|
} |
617
|
|
|
} |
618
|
|
|
|
619
|
|
|
while (($registration = array_shift($this->aliases)) !== null) { |
620
|
|
|
$appId = $registration->getAppId(); |
621
|
|
|
if (!isset($apps[$appId])) { |
622
|
|
|
// If we land here something really isn't right. But at least we caught the |
623
|
|
|
// notice that is otherwise emitted for the undefined index |
624
|
|
|
$this->logger->error("App $appId not loaded for the container alias registration"); |
625
|
|
|
|
626
|
|
|
continue; |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
try { |
630
|
|
|
$apps[$appId] |
631
|
|
|
->getContainer() |
632
|
|
|
->registerAlias( |
633
|
|
|
$registration->getAlias(), |
634
|
|
|
$registration->getTarget() |
635
|
|
|
); |
636
|
|
|
} catch (Throwable $e) { |
637
|
|
|
$this->logger->error("Error during service alias registration of $appId: " . $e->getMessage(), [ |
638
|
|
|
'exception' => $e, |
639
|
|
|
]); |
640
|
|
|
} |
641
|
|
|
} |
642
|
|
|
|
643
|
|
|
while (($registration = array_shift($this->parameters)) !== null) { |
644
|
|
|
$appId = $registration->getAppId(); |
645
|
|
|
if (!isset($apps[$appId])) { |
646
|
|
|
// If we land here something really isn't right. But at least we caught the |
647
|
|
|
// notice that is otherwise emitted for the undefined index |
648
|
|
|
$this->logger->error("App $appId not loaded for the container parameter registration"); |
649
|
|
|
|
650
|
|
|
continue; |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
try { |
654
|
|
|
$apps[$appId] |
655
|
|
|
->getContainer() |
656
|
|
|
->registerParameter( |
657
|
|
|
$registration->getName(), |
658
|
|
|
$registration->getValue() |
659
|
|
|
); |
660
|
|
|
} catch (Throwable $e) { |
661
|
|
|
$this->logger->error("Error during service parameter registration of $appId: " . $e->getMessage(), [ |
662
|
|
|
'exception' => $e, |
663
|
|
|
]); |
664
|
|
|
} |
665
|
|
|
} |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
/** |
669
|
|
|
* @return MiddlewareRegistration[] |
670
|
|
|
*/ |
671
|
|
|
public function getMiddlewareRegistrations(): array { |
672
|
|
|
return $this->middlewares; |
673
|
|
|
} |
674
|
|
|
|
675
|
|
|
/** |
676
|
|
|
* @return ServiceRegistration<IProvider>[] |
677
|
|
|
*/ |
678
|
|
|
public function getSearchProviders(): array { |
679
|
|
|
return $this->searchProviders; |
|
|
|
|
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
/** |
683
|
|
|
* @return ServiceRegistration<IAlternativeLogin>[] |
684
|
|
|
*/ |
685
|
|
|
public function getAlternativeLogins(): array { |
686
|
|
|
return $this->alternativeLogins; |
|
|
|
|
687
|
|
|
} |
688
|
|
|
|
689
|
|
|
/** |
690
|
|
|
* @return ServiceRegistration<InitialStateProvider>[] |
691
|
|
|
*/ |
692
|
|
|
public function getInitialStates(): array { |
693
|
|
|
return $this->initialStates; |
|
|
|
|
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
/** |
697
|
|
|
* @return ServiceRegistration<IHandler>[] |
698
|
|
|
*/ |
699
|
|
|
public function getWellKnownHandlers(): array { |
700
|
|
|
return $this->wellKnownHandlers; |
|
|
|
|
701
|
|
|
} |
702
|
|
|
|
703
|
|
|
/** |
704
|
|
|
* @return ServiceRegistration<ISpeechToTextProvider>[] |
705
|
|
|
*/ |
706
|
|
|
public function getSpeechToTextProviders(): array { |
707
|
|
|
return $this->speechToTextProviders; |
|
|
|
|
708
|
|
|
} |
709
|
|
|
|
710
|
|
|
/** |
711
|
|
|
* @return ServiceRegistration<ICustomTemplateProvider>[] |
712
|
|
|
*/ |
713
|
|
|
public function getTemplateProviders(): array { |
714
|
|
|
return $this->templateProviders; |
|
|
|
|
715
|
|
|
} |
716
|
|
|
|
717
|
|
|
/** |
718
|
|
|
* @return ServiceRegistration<ITranslationProvider>[] |
719
|
|
|
*/ |
720
|
|
|
public function getTranslationProviders(): array { |
721
|
|
|
return $this->translationProviders; |
|
|
|
|
722
|
|
|
} |
723
|
|
|
|
724
|
|
|
/** |
725
|
|
|
* @return ServiceRegistration<INotifier>[] |
726
|
|
|
*/ |
727
|
|
|
public function getNotifierServices(): array { |
728
|
|
|
return $this->notifierServices; |
|
|
|
|
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
/** |
732
|
|
|
* @return ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] |
733
|
|
|
*/ |
734
|
|
|
public function getTwoFactorProviders(): array { |
735
|
|
|
return $this->twoFactorProviders; |
|
|
|
|
736
|
|
|
} |
737
|
|
|
|
738
|
|
|
/** |
739
|
|
|
* @return PreviewProviderRegistration[] |
740
|
|
|
*/ |
741
|
|
|
public function getPreviewProviders(): array { |
742
|
|
|
return $this->previewProviders; |
743
|
|
|
} |
744
|
|
|
|
745
|
|
|
/** |
746
|
|
|
* @return ServiceRegistration<ICalendarProvider>[] |
747
|
|
|
*/ |
748
|
|
|
public function getCalendarProviders(): array { |
749
|
|
|
return $this->calendarProviders; |
|
|
|
|
750
|
|
|
} |
751
|
|
|
|
752
|
|
|
/** |
753
|
|
|
* @return ServiceRegistration<IReferenceProvider>[] |
754
|
|
|
*/ |
755
|
|
|
public function getReferenceProviders(): array { |
756
|
|
|
return $this->referenceProviders; |
|
|
|
|
757
|
|
|
} |
758
|
|
|
|
759
|
|
|
/** |
760
|
|
|
* @return ServiceRegistration<ILinkAction>[] |
761
|
|
|
*/ |
762
|
|
|
public function getProfileLinkActions(): array { |
763
|
|
|
return $this->profileLinkActions; |
|
|
|
|
764
|
|
|
} |
765
|
|
|
|
766
|
|
|
/** |
767
|
|
|
* @return ServiceRegistration|null |
768
|
|
|
* @psalm-return ServiceRegistration<ITalkBackend>|null |
769
|
|
|
*/ |
770
|
|
|
public function getTalkBackendRegistration(): ?ServiceRegistration { |
771
|
|
|
return $this->talkBackendRegistration; |
772
|
|
|
} |
773
|
|
|
|
774
|
|
|
/** |
775
|
|
|
* @return ServiceRegistration[] |
776
|
|
|
* @psalm-return ServiceRegistration<IResourceBackend>[] |
777
|
|
|
*/ |
778
|
|
|
public function getCalendarResourceBackendRegistrations(): array { |
779
|
|
|
return $this->calendarResourceBackendRegistrations; |
|
|
|
|
780
|
|
|
} |
781
|
|
|
|
782
|
|
|
/** |
783
|
|
|
* @return ServiceRegistration[] |
784
|
|
|
* @psalm-return ServiceRegistration<IRoomBackend>[] |
785
|
|
|
*/ |
786
|
|
|
public function getCalendarRoomBackendRegistrations(): array { |
787
|
|
|
return $this->calendarRoomBackendRegistrations; |
|
|
|
|
788
|
|
|
} |
789
|
|
|
|
790
|
|
|
/** |
791
|
|
|
* @return ServiceRegistration<IUserMigrator>[] |
792
|
|
|
*/ |
793
|
|
|
public function getUserMigrators(): array { |
794
|
|
|
return $this->userMigrators; |
|
|
|
|
795
|
|
|
} |
796
|
|
|
|
797
|
|
|
/** |
798
|
|
|
* @return ParameterRegistration[] |
799
|
|
|
*/ |
800
|
|
|
public function getSensitiveMethods(): array { |
801
|
|
|
return $this->sensitiveMethods; |
802
|
|
|
} |
803
|
|
|
|
804
|
|
|
/** |
805
|
|
|
* @return ServiceRegistration<IPublicShareTemplateProvider>[] |
806
|
|
|
*/ |
807
|
|
|
public function getPublicShareTemplateProviders(): array { |
808
|
|
|
return $this->publicShareTemplateProviders; |
|
|
|
|
809
|
|
|
} |
810
|
|
|
} |
811
|
|
|
|