Application.php 5.2 KB

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