RegistrationContext.php 26 KB

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