Application.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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\LoadSearchPluginsListener;
  18. use OCA\Files\Listener\LoadSidebarListener;
  19. use OCA\Files\Listener\NodeAddedToFavoriteListener;
  20. use OCA\Files\Listener\NodeRemovedFromFavoriteListener;
  21. use OCA\Files\Listener\RenderReferenceEventListener;
  22. use OCA\Files\Listener\SyncLivePhotosListener;
  23. use OCA\Files\Notification\Notifier;
  24. use OCA\Files\Search\FilesSearchProvider;
  25. use OCA\Files\Service\TagService;
  26. use OCA\Files\Service\UserConfig;
  27. use OCA\Files\Service\ViewConfig;
  28. use OCA\Files\Settings\DeclarativeAdminSettings;
  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\Files\Cache\CacheEntryRemovedEvent;
  37. use OCP\Files\Events\Node\BeforeNodeCopiedEvent;
  38. use OCP\Files\Events\Node\BeforeNodeDeletedEvent;
  39. use OCP\Files\Events\Node\BeforeNodeRenamedEvent;
  40. use OCP\Files\Events\Node\NodeCopiedEvent;
  41. use OCP\Files\Events\NodeAddedToFavorite;
  42. use OCP\Files\Events\NodeRemovedFromFavorite;
  43. use OCP\Files\IRootFolder;
  44. use OCP\IConfig;
  45. use OCP\IL10N;
  46. use OCP\IPreview;
  47. use OCP\IRequest;
  48. use OCP\IServerContainer;
  49. use OCP\ITagManager;
  50. use OCP\IUserSession;
  51. use OCP\Share\IManager as IShareManager;
  52. use OCP\Util;
  53. use Psr\Container\ContainerInterface;
  54. use Psr\Log\LoggerInterface;
  55. class Application extends App implements IBootstrap {
  56. public const APP_ID = 'files';
  57. public function __construct(array $urlParams = []) {
  58. parent::__construct(self::APP_ID, $urlParams);
  59. }
  60. public function register(IRegistrationContext $context): void {
  61. /**
  62. * Controllers
  63. */
  64. $context->registerService('APIController', function (ContainerInterface $c) {
  65. /** @var IServerContainer $server */
  66. $server = $c->get(IServerContainer::class);
  67. return new ApiController(
  68. $c->get('AppName'),
  69. $c->get(IRequest::class),
  70. $c->get(IUserSession::class),
  71. $c->get(TagService::class),
  72. $c->get(IPreview::class),
  73. $c->get(IShareManager::class),
  74. $c->get(IConfig::class),
  75. $server->getUserFolder(),
  76. $c->get(UserConfig::class),
  77. $c->get(ViewConfig::class),
  78. $c->get(IL10N::class),
  79. $c->get(IRootFolder::class),
  80. $c->get(LoggerInterface::class),
  81. );
  82. });
  83. /**
  84. * Services
  85. */
  86. $context->registerService(TagService::class, function (ContainerInterface $c) {
  87. /** @var IServerContainer $server */
  88. $server = $c->get(IServerContainer::class);
  89. return new TagService(
  90. $c->get(IUserSession::class),
  91. $c->get(IActivityManager::class),
  92. $c->get(ITagManager::class)->load(self::APP_ID),
  93. $server->getUserFolder(),
  94. );
  95. });
  96. /*
  97. * Register capabilities
  98. */
  99. $context->registerCapability(Capabilities::class);
  100. $context->registerCapability(DirectEditingCapabilities::class);
  101. $context->registerDeclarativeSettings(DeclarativeAdminSettings::class);
  102. $context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class);
  103. $context->registerEventListener(RenderReferenceEvent::class, RenderReferenceEventListener::class);
  104. $context->registerEventListener(BeforeNodeRenamedEvent::class, SyncLivePhotosListener::class);
  105. $context->registerEventListener(BeforeNodeDeletedEvent::class, SyncLivePhotosListener::class);
  106. $context->registerEventListener(CacheEntryRemovedEvent::class, SyncLivePhotosListener::class);
  107. $context->registerEventListener(BeforeNodeCopiedEvent::class, SyncLivePhotosListener::class);
  108. $context->registerEventListener(NodeCopiedEvent::class, SyncLivePhotosListener::class);
  109. $context->registerEventListener(LoadSearchPlugins::class, LoadSearchPluginsListener::class);
  110. $context->registerEventListener(NodeAddedToFavorite::class, NodeAddedToFavoriteListener::class);
  111. $context->registerEventListener(NodeRemovedFromFavorite::class, NodeRemovedFromFavoriteListener::class);
  112. $context->registerSearchProvider(FilesSearchProvider::class);
  113. $context->registerNotifierService(Notifier::class);
  114. }
  115. public function boot(IBootContext $context): void {
  116. $context->injectFn(Closure::fromCallable([$this, 'registerCollaboration']));
  117. $context->injectFn([Listener::class, 'register']);
  118. $this->registerTemplates();
  119. $this->registerHooks();
  120. }
  121. private function registerCollaboration(IProviderManager $providerManager): void {
  122. $providerManager->registerResourceProvider(ResourceProvider::class);
  123. }
  124. private function registerTemplates(): void {
  125. $templateManager = \OC_Helper::getFileTemplateManager();
  126. $templateManager->registerTemplate('application/vnd.oasis.opendocument.presentation', 'core/templates/filetemplates/template.odp');
  127. $templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'core/templates/filetemplates/template.odt');
  128. $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');
  129. }
  130. private function registerHooks(): void {
  131. Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig');
  132. }
  133. }