diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index 078a0a5f59dee..6e12c709ae4d5 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -1,4 +1,7 @@ getContainer(); + public function __construct() { + parent::__construct(self::APP_ID); + } - /** @var IServerContainer $server */ - $server = $container->getServer(); + public function register(IRegistrationContext $context): void { + $context->registerCapability(Capabilities::class); - /** @var IEventDispatcher $dispatcher */ - $dispatcher = $container->query(IEventDispatcher::class); - $oldDispatcher = $container->getServer()->getEventDispatcher(); - $mountProviderCollection = $server->getMountProviderCollection(); - $notifications = $server->getNotificationManager(); + $context->registerMiddleWare(SharingCheckMiddleware::class); + $context->registerMiddleWare(OCSShareAPIMiddleware::class); + $context->registerMiddleWare(ShareInfoMiddleware::class); - /** - * Core class wrappers - */ - $container->registerService(Manager::class, function (SimpleContainer $c) use ($server) { + // sidebar and files scripts + $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); + $context->registerEventListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class); + $context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class); + $context->registerEventListener(ShareCreatedEvent::class, ShareInteractionListener::class); + $context->registerEventListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class); + $context->registerEventListener(UserAddedEvent::class, UserAddedToGroupListener::class); + + $context->registerService('ExternalMountProvider', function (ContainerInterface $c) { + return new \OCA\Files_Sharing\External\MountProvider( + $c->get(IDBConnection::class), + function () use ($c) { + return $c->get(Manager::class); + }, + $c->get(ICloudIdManager::class) + ); + }); + $context->registerService(Manager::class, function (IAppContainer $c) { + /** @var IServerContainer $server */ + $server = $c->get(IServerContainer::class); $user = $server->getUserSession()->getUser(); $uid = $user ? $user->getUID() : null; - return new \OCA\Files_Sharing\External\Manager( + return new Manager( $server->getDatabaseConnection(), - \OC\Files\Filesystem::getMountManager(), - \OC\Files\Filesystem::getLoader(), + Filesystem::getMountManager(), + Filesystem::getLoader(), $server->getHTTPClientService(), $server->getNotificationManager(), - $server->query(\OCP\OCS\IDiscoveryService::class), + $server->query(IDiscoveryService::class), $server->getCloudFederationProviderManager(), $server->getCloudFederationFactory(), $server->getGroupManager(), @@ -100,34 +124,19 @@ public function __construct(array $urlParams = []) { $server->query(IEventDispatcher::class) ); }); + } - /** - * Middleware - */ - $container->registerMiddleWare(SharingCheckMiddleware::class); - $container->registerMiddleWare(OCSShareAPIMiddleware::class); - $container->registerMiddleWare(ShareInfoMiddleware::class); - - $container->registerService('ExternalMountProvider', function (ContainerInterface $c) { - return new \OCA\Files_Sharing\External\MountProvider( - $c->get(IDBConnection::class), - function () use ($c) { - return $c->get(Manager::class); - }, - $c->get(ICloudIdManager::class) - ); - }); - - /** - * Register capabilities - */ - $container->registerCapability(Capabilities::class); + public function boot(IBootContext $context): void { + $context->injectFn(Closure::fromCallable([$this, 'registerEventsScripts'])); + $context->injectFn(Closure::fromCallable([$this, 'setupSharingMenus'])); + /** @var IManager $notifications */ + $notifications = $context->getServerContainer()->get(IManager::class); $notifications->registerNotifierService(Notifier::class); + /** @var IMountProviderCollection $mountProviderCollection */ + $mountProviderCollection = $context->getServerContainer()->get(IMountProviderCollection::class); $this->registerMountProviders($mountProviderCollection); - $this->registerEventsScripts($dispatcher, $oldDispatcher); - $this->setupSharingMenus(); /** * Always add main sharing script @@ -140,18 +149,10 @@ protected function registerMountProviders(IMountProviderCollection $mountProvide $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider')); } - protected function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher) { - // sidebar and files scripts - $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); - $dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class); - $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class); - $dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class); - $dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () { - \OCP\Util::addScript('files_sharing', 'dist/collaboration'); + private function registerEventsScripts(EventDispatcherInterface $oldDispatcher) { + $oldDispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () { + Util::addScript('files_sharing', 'dist/collaboration'); }); - $dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class); - $dispatcher->addServiceListener(UserAddedEvent::class, UserAddedToGroupListener::class); - // notifications api to accept incoming user shares $oldDispatcher->addListener('OCP\Share::postShare', function (GenericEvent $event) { /** @var Listener $listener */ @@ -165,9 +166,7 @@ protected function registerEventsScripts(IEventDispatcher $dispatcher, EventDisp }); } - protected function setupSharingMenus() { - $config = \OC::$server->getConfig(); - + protected function setupSharingMenus(IConfig $config) { if ($config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes' || !class_exists('\OCA\Files\App')) { return; } @@ -179,7 +178,7 @@ protected function setupSharingMenus() { $sharingSublistArray = []; - if (\OCP\Util::isSharingDisabledForUser() === false) { + if (Util::isSharingDisabledForUser() === false) { $sharingSublistArray[] = [ 'id' => 'sharingout', 'appname' => 'files_sharing', @@ -197,7 +196,7 @@ protected function setupSharingMenus() { 'name' => $l->t('Shared with you'), ]; - if (\OCP\Util::isSharingDisabledForUser() === false) { + if (Util::isSharingDisabledForUser() === false) { // Check if sharing by link is enabled if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { $sharingSublistArray[] = [