injectFn(function (IManager $encryptionManager) use ($context): void { if (!($encryptionManager instanceof \OC\Encryption\Manager)) { return; } if (!$encryptionManager->isReady()) { return; } $context->injectFn($this->registerEncryptionModule(...)); $context->injectFn($this->registerEventListeners(...)); $context->injectFn($this->setUp(...)); }); } public function setUp(IManager $encryptionManager) { if ($encryptionManager->isEnabled()) { /** @var Setup $setup */ $setup = $this->getContainer()->get(Setup::class); $setup->setupSystem(); } } public function registerEventListeners(IConfig $config, IEventDispatcher $eventDispatcher, IManager $encryptionManager): void { if (!$encryptionManager->isEnabled()) { return; } if ($config->getSystemValueBool('maintenance')) { // Logout user if we are in maintenance to force re-login $this->getContainer()->get(IUserSession::class)->logout(); return; } // No maintenance so register all events $eventDispatcher->addServiceListener(UserCreatedEvent::class, UserEventsListener::class); $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserEventsListener::class); $eventDispatcher->addServiceListener(BeforePasswordUpdatedEvent::class, UserEventsListener::class); $eventDispatcher->addServiceListener(PasswordUpdatedEvent::class, UserEventsListener::class); $eventDispatcher->addServiceListener(BeforePasswordResetEvent::class, UserEventsListener::class); $eventDispatcher->addServiceListener(PasswordResetEvent::class, UserEventsListener::class); } public function registerEncryptionModule(IManager $encryptionManager) { $container = $this->getContainer(); $encryptionManager->registerEncryptionModule( Encryption::ID, Encryption::DISPLAY_NAME, function () use ($container) { return new Encryption( $container->get(Crypt::class), $container->get(KeyManager::class), $container->get(Util::class), $container->get(Session::class), $container->get(EncryptAll::class), $container->get(DecryptAll::class), $container->get(LoggerInterface::class), $container->get(IL10N::class), ); }); } }