diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-07-13 16:23:59 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2020-07-14 16:34:43 +0200 |
commit | 7e281a07bb66a082a35cbdd52f7d1e418beb4f53 (patch) | |
tree | 9a2ab162c879eec9ede9087d2869a490c3988a49 /apps/federatedfilesharing | |
parent | 2c87ce60a04eb98533d430ef7abe386ef0d04c2a (diff) | |
download | nextcloud-server-7e281a07bb66a082a35cbdd52f7d1e418beb4f53.tar.gz nextcloud-server-7e281a07bb66a082a35cbdd52f7d1e418beb4f53.zip |
Use IBootstrap for the app federatedfilesharing
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'apps/federatedfilesharing')
5 files changed, 67 insertions, 153 deletions
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 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Björn Schießle <bjoern@schiessle.org> - * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> - * @author Robin Appelman <robin@icewind.nl> - * - * @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 <http://www.gnu.org/licenses/> - * - */ - -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 <bjoern@schiessle.org> * @author Björn Schießle <bjoern@schiessle.org> * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> @@ -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 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de> + * + * @author Morris Jobke <hey@morrisjobke.de> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +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'); + } + } +} |