From 7e281a07bb66a082a35cbdd52f7d1e418beb4f53 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 13 Jul 2020 16:23:59 +0200 Subject: Use IBootstrap for the app federatedfilesharing Signed-off-by: Morris Jobke --- apps/federatedfilesharing/appinfo/app.php | 27 ---- .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + .../lib/AppInfo/Application.php | 141 +++------------------ .../Listeners/LoadAdditionalScriptsListener.php | 50 ++++++++ 5 files changed, 67 insertions(+), 153 deletions(-) delete mode 100644 apps/federatedfilesharing/appinfo/app.php create mode 100644 apps/federatedfilesharing/lib/Listeners/LoadAdditionalScriptsListener.php (limited to 'apps/federatedfilesharing') diff --git a/apps/federatedfilesharing/appinfo/app.php b/apps/federatedfilesharing/appinfo/app.php deleted file mode 100644 index e4a94d84088..00000000000 --- a/apps/federatedfilesharing/appinfo/app.php +++ /dev/null @@ -1,27 +0,0 @@ - - * @author John Molakvoæ (skjnldsv) - * @author Robin Appelman - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -use OCA\FederatedFileSharing\AppInfo\Application; - -\OC::$server->query(Application::class); diff --git a/apps/federatedfilesharing/composer/composer/autoload_classmap.php b/apps/federatedfilesharing/composer/composer/autoload_classmap.php index 15573f5434f..08060823692 100644 --- a/apps/federatedfilesharing/composer/composer/autoload_classmap.php +++ b/apps/federatedfilesharing/composer/composer/autoload_classmap.php @@ -12,6 +12,7 @@ return array( 'OCA\\FederatedFileSharing\\Controller\\MountPublicLinkController' => $baseDir . '/../lib/Controller/MountPublicLinkController.php', 'OCA\\FederatedFileSharing\\Controller\\RequestHandlerController' => $baseDir . '/../lib/Controller/RequestHandlerController.php', 'OCA\\FederatedFileSharing\\FederatedShareProvider' => $baseDir . '/../lib/FederatedShareProvider.php', + 'OCA\\FederatedFileSharing\\Listeners\\LoadAdditionalScriptsListener' => $baseDir . '/../lib/Listeners/LoadAdditionalScriptsListener.php', 'OCA\\FederatedFileSharing\\Migration\\Version1010Date20200630191755' => $baseDir . '/../lib/Migration/Version1010Date20200630191755.php', 'OCA\\FederatedFileSharing\\Notifications' => $baseDir . '/../lib/Notifications.php', 'OCA\\FederatedFileSharing\\Notifier' => $baseDir . '/../lib/Notifier.php', diff --git a/apps/federatedfilesharing/composer/composer/autoload_static.php b/apps/federatedfilesharing/composer/composer/autoload_static.php index 24c93eee973..b0e17eb568f 100644 --- a/apps/federatedfilesharing/composer/composer/autoload_static.php +++ b/apps/federatedfilesharing/composer/composer/autoload_static.php @@ -27,6 +27,7 @@ class ComposerStaticInitFederatedFileSharing 'OCA\\FederatedFileSharing\\Controller\\MountPublicLinkController' => __DIR__ . '/..' . '/../lib/Controller/MountPublicLinkController.php', 'OCA\\FederatedFileSharing\\Controller\\RequestHandlerController' => __DIR__ . '/..' . '/../lib/Controller/RequestHandlerController.php', 'OCA\\FederatedFileSharing\\FederatedShareProvider' => __DIR__ . '/..' . '/../lib/FederatedShareProvider.php', + 'OCA\\FederatedFileSharing\\Listeners\\LoadAdditionalScriptsListener' => __DIR__ . '/..' . '/../lib/Listeners/LoadAdditionalScriptsListener.php', 'OCA\\FederatedFileSharing\\Migration\\Version1010Date20200630191755' => __DIR__ . '/..' . '/../lib/Migration/Version1010Date20200630191755.php', 'OCA\\FederatedFileSharing\\Notifications' => __DIR__ . '/..' . '/../lib/Notifications.php', 'OCA\\FederatedFileSharing\\Notifier' => __DIR__ . '/..' . '/../lib/Notifier.php', diff --git a/apps/federatedfilesharing/lib/AppInfo/Application.php b/apps/federatedfilesharing/lib/AppInfo/Application.php index f38f583d85a..09f881d5bb8 100644 --- a/apps/federatedfilesharing/lib/AppInfo/Application.php +++ b/apps/federatedfilesharing/lib/AppInfo/Application.php @@ -2,7 +2,6 @@ /** * @copyright Copyright (c) 2016, ownCloud, Inc. * - * @author Bjoern Schiessle * @author Björn Schießle * @author Christoph Wurst * @author John Molakvoæ (skjnldsv) @@ -29,145 +28,35 @@ namespace OCA\FederatedFileSharing\AppInfo; -use OC\AppFramework\Utility\SimpleContainer; -use OCA\FederatedFileSharing\AddressHandler; -use OCA\FederatedFileSharing\Controller\RequestHandlerController; -use OCA\FederatedFileSharing\FederatedShareProvider; -use OCA\FederatedFileSharing\Notifications; +use OCA\FederatedFileSharing\Listeners\LoadAdditionalScriptsListener; use OCA\FederatedFileSharing\Notifier; use OCA\FederatedFileSharing\OCM\CloudFederationProviderFiles; +use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCP\AppFramework\App; -use OCP\GlobalScale\IConfig; - -class Application extends App { - - /** @var FederatedShareProvider */ - protected $federatedShareProvider; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; +class Application extends App implements IBootstrap { public function __construct() { parent::__construct('federatedfilesharing'); + } - $container = $this->getContainer(); - $server = $container->getServer(); + public function register(IRegistrationContext $context): void { + $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScriptsListener::class); + } + + public function boot(IBootContext $context): void { + $server = $context->getServerContainer(); $cloudFederationManager = $server->getCloudFederationProviderManager(); $cloudFederationManager->addCloudFederationProvider('file', 'Federated Files Sharing', - function () use ($container) { - $server = $container->getServer(); - return new CloudFederationProviderFiles( - $server->getAppManager(), - $server->query(FederatedShareProvider::class), - $server->query(AddressHandler::class), - $server->getLogger(), - $server->getUserManager(), - $server->getShareManager(), - $server->getCloudIdManager(), - $server->getActivityManager(), - $server->getNotificationManager(), - $server->getURLGenerator(), - $server->getCloudFederationFactory(), - $server->getCloudFederationProviderManager(), - $server->getDatabaseConnection(), - $server->getGroupManager() - ); + function () use ($server) { + return $server->query(CloudFederationProviderFiles::class); }); - $container->registerService('RequestHandlerController', function (SimpleContainer $c) use ($server) { - $addressHandler = new AddressHandler( - $server->getURLGenerator(), - $server->getL10N('federatedfilesharing'), - $server->getCloudIdManager() - ); - $notification = new Notifications( - $addressHandler, - $server->getHTTPClientService(), - $server->query(\OCP\OCS\IDiscoveryService::class), - \OC::$server->getJobList(), - \OC::$server->getCloudFederationProviderManager(), - \OC::$server->getCloudFederationFactory() - ); - return new RequestHandlerController( - $c->query('AppName'), - $server->getRequest(), - $this->getFederatedShareProvider(), - $server->getDatabaseConnection(), - $server->getShareManager(), - $notification, - $addressHandler, - $server->getUserManager(), - $server->getCloudIdManager(), - $server->getLogger(), - $server->getCloudFederationFactory(), - $server->getCloudFederationProviderManager() - ); - }); - - // register events listeners - $eventDispatcher = $server->getEventDispatcher(); $manager = $server->getNotificationManager(); - $federatedShareProvider = $this->getFederatedShareProvider(); - $manager->registerNotifierService(Notifier::class); - - $eventDispatcher->addListener( - 'OCA\Files::loadAdditionalScripts', - function () use ($federatedShareProvider) { - if ($federatedShareProvider->isIncomingServer2serverShareEnabled()) { - \OCP\Util::addScript('federatedfilesharing', 'external'); - } - } - ); - } - - /** - * get instance of federated share provider - * - * @return FederatedShareProvider - */ - public function getFederatedShareProvider() { - if ($this->federatedShareProvider === null) { - $this->initFederatedShareProvider(); - } - return $this->federatedShareProvider; - } - - /** - * initialize federated share provider - */ - protected function initFederatedShareProvider() { - $c = $this->getContainer(); - $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( - \OC::$server->getURLGenerator(), - \OC::$server->getL10N('federatedfilesharing'), - \OC::$server->getCloudIdManager() - ); - $notifications = new \OCA\FederatedFileSharing\Notifications( - $addressHandler, - \OC::$server->getHTTPClientService(), - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), - \OC::$server->getJobList(), - \OC::$server->getCloudFederationProviderManager(), - \OC::$server->getCloudFederationFactory() - ); - $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( - \OC::$server->getSecureRandom() - ); - - $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider( - \OC::$server->getDatabaseConnection(), - $addressHandler, - $notifications, - $tokenHandler, - \OC::$server->getL10N('federatedfilesharing'), - \OC::$server->getLogger(), - \OC::$server->getLazyRootFolder(), - \OC::$server->getConfig(), - \OC::$server->getUserManager(), - \OC::$server->getCloudIdManager(), - $c->query(IConfig::class), - \OC::$server->getCloudFederationProviderManager() - - ); } } diff --git a/apps/federatedfilesharing/lib/Listeners/LoadAdditionalScriptsListener.php b/apps/federatedfilesharing/lib/Listeners/LoadAdditionalScriptsListener.php new file mode 100644 index 00000000000..3901a1c93ea --- /dev/null +++ b/apps/federatedfilesharing/lib/Listeners/LoadAdditionalScriptsListener.php @@ -0,0 +1,50 @@ + + * + * @author Morris Jobke + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\FederatedFileSharing\Listeners; + +use OCA\FederatedFileSharing\FederatedShareProvider; +use OCA\Files\Event\LoadAdditionalScriptsEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; + +class LoadAdditionalScriptsListener implements IEventListener { + /** @var FederatedShareProvider */ + protected $federatedShareProvider; + + public function __construct(FederatedShareProvider $federatedShareProvider) { + $this->federatedShareProvider = $federatedShareProvider; + } + + public function handle(Event $event): void { + if (!$event instanceof LoadAdditionalScriptsEvent) { + return; + } + + if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled()) { + \OCP\Util::addScript('federatedfilesharing', 'external'); + } + } +} -- cgit v1.2.3