Application.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Comments\AppInfo;
  7. use Closure;
  8. use OCA\Comments\Capabilities;
  9. use OCA\Comments\EventHandler;
  10. use OCA\Comments\Listener\CommentsEntityEventListener;
  11. use OCA\Comments\Listener\LoadAdditionalScripts;
  12. use OCA\Comments\Listener\LoadSidebarScripts;
  13. use OCA\Comments\MaxAutoCompleteResultsInitialState;
  14. use OCA\Comments\Notification\Notifier;
  15. use OCA\Comments\Search\CommentsSearchProvider;
  16. use OCA\Comments\Search\LegacyProvider;
  17. use OCA\Files\Event\LoadAdditionalScriptsEvent;
  18. use OCA\Files\Event\LoadSidebar;
  19. use OCP\AppFramework\App;
  20. use OCP\AppFramework\Bootstrap\IBootContext;
  21. use OCP\AppFramework\Bootstrap\IBootstrap;
  22. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  23. use OCP\Comments\CommentsEntityEvent;
  24. use OCP\Comments\ICommentsManager;
  25. use OCP\ISearch;
  26. use OCP\IServerContainer;
  27. class Application extends App implements IBootstrap {
  28. public const APP_ID = 'comments';
  29. public function __construct(array $urlParams = []) {
  30. parent::__construct(self::APP_ID, $urlParams);
  31. }
  32. public function register(IRegistrationContext $context): void {
  33. $context->registerCapability(Capabilities::class);
  34. $context->registerEventListener(
  35. LoadAdditionalScriptsEvent::class,
  36. LoadAdditionalScripts::class
  37. );
  38. $context->registerEventListener(
  39. LoadSidebar::class,
  40. LoadSidebarScripts::class
  41. );
  42. $context->registerEventListener(
  43. CommentsEntityEvent::class,
  44. CommentsEntityEventListener::class
  45. );
  46. $context->registerSearchProvider(CommentsSearchProvider::class);
  47. $context->registerInitialStateProvider(MaxAutoCompleteResultsInitialState::class);
  48. $context->registerNotifierService(Notifier::class);
  49. }
  50. public function boot(IBootContext $context): void {
  51. $context->injectFn(Closure::fromCallable([$this, 'registerCommentsEventHandler']));
  52. $context->getServerContainer()->get(ISearch::class)->registerProvider(LegacyProvider::class, ['apps' => ['files']]);
  53. }
  54. protected function registerCommentsEventHandler(IServerContainer $container): void {
  55. $container->get(ICommentsManager::class)->registerEventHandler(function (): EventHandler {
  56. return $this->getContainer()->get(EventHandler::class);
  57. });
  58. }
  59. }