11<?php
2+
3+ declare (strict_types=1 );
4+
25/**
36 * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
47 *
3437use OCA \TwoFactorBackupCodes \Listener \RegistryUpdater ;
3538use OCA \TwoFactorBackupCodes \Notifications \Notifier ;
3639use OCP \AppFramework \App ;
40+ use OCP \AppFramework \Bootstrap \IBootContext ;
41+ use OCP \AppFramework \Bootstrap \IBootstrap ;
42+ use OCP \AppFramework \Bootstrap \IRegistrationContext ;
3743use OCP \Authentication \TwoFactorAuth \IRegistry ;
3844use OCP \EventDispatcher \IEventDispatcher ;
3945use OCP \Notification \IManager ;
4046use 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