Skip to content

Commit ee55e01

Browse files
Migrate Two-Factor Backup Codes to new bootstrap mechanism
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent 94e1760 commit ee55e01

File tree

2 files changed

+28
-53
lines changed

2 files changed

+28
-53
lines changed

apps/twofactor_backupcodes/appinfo/app.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

apps/twofactor_backupcodes/lib/AppInfo/Application.php

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/**
36
* @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
47
*
@@ -34,45 +37,45 @@
3437
use OCA\TwoFactorBackupCodes\Listener\RegistryUpdater;
3538
use OCA\TwoFactorBackupCodes\Notifications\Notifier;
3639
use OCP\AppFramework\App;
40+
use OCP\AppFramework\Bootstrap\IBootContext;
41+
use OCP\AppFramework\Bootstrap\IBootstrap;
42+
use OCP\AppFramework\Bootstrap\IRegistrationContext;
3743
use OCP\Authentication\TwoFactorAuth\IRegistry;
3844
use OCP\EventDispatcher\IEventDispatcher;
3945
use OCP\Notification\IManager;
4046
use OCP\Util;
4147

42-
class Application extends App {
48+
class Application extends App implements IBootstrap {
49+
public const APP_ID = 'twofactor_backupcodes';
50+
4351
public function __construct() {
44-
parent::__construct('twofactor_backupcodes');
52+
parent::__construct(self::APP_ID);
4553
}
4654

47-
/**
48-
* Register the different app parts
49-
*/
50-
public function register() {
51-
$this->registerHooksAndEvents();
52-
$this->registerNotification();
55+
public function register(IRegistrationContext $context): void {
56+
$this->registerHooksAndEvents($context);
5357
}
5458

55-
/**
56-
* Register the hooks and events
57-
*/
58-
public function registerHooksAndEvents() {
59+
public function boot(IBootContext $context): void {
5960
Util::connectHook('OC_User', 'post_deleteUser', $this, 'deleteUser');
6061

61-
$container = $this->getContainer();
62+
$this->registerNotification(
63+
$context->getAppContainer()->query(IManager::class)
64+
);
65+
}
6266

63-
/** @var IEventDispatcher $eventDispatcher */
64-
$eventDispatcher = $container->query(IEventDispatcher::class);
65-
$eventDispatcher->addServiceListener(CodesGenerated::class, ActivityPublisher::class);
66-
$eventDispatcher->addServiceListener(CodesGenerated::class, RegistryUpdater::class);
67-
$eventDispatcher->addServiceListener(CodesGenerated::class, ClearNotifications::class);
68-
$eventDispatcher->addServiceListener(IRegistry::EVENT_PROVIDER_ENABLED, ProviderEnabled::class);
69-
$eventDispatcher->addServiceListener(IRegistry::EVENT_PROVIDER_DISABLED, ProviderDisabled::class);
67+
/**
68+
* Register the hooks and events
69+
*/
70+
public function registerHooksAndEvents(IRegistrationContext $context) {
71+
$context->registerEventListener(CodesGenerated::class, ActivityPublisher::class);
72+
$context->registerEventListener(CodesGenerated::class, RegistryUpdater::class);
73+
$context->registerEventListener(CodesGenerated::class, ClearNotifications::class);
74+
$context->registerEventListener(IRegistry::EVENT_PROVIDER_ENABLED, ProviderEnabled::class);
75+
$context->registerEventListener(IRegistry::EVENT_PROVIDER_DISABLED, ProviderDisabled::class);
7076
}
7177

72-
public function registerNotification() {
73-
$container = $this->getContainer();
74-
/** @var IManager $manager */
75-
$manager = $container->query(IManager::class);
78+
private function registerNotification(IManager $manager) {
7679
$manager->registerNotifierService(Notifier::class);
7780
}
7881

@@ -81,4 +84,5 @@ public function deleteUser($params) {
8184
$mapper = $this->getContainer()->query(BackupCodeMapper::class);
8285
$mapper->deleteCodesByUserId($params['uid']);
8386
}
87+
8488
}

0 commit comments

Comments
 (0)