RegistrationContext.php 26 KB

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