From 5be18215fb52f2ee907c73d6f3ee1bad5222c86d Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 11 Nov 2020 22:04:12 +0100 Subject: [PATCH] Auto-wire as much as possible in the encryption app Also cleans up only non-classname services in the server container Signed-off-by: Morris Jobke --- apps/encryption/lib/AppInfo/Application.php | 93 --------------------- lib/private/Server.php | 14 +++- 2 files changed, 10 insertions(+), 97 deletions(-) diff --git a/apps/encryption/lib/AppInfo/Application.php b/apps/encryption/lib/AppInfo/Application.php index a5ba3a567f..44a5a5af35 100644 --- a/apps/encryption/lib/AppInfo/Application.php +++ b/apps/encryption/lib/AppInfo/Application.php @@ -30,9 +30,6 @@ namespace OCA\Encryption\AppInfo; use OC\Files\View; -use OCA\Encryption\Controller\RecoveryController; -use OCA\Encryption\Controller\SettingsController; -use OCA\Encryption\Controller\StatusController; use OCA\Encryption\Crypto\Crypt; use OCA\Encryption\Crypto\DecryptAll; use OCA\Encryption\Crypto\EncryptAll; @@ -128,36 +125,6 @@ class Application extends \OCP\AppFramework\App { public function registerServices() { $container = $this->getContainer(); - $container->registerService(Crypt::class, function (ContainerInterface $c) { - /** @var IServerContainer $server */ - $server = $c->get(IServerContainer::class); - return new Crypt($server->getLogger(), - $server->getUserSession(), - $server->getConfig(), - $server->getL10N($c->get('AppName'))); - }); - - $container->registerService(Session::class, function (ContainerInterface $c) { - /** @var IServerContainer $server */ - $server = $c->get(IServerContainer::class); - return new Session($server->getSession()); - } - ); - - $container->registerService(KeyManager::class, function (ContainerInterface $c) { - /** @var IServerContainer $server */ - $server = $c->get(IServerContainer::class); - - return new KeyManager($server->getEncryptionKeyStorage(), - $c->get(Crypt::class), - $server->getConfig(), - $server->getUserSession(), - new Session($server->getSession()), - $server->getLogger(), - $c->get(Util::class), - $server->getLockingProvider() - ); - }); $container->registerService(Recovery::class, function (ContainerInterface $c) { /** @var IServerContainer $server */ @@ -172,55 +139,6 @@ class Application extends \OCP\AppFramework\App { new View()); }); - $container->registerService(RecoveryController::class, function (ContainerInterface $c) { - /** @var IServerContainer $server */ - $server = $c->get(IServerContainer::class); - return new RecoveryController( - $c->get('AppName'), - $server->getRequest(), - $server->getConfig(), - $server->getL10N($c->get('AppName')), - $c->get(Recovery::class)); - }); - - $container->registerService(StatusController::class, function (ContainerInterface $c) { - /** @var IServerContainer $server */ - $server = $c->get(IServerContainer::class); - return new StatusController( - $c->get('AppName'), - $server->getRequest(), - $server->getL10N($c->get('AppName')), - $c->get(Session::class), - $server->getEncryptionManager() - ); - }); - - $container->registerService(SettingsController::class, function (ContainerInterface $c) { - /** @var IServerContainer $server */ - $server = $c->get(IServerContainer::class); - return new SettingsController( - $c->get('AppName'), - $server->getRequest(), - $server->getL10N($c->get('AppName')), - $server->getUserManager(), - $server->getUserSession(), - $c->get(KeyManager::class), - $c->get(Crypt::class), - $c->get(Session::class), - $server->getSession(), - $c->get(Util::class) - ); - }); - - $container->registerService(Setup::class, function (ContainerInterface $c) { - /** @var IServerContainer $server */ - $server = $c->get(IServerContainer::class); - return new Setup($server->getLogger(), - $server->getUserSession(), - $c->get(Crypt::class), - $c->get(KeyManager::class)); - }); - $container->registerService(Util::class, function (ContainerInterface $c) { /** @var IServerContainer $server */ $server = $c->get(IServerContainer::class); @@ -251,16 +169,5 @@ class Application extends \OCP\AppFramework\App { ); } ); - - $container->registerService(DecryptAll::class,function (ContainerInterface $c) { - return new DecryptAll( - $c->get(Util::class), - $c->get(KeyManager::class), - $c->get(Crypt::class), - $c->get(Session::class), - new QuestionHelper() - ); - } - ); } } diff --git a/lib/private/Server.php b/lib/private/Server.php index 1a2085fa0b..360d682e0d 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -150,6 +150,8 @@ use OCP\Dashboard\IDashboardManager; use OCP\Defaults; use OCP\Diagnostics\IEventLogger; use OCP\Diagnostics\IQueryLogger; +use OCP\Encryption\IFile; +use OCP\Encryption\Keys\IStorage; use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudFederationFactory; use OCP\Federation\ICloudFederationProviderManager; @@ -334,7 +336,9 @@ class Server extends ServerContainer implements IServerContainer { /** @deprecated 19.0.0 */ $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); - $this->registerService('EncryptionFileHelper', function (ContainerInterface $c) { + /** @deprecated 21.0.0 */ + $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); + $this->registerService(IFile::class, function (ContainerInterface $c) { $util = new Encryption\Util( new View(), $c->get(IUserManager::class), @@ -348,7 +352,9 @@ class Server extends ServerContainer implements IServerContainer { ); }); - $this->registerService('EncryptionKeyStorage', function (ContainerInterface $c) { + /** @deprecated 21.0.0 */ + $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); + $this->registerService(IStorage::class, function (ContainerInterface $c) { $view = new View(); $util = new Encryption\Util( $view, @@ -1427,7 +1433,7 @@ class Server extends ServerContainer implements IServerContainer { * @deprecated 20.0.0 */ public function getEncryptionFilesHelper() { - return $this->get('EncryptionFileHelper'); + return $this->get(IFile::class); } /** @@ -1435,7 +1441,7 @@ class Server extends ServerContainer implements IServerContainer { * @deprecated 20.0.0 */ public function getEncryptionKeyStorage() { - return $this->get('EncryptionKeyStorage'); + return $this->get(IStorage::class); } /**