RegistrationContext.php 27 KB

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