[encryption] Remove dependency fetching inside the constructor and move them to method call parameters

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2020-11-22 22:09:09 +01:00
parent 9a0428835f
commit efe644137d
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
3 changed files with 14 additions and 20 deletions

View File

@ -27,12 +27,13 @@ namespace OCA\Encryption\AppInfo;
\OCP\Util::addscript('encryption', 'encryption'); \OCP\Util::addscript('encryption', 'encryption');
$encryptionSystemReady = \OC::$server->getEncryptionManager()->isReady(); $encryptionManager = \OC::$server->getEncryptionManager();
$encryptionSystemReady = $encryptionManager->isReady();
/** @var Application $app */ /** @var Application $app */
$app = \OC::$server->query(Application::class); $app = \OC::$server->query(Application::class);
if ($encryptionSystemReady) { if ($encryptionSystemReady) {
$app->registerEncryptionModule(); $app->registerEncryptionModule($encryptionManager);
$app->registerHooks(); $app->registerHooks(\OC::$server->getConfig());
$app->setUp(); $app->setUp($encryptionManager);
} }

View File

@ -44,23 +44,15 @@ use OCP\Encryption\IManager;
use OCP\IConfig; use OCP\IConfig;
class Application extends \OCP\AppFramework\App { class Application extends \OCP\AppFramework\App {
/** @var IManager */
private $encryptionManager;
/** @var IConfig */
private $config;
/** /**
* @param array $urlParams * @param array $urlParams
*/ */
public function __construct($urlParams = []) { public function __construct($urlParams = []) {
parent::__construct('encryption', $urlParams); parent::__construct('encryption', $urlParams);
$this->encryptionManager = \OC::$server->getEncryptionManager();
$this->config = \OC::$server->getConfig();
} }
public function setUp() { public function setUp(IManager $encryptionManager) {
if ($this->encryptionManager->isEnabled()) { if ($encryptionManager->isEnabled()) {
/** @var Setup $setup */ /** @var Setup $setup */
$setup = $this->getContainer()->query(Setup::class); $setup = $this->getContainer()->query(Setup::class);
$setup->setupSystem(); $setup->setupSystem();
@ -70,8 +62,8 @@ class Application extends \OCP\AppFramework\App {
/** /**
* register hooks * register hooks
*/ */
public function registerHooks() { public function registerHooks(IConfig $config) {
if (!$this->config->getSystemValueBool('maintenance')) { if (!$config->getSystemValueBool('maintenance')) {
$container = $this->getContainer(); $container = $this->getContainer();
$server = $container->getServer(); $server = $container->getServer();
// Register our hooks and fire them. // Register our hooks and fire them.
@ -96,11 +88,10 @@ class Application extends \OCP\AppFramework\App {
} }
} }
public function registerEncryptionModule() { public function registerEncryptionModule(IManager $encryptionManager) {
$container = $this->getContainer(); $container = $this->getContainer();
$encryptionManager->registerEncryptionModule(
$this->encryptionManager->registerEncryptionModule(
Encryption::ID, Encryption::ID,
Encryption::DISPLAY_NAME, Encryption::DISPLAY_NAME,
function () use ($container) { function () use ($container) {

View File

@ -14,6 +14,7 @@ use OC\Memcache\ArrayCache;
use OCA\Encryption\AppInfo\Application; use OCA\Encryption\AppInfo\Application;
use OCA\Encryption\KeyManager; use OCA\Encryption\KeyManager;
use OCA\Encryption\Users\Setup; use OCA\Encryption\Users\Setup;
use OCP\Encryption\IManager;
/** /**
* Enables encryption * Enables encryption
@ -64,7 +65,8 @@ trait EncryptionTrait {
/** @var Setup $userSetup */ /** @var Setup $userSetup */
$userSetup = $container->query(Setup::class); $userSetup = $container->query(Setup::class);
$userSetup->setupUser($name, $password); $userSetup->setupUser($name, $password);
$this->encryptionApp->setUp(); $encryptionManager = $container->query(IManager::class);
$this->encryptionApp->setUp($encryptionManager);
$keyManager->init($name, $password); $keyManager->init($name, $password);
} }