1
0

RegistrationContext.php 28 KB

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