diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 163a226cc..014c4c6bd 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -83,15 +83,8 @@ protected function registerScripts() { } protected function registerNotificationNotifier() { - $this->getContainer()->getServer()->getNotificationManager()->registerNotifier(function() { - return $this->getContainer()->query(Notifier::class); - }, function() { - $l = $this->getContainer()->query(IL10N::class); - return [ - 'id' => 'firstrunwizard', - 'name' => $l->t('First run wizard'), - ]; - }); + $this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class); + /** @var AppHint $appHint */ $appHint = $this->getContainer()->query(AppHint::class); $appHint->registerAppListener(); diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index af0f32e78..c72e81950 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -56,6 +56,26 @@ public function __construct(IFactory $factory, IUserManager $userManager, INotif $this->url = $urlGenerator; } + /** + * Identifier of the notifier, only use [a-z0-9_] + * + * @return string + * @since 17.0.0 + */ + public function getID(): string { + return 'firstrunwizard'; + } + + /** + * Human readable name describing the notifier + * + * @return string + * @since 17.0.0 + */ + public function getName(): string { + return $this->factory->get('firstrunwizard')->t('First run wizard'); + } + /** * @param INotification $notification * @param string $languageCode The code of the language that should be used to prepare the notification @@ -63,7 +83,7 @@ public function __construct(IFactory $factory, IUserManager $userManager, INotif * @throws \InvalidArgumentException When the notification was not prepared by a notifier * @since 9.0.0 */ - public function prepare(INotification $notification, $languageCode) { + public function prepare(INotification $notification, string $languageCode): INotification { if ($notification->getApp() !== 'firstrunwizard') { // Not my app => throw throw new \InvalidArgumentException(); diff --git a/tests/AppInfo/ApplicationTest.php b/tests/AppInfo/ApplicationTest.php index 049f5446a..95ccf84f0 100644 --- a/tests/AppInfo/ApplicationTest.php +++ b/tests/AppInfo/ApplicationTest.php @@ -122,16 +122,8 @@ public function testRegisterNotifier() { $manager = $this->createMock(IManager::class); $manager->expects($this->once()) - ->method('registerNotifier') - ->willReturnCallback(function($service, $info) { - $this->assertInstanceOf(\Closure::class, $service); - $this->assertInstanceOf(INotifier::class, $service()); - - $this->assertInstanceOf(\Closure::class, $info); - $data = $info(); - $this->assertArrayHasKey('id', $data); - $this->assertArrayHasKey('name', $data); - }); + ->method('registerNotifierService') + ->with(Notifier::class); $this->overwriteService('NotificationManager', $manager); $this->invokePrivate($app, 'registerNotificationNotifier');