Application.php 5.2 KB

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