aboutsummaryrefslogtreecommitdiffstats
path: root/apps/twofactor_backupcodes/lib
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2019-05-28 19:46:36 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2019-06-25 10:02:27 +0200
commit3174012adf3fde4de74efa12cfa7e480b874b295 (patch)
treebc58b99dc45b5adcdeaf30269e9a6eab2c853773 /apps/twofactor_backupcodes/lib
parent817bdc47c804ae8511ad3423eae216f6ccdee6c6 (diff)
downloadnextcloud-server-3174012adf3fde4de74efa12cfa7e480b874b295.tar.gz
nextcloud-server-3174012adf3fde4de74efa12cfa7e480b874b295.zip
Add event dispatcher to OCP
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/twofactor_backupcodes/lib')
-rw-r--r--apps/twofactor_backupcodes/lib/AppInfo/Application.php36
-rw-r--r--apps/twofactor_backupcodes/lib/Event/CodesGenerated.php3
-rw-r--r--apps/twofactor_backupcodes/lib/Listener/ActivityPublisher.php10
-rw-r--r--apps/twofactor_backupcodes/lib/Listener/ClearNotifications.php9
-rw-r--r--apps/twofactor_backupcodes/lib/Listener/IListener.php33
-rw-r--r--apps/twofactor_backupcodes/lib/Listener/ProviderDisabled.php10
-rw-r--r--apps/twofactor_backupcodes/lib/Listener/ProviderEnabled.php7
-rw-r--r--apps/twofactor_backupcodes/lib/Listener/RegistryUpdater.php8
-rw-r--r--apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php5
9 files changed, 40 insertions, 81 deletions
diff --git a/apps/twofactor_backupcodes/lib/AppInfo/Application.php b/apps/twofactor_backupcodes/lib/AppInfo/Application.php
index fc6c94d5b7a..041af037067 100644
--- a/apps/twofactor_backupcodes/lib/AppInfo/Application.php
+++ b/apps/twofactor_backupcodes/lib/AppInfo/Application.php
@@ -29,18 +29,16 @@ use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper;
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
use OCA\TwoFactorBackupCodes\Listener\ActivityPublisher;
use OCA\TwoFactorBackupCodes\Listener\ClearNotifications;
-use OCA\TwoFactorBackupCodes\Listener\IListener;
use OCA\TwoFactorBackupCodes\Listener\ProviderDisabled;
use OCA\TwoFactorBackupCodes\Listener\ProviderEnabled;
use OCA\TwoFactorBackupCodes\Listener\RegistryUpdater;
use OCA\TwoFactorBackupCodes\Notifications\Notifier;
use OCP\AppFramework\App;
use OCP\Authentication\TwoFactorAuth\IRegistry;
-use OCP\Authentication\TwoFactorAuth\RegistryEvent;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IL10N;
use OCP\Notification\IManager;
use OCP\Util;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class Application extends App {
public function __construct() {
@@ -62,32 +60,14 @@ class Application extends App {
Util::connectHook('OC_User', 'post_deleteUser', $this, 'deleteUser');
$container = $this->getContainer();
- /** @var EventDispatcherInterface $eventDispatcher */
- $eventDispatcher = $container->query(EventDispatcherInterface::class);
- $eventDispatcher->addListener(CodesGenerated::class, function (CodesGenerated $event) use ($container) {
- /** @var IListener[] $listeners */
- $listeners = [
- $container->query(ActivityPublisher::class),
- $container->query(RegistryUpdater::class),
- $container->query(ClearNotifications::class),
- ];
- foreach ($listeners as $listener) {
- $listener->handle($event);
- }
- });
-
- $eventDispatcher->addListener(IRegistry::EVENT_PROVIDER_ENABLED, function(RegistryEvent $event) use ($container) {
- /** @var IListener $listener */
- $listener = $container->query(ProviderEnabled::class);
- $listener->handle($event);
- });
-
- $eventDispatcher->addListener(IRegistry::EVENT_PROVIDER_DISABLED, function(RegistryEvent $event) use ($container) {
- /** @var IListener $listener */
- $listener = $container->query(ProviderDisabled::class);
- $listener->handle($event);
- });
+ /** @var IEventDispatcher $eventDispatcher */
+ $eventDispatcher = $container->query(IEventDispatcher::class);
+ $eventDispatcher->addServiceListener(CodesGenerated::class, ActivityPublisher::class);
+ $eventDispatcher->addServiceListener(CodesGenerated::class, RegistryUpdater::class);
+ $eventDispatcher->addServiceListener(CodesGenerated::class, ClearNotifications::class);
+ $eventDispatcher->addServiceListener(IRegistry::EVENT_PROVIDER_ENABLED, ProviderEnabled::class);
+ $eventDispatcher->addServiceListener(IRegistry::EVENT_PROVIDER_DISABLED, ProviderDisabled::class);
}
public function registerNotification() {
diff --git a/apps/twofactor_backupcodes/lib/Event/CodesGenerated.php b/apps/twofactor_backupcodes/lib/Event/CodesGenerated.php
index c4ffcb37601..1724053281b 100644
--- a/apps/twofactor_backupcodes/lib/Event/CodesGenerated.php
+++ b/apps/twofactor_backupcodes/lib/Event/CodesGenerated.php
@@ -24,8 +24,8 @@ declare(strict_types=1);
namespace OCA\TwoFactorBackupCodes\Event;
+use OCP\EventDispatcher\Event;
use OCP\IUser;
-use Symfony\Component\EventDispatcher\Event;
class CodesGenerated extends Event {
@@ -33,6 +33,7 @@ class CodesGenerated extends Event {
private $user;
public function __construct(IUser $user) {
+ parent::__construct();
$this->user = $user;
}
diff --git a/apps/twofactor_backupcodes/lib/Listener/ActivityPublisher.php b/apps/twofactor_backupcodes/lib/Listener/ActivityPublisher.php
index 31e2ac6e508..75a5937b5fa 100644
--- a/apps/twofactor_backupcodes/lib/Listener/ActivityPublisher.php
+++ b/apps/twofactor_backupcodes/lib/Listener/ActivityPublisher.php
@@ -27,10 +27,11 @@ namespace OCA\TwoFactorBackupCodes\Listener;
use BadMethodCallException;
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
use OCP\Activity\IManager;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
use OCP\ILogger;
-use Symfony\Component\EventDispatcher\Event;
-class ActivityPublisher implements IListener {
+class ActivityPublisher implements IEventListener {
/** @var IManager */
private $activityManager;
@@ -38,7 +39,8 @@ class ActivityPublisher implements IListener {
/** @var ILogger */
private $logger;
- public function __construct(IManager $activityManager, ILogger $logger) {
+ public function __construct(IManager $activityManager,
+ ILogger $logger) {
$this->activityManager = $activityManager;
$this->logger = $logger;
}
@@ -46,7 +48,7 @@ class ActivityPublisher implements IListener {
/**
* Push an event to the user's activity stream
*/
- public function handle(Event $event) {
+ public function handle(Event $event): void {
if ($event instanceof CodesGenerated) {
$activity = $this->activityManager->generateEvent();
$activity->setApp('twofactor_backupcodes')
diff --git a/apps/twofactor_backupcodes/lib/Listener/ClearNotifications.php b/apps/twofactor_backupcodes/lib/Listener/ClearNotifications.php
index ad7fd188ebc..eb0f7363aab 100644
--- a/apps/twofactor_backupcodes/lib/Listener/ClearNotifications.php
+++ b/apps/twofactor_backupcodes/lib/Listener/ClearNotifications.php
@@ -1,5 +1,7 @@
<?php
+
declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl>
*
@@ -25,10 +27,11 @@ declare(strict_types=1);
namespace OCA\TwoFactorBackupCodes\Listener;
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
use OCP\Notification\IManager;
-use Symfony\Component\EventDispatcher\Event;
-class ClearNotifications implements IListener {
+class ClearNotifications implements IEventListener {
/** @var IManager */
private $manager;
@@ -37,7 +40,7 @@ class ClearNotifications implements IListener {
$this->manager = $manager;
}
- public function handle(Event $event) {
+ public function handle(Event $event): void {
if (!($event instanceof CodesGenerated)) {
return;
}
diff --git a/apps/twofactor_backupcodes/lib/Listener/IListener.php b/apps/twofactor_backupcodes/lib/Listener/IListener.php
deleted file mode 100644
index ec45de5c075..00000000000
--- a/apps/twofactor_backupcodes/lib/Listener/IListener.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\TwoFactorBackupCodes\Listener;
-
-use Symfony\Component\EventDispatcher\Event;
-
-interface IListener {
-
- public function handle(Event $event);
-
-}
diff --git a/apps/twofactor_backupcodes/lib/Listener/ProviderDisabled.php b/apps/twofactor_backupcodes/lib/Listener/ProviderDisabled.php
index 835eb0394f9..bf2899f391f 100644
--- a/apps/twofactor_backupcodes/lib/Listener/ProviderDisabled.php
+++ b/apps/twofactor_backupcodes/lib/Listener/ProviderDisabled.php
@@ -1,5 +1,7 @@
<?php
+
declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
*
@@ -22,16 +24,16 @@ declare(strict_types=1);
*
*/
-
namespace OCA\TwoFactorBackupCodes\Listener;
use OCA\TwoFactorBackupCodes\BackgroundJob\RememberBackupCodesJob;
use OCP\Authentication\TwoFactorAuth\IRegistry;
use OCP\Authentication\TwoFactorAuth\RegistryEvent;
use OCP\BackgroundJob\IJobList;
-use Symfony\Component\EventDispatcher\Event;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
-class ProviderDisabled implements IListener {
+class ProviderDisabled implements IEventListener {
/** @var IRegistry */
private $registry;
@@ -45,7 +47,7 @@ class ProviderDisabled implements IListener {
$this->jobList = $jobList;
}
- public function handle(Event $event) {
+ public function handle(Event $event): void {
if (!($event instanceof RegistryEvent)) {
return;
}
diff --git a/apps/twofactor_backupcodes/lib/Listener/ProviderEnabled.php b/apps/twofactor_backupcodes/lib/Listener/ProviderEnabled.php
index 48cbef66f1b..7c258213384 100644
--- a/apps/twofactor_backupcodes/lib/Listener/ProviderEnabled.php
+++ b/apps/twofactor_backupcodes/lib/Listener/ProviderEnabled.php
@@ -28,9 +28,10 @@ use OCA\TwoFactorBackupCodes\BackgroundJob\RememberBackupCodesJob;
use OCP\Authentication\TwoFactorAuth\IRegistry;
use OCP\Authentication\TwoFactorAuth\RegistryEvent;
use OCP\BackgroundJob\IJobList;
-use Symfony\Component\EventDispatcher\Event;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
-class ProviderEnabled implements IListener {
+class ProviderEnabled implements IEventListener {
/** @var IRegistry */
private $registry;
@@ -44,7 +45,7 @@ class ProviderEnabled implements IListener {
$this->jobList = $jobList;
}
- public function handle(Event $event) {
+ public function handle(Event $event): void {
if (!($event instanceof RegistryEvent)) {
return;
}
diff --git a/apps/twofactor_backupcodes/lib/Listener/RegistryUpdater.php b/apps/twofactor_backupcodes/lib/Listener/RegistryUpdater.php
index 95b0db090ee..93e4959b24b 100644
--- a/apps/twofactor_backupcodes/lib/Listener/RegistryUpdater.php
+++ b/apps/twofactor_backupcodes/lib/Listener/RegistryUpdater.php
@@ -27,9 +27,10 @@ namespace OCA\TwoFactorBackupCodes\Listener;
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
use OCP\Authentication\TwoFactorAuth\IRegistry;
-use Symfony\Component\EventDispatcher\Event;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
-class RegistryUpdater implements IListener {
+class RegistryUpdater implements IEventListener {
/** @var IRegistry */
private $registry;
@@ -42,9 +43,10 @@ class RegistryUpdater implements IListener {
$this->provider = $provider;
}
- public function handle(Event $event) {
+ public function handle(Event $event): void {
if ($event instanceof CodesGenerated) {
$this->registry->enableProviderFor($this->provider, $event->getUser());
}
}
+
}
diff --git a/apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php b/apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php
index 74a032dcc0a..88117c37ec0 100644
--- a/apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php
+++ b/apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php
@@ -27,6 +27,7 @@ use OCA\TwoFactorBackupCodes\Db\BackupCode;
use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper;
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
use OCP\Activity\IManager;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
use OCP\IUser;
use OCP\Security\IHasher;
@@ -46,13 +47,13 @@ class BackupCodeStorage {
/** @var ISecureRandom */
private $random;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
private $eventDispatcher;
public function __construct(BackupCodeMapper $mapper,
ISecureRandom $random,
IHasher $hasher,
- EventDispatcherInterface $eventDispatcher) {
+ IEventDispatcher $eventDispatcher) {
$this->mapper = $mapper;
$this->hasher = $hasher;
$this->random = $random;