1
0

Application.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  6. * SPDX-License-Identifier: AGPL-3.0-only
  7. */
  8. namespace OCA\Files\AppInfo;
  9. use Closure;
  10. use OCA\Files\Capabilities;
  11. use OCA\Files\Collaboration\Resources\Listener;
  12. use OCA\Files\Collaboration\Resources\ResourceProvider;
  13. use OCA\Files\Controller\ApiController;
  14. use OCA\Files\DirectEditingCapabilities;
  15. use OCA\Files\Event\LoadSearchPlugins;
  16. use OCA\Files\Event\LoadSidebar;
  17. use OCA\Files\Listener\DeclarativeSettingsGetValueEventListener;
  18. use OCA\Files\Listener\DeclarativeSettingsRegisterFormEventListener;
  19. use OCA\Files\Listener\DeclarativeSettingsSetValueEventListener;
  20. use OCA\Files\Listener\LoadSearchPluginsListener;
  21. use OCA\Files\Listener\LoadSidebarListener;
  22. use OCA\Files\Listener\RenderReferenceEventListener;
  23. use OCA\Files\Listener\SyncLivePhotosListener;
  24. use OCA\Files\Notification\Notifier;
  25. use OCA\Files\Search\FilesSearchProvider;
  26. use OCA\Files\Service\TagService;
  27. use OCA\Files\Service\UserConfig;
  28. use OCA\Files\Service\ViewConfig;
  29. use OCP\Activity\IManager as IActivityManager;
  30. use OCP\AppFramework\App;
  31. use OCP\AppFramework\Bootstrap\IBootContext;
  32. use OCP\AppFramework\Bootstrap\IBootstrap;
  33. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  34. use OCP\Collaboration\Reference\RenderReferenceEvent;
  35. use OCP\Collaboration\Resources\IProviderManager;
  36. use OCP\EventDispatcher\IEventDispatcher;
  37. use OCP\Files\Cache\CacheEntryRemovedEvent;
  38. use OCP\Files\Events\Node\BeforeNodeCopiedEvent;
  39. use OCP\Files\Events\Node\BeforeNodeDeletedEvent;
  40. use OCP\Files\Events\Node\BeforeNodeRenamedEvent;
  41. use OCP\Files\Events\Node\NodeCopiedEvent;
  42. use OCP\Files\IRootFolder;
  43. use OCP\IConfig;
  44. use OCP\IL10N;
  45. use OCP\IPreview;
  46. use OCP\IRequest;
  47. use OCP\IServerContainer;
  48. use OCP\ITagManager;
  49. use OCP\IUserSession;
  50. use OCP\Settings\Events\DeclarativeSettingsGetValueEvent;
  51. use OCP\Settings\Events\DeclarativeSettingsRegisterFormEvent;
  52. use OCP\Settings\Events\DeclarativeSettingsSetValueEvent;
  53. use OCP\Share\IManager as IShareManager;
  54. use OCP\Util;
  55. use Psr\Container\ContainerInterface;
  56. use Psr\Log\LoggerInterface;
  57. class Application extends App implements IBootstrap {
  58. public const APP_ID = 'files';
  59. public function __construct(array $urlParams = []) {
  60. parent::__construct(self::APP_ID, $urlParams);
  61. }
  62. public function register(IRegistrationContext $context): void {
  63. /**
  64. * Controllers
  65. */
  66. $context->registerService('APIController', function (ContainerInterface $c) {
  67. /** @var IServerContainer $server */
  68. $server = $c->get(IServerContainer::class);
  69. return new ApiController(
  70. $c->get('AppName'),
  71. $c->get(IRequest::class),
  72. $c->get(IUserSession::class),
  73. $c->get(TagService::class),
  74. $c->get(IPreview::class),
  75. $c->get(IShareManager::class),
  76. $c->get(IConfig::class),
  77. $server->getUserFolder(),
  78. $c->get(UserConfig::class),
  79. $c->get(ViewConfig::class),
  80. $c->get(IL10N::class),
  81. $c->get(IRootFolder::class),
  82. $c->get(LoggerInterface::class),
  83. );
  84. });
  85. /**
  86. * Services
  87. */
  88. $context->registerService(TagService::class, function (ContainerInterface $c) {
  89. /** @var IServerContainer $server */
  90. $server = $c->get(IServerContainer::class);
  91. return new TagService(
  92. $c->get(IUserSession::class),
  93. $c->get(IActivityManager::class),
  94. $c->get(ITagManager::class)->load(self::APP_ID),
  95. $server->getUserFolder(),
  96. $c->get(IEventDispatcher::class),
  97. );
  98. });
  99. /*
  100. * Register capabilities
  101. */
  102. $context->registerCapability(Capabilities::class);
  103. $context->registerCapability(DirectEditingCapabilities::class);
  104. $context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class);
  105. $context->registerEventListener(RenderReferenceEvent::class, RenderReferenceEventListener::class);
  106. $context->registerEventListener(BeforeNodeRenamedEvent::class, SyncLivePhotosListener::class);
  107. $context->registerEventListener(BeforeNodeDeletedEvent::class, SyncLivePhotosListener::class);
  108. $context->registerEventListener(CacheEntryRemovedEvent::class, SyncLivePhotosListener::class);
  109. $context->registerEventListener(BeforeNodeCopiedEvent::class, SyncLivePhotosListener::class);
  110. $context->registerEventListener(NodeCopiedEvent::class, SyncLivePhotosListener::class);
  111. $context->registerEventListener(LoadSearchPlugins::class, LoadSearchPluginsListener::class);
  112. $context->registerEventListener(DeclarativeSettingsRegisterFormEvent::class, DeclarativeSettingsRegisterFormEventListener::class);
  113. $context->registerEventListener(DeclarativeSettingsGetValueEvent::class, DeclarativeSettingsGetValueEventListener::class);
  114. $context->registerEventListener(DeclarativeSettingsSetValueEvent::class, DeclarativeSettingsSetValueEventListener::class);
  115. $context->registerSearchProvider(FilesSearchProvider::class);
  116. $context->registerNotifierService(Notifier::class);
  117. }
  118. public function boot(IBootContext $context): void {
  119. $context->injectFn(Closure::fromCallable([$this, 'registerCollaboration']));
  120. $context->injectFn([Listener::class, 'register']);
  121. $this->registerTemplates();
  122. $this->registerHooks();
  123. }
  124. private function registerCollaboration(IProviderManager $providerManager): void {
  125. $providerManager->registerResourceProvider(ResourceProvider::class);
  126. }
  127. private function registerTemplates(): void {
  128. $templateManager = \OC_Helper::getFileTemplateManager();
  129. $templateManager->registerTemplate('application/vnd.oasis.opendocument.presentation', 'core/templates/filetemplates/template.odp');
  130. $templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'core/templates/filetemplates/template.odt');
  131. $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');
  132. }
  133. private function registerHooks(): void {
  134. Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig');
  135. }
  136. }