Merge pull request #15777 from nextcloud/feature/ocp-event-dispatcher
Add event dispatcher to OCP
This commit is contained in:
commit
5fbf304c2a
|
@ -32,7 +32,7 @@ use OCA\DAV\CardDAV\SyncService;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use OCP\Util;
|
use OCP\Util;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
class HookManager {
|
class HookManager {
|
||||||
|
|
||||||
|
@ -57,14 +57,14 @@ class HookManager {
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $addressBooksToDelete = [];
|
private $addressBooksToDelete = [];
|
||||||
|
|
||||||
/** @var EventDispatcher */
|
/** @var EventDispatcherInterface */
|
||||||
private $eventDispatcher;
|
private $eventDispatcher;
|
||||||
|
|
||||||
public function __construct(IUserManager $userManager,
|
public function __construct(IUserManager $userManager,
|
||||||
SyncService $syncService,
|
SyncService $syncService,
|
||||||
CalDavBackend $calDav,
|
CalDavBackend $calDav,
|
||||||
CardDavBackend $cardDav,
|
CardDavBackend $cardDav,
|
||||||
EventDispatcher $eventDispatcher) {
|
EventDispatcherInterface $eventDispatcher) {
|
||||||
$this->userManager = $userManager;
|
$this->userManager = $userManager;
|
||||||
$this->syncService = $syncService;
|
$this->syncService = $syncService;
|
||||||
$this->calDav = $calDav;
|
$this->calDav = $calDav;
|
||||||
|
|
|
@ -32,7 +32,6 @@ use OCP\IDBConnection;
|
||||||
use OCP\IImage;
|
use OCP\IImage;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use PHPUnit_Framework_MockObject_MockObject;
|
use PHPUnit_Framework_MockObject_MockObject;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class ConverterTest extends TestCase {
|
class ConverterTest extends TestCase {
|
||||||
|
@ -40,19 +39,10 @@ class ConverterTest extends TestCase {
|
||||||
/** @var AccountManager | PHPUnit_Framework_MockObject_MockObject */
|
/** @var AccountManager | PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $accountManager;
|
private $accountManager;
|
||||||
|
|
||||||
/** @var EventDispatcher | PHPUnit_Framework_MockObject_MockObject */
|
|
||||||
private $eventDispatcher;
|
|
||||||
|
|
||||||
/** @var IDBConnection | PHPUnit_Framework_MockObject_MockObject */
|
|
||||||
private $databaseConnection;
|
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->databaseConnection = $this->getMockBuilder(IDBConnection::class)->getMock();
|
|
||||||
$this->eventDispatcher = $this->getMockBuilder(EventDispatcher::class)
|
$this->accountManager = $this->createMock(AccountManager::class);
|
||||||
->disableOriginalConstructor()->getMock();
|
|
||||||
$this->accountManager = $this->getMockBuilder(AccountManager::class)
|
|
||||||
->disableOriginalConstructor()->getMock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAccountManager(IUser $user) {
|
public function getAccountManager(IUser $user) {
|
||||||
|
|
|
@ -36,19 +36,19 @@ use OCA\DAV\HookManager;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class HookManagerTest extends TestCase {
|
class HookManagerTest extends TestCase {
|
||||||
/** @var IL10N */
|
/** @var IL10N */
|
||||||
private $l10n;
|
private $l10n;
|
||||||
|
|
||||||
/** @var EventDispatcher | \PHPUnit_Framework_MockObject_MockObject */
|
/** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $eventDispatcher;
|
private $eventDispatcher;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->eventDispatcher = $this->getMockBuilder(EventDispatcher::class)->disableOriginalConstructor()->getMock();
|
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
|
||||||
$this->l10n = $this->createMock(IL10N::class);
|
$this->l10n = $this->createMock(IL10N::class);
|
||||||
$this->l10n
|
$this->l10n
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
|
|
|
@ -38,7 +38,7 @@ use OCP\Files\Mount\IMountPoint;
|
||||||
use OCP\Files\Node;
|
use OCP\Files\Node;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
class Storage extends Wrapper {
|
class Storage extends Wrapper {
|
||||||
/** @var IMountPoint */
|
/** @var IMountPoint */
|
||||||
|
@ -50,7 +50,7 @@ class Storage extends Wrapper {
|
||||||
/** @var ILogger */
|
/** @var ILogger */
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
/** @var EventDispatcher */
|
/** @var EventDispatcherInterface */
|
||||||
private $eventDispatcher;
|
private $eventDispatcher;
|
||||||
|
|
||||||
/** @var IRootFolder */
|
/** @var IRootFolder */
|
||||||
|
@ -66,7 +66,7 @@ class Storage extends Wrapper {
|
||||||
* @param ITrashManager $trashManager
|
* @param ITrashManager $trashManager
|
||||||
* @param IUserManager|null $userManager
|
* @param IUserManager|null $userManager
|
||||||
* @param ILogger|null $logger
|
* @param ILogger|null $logger
|
||||||
* @param EventDispatcher|null $eventDispatcher
|
* @param EventDispatcherInterface|null $eventDispatcher
|
||||||
* @param IRootFolder|null $rootFolder
|
* @param IRootFolder|null $rootFolder
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
@ -74,7 +74,7 @@ class Storage extends Wrapper {
|
||||||
ITrashManager $trashManager = null,
|
ITrashManager $trashManager = null,
|
||||||
IUserManager $userManager = null,
|
IUserManager $userManager = null,
|
||||||
ILogger $logger = null,
|
ILogger $logger = null,
|
||||||
EventDispatcher $eventDispatcher = null,
|
EventDispatcherInterface $eventDispatcher = null,
|
||||||
IRootFolder $rootFolder = null
|
IRootFolder $rootFolder = null
|
||||||
) {
|
) {
|
||||||
$this->mountPoint = $parameters['mountPoint'];
|
$this->mountPoint = $parameters['mountPoint'];
|
||||||
|
|
|
@ -40,7 +40,7 @@ use OCP\Files\IRootFolder;
|
||||||
use OCP\Files\Node;
|
use OCP\Files\Node;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Storage
|
* Class Storage
|
||||||
|
@ -543,8 +543,7 @@ class StorageTest extends \Test\TestCase {
|
||||||
$userManager->expects($this->any())
|
$userManager->expects($this->any())
|
||||||
->method('userExists')->willReturn($userExists);
|
->method('userExists')->willReturn($userExists);
|
||||||
$logger = $this->getMockBuilder(ILogger::class)->getMock();
|
$logger = $this->getMockBuilder(ILogger::class)->getMock();
|
||||||
$eventDispatcher = $this->getMockBuilder(EventDispatcher::class)
|
$eventDispatcher = $this->createMock(EventDispatcherInterface::class);
|
||||||
->disableOriginalConstructor()->getMock();
|
|
||||||
$rootFolder = $this->createMock(IRootFolder::class);
|
$rootFolder = $this->createMock(IRootFolder::class);
|
||||||
$node = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock();
|
$node = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock();
|
||||||
$trashManager = $this->createMock(ITrashManager::class);
|
$trashManager = $this->createMock(ITrashManager::class);
|
||||||
|
|
|
@ -16,7 +16,6 @@ return array(
|
||||||
'OCA\\TwoFactorBackupCodes\\Event\\CodesGenerated' => $baseDir . '/../lib/Event/CodesGenerated.php',
|
'OCA\\TwoFactorBackupCodes\\Event\\CodesGenerated' => $baseDir . '/../lib/Event/CodesGenerated.php',
|
||||||
'OCA\\TwoFactorBackupCodes\\Listener\\ActivityPublisher' => $baseDir . '/../lib/Listener/ActivityPublisher.php',
|
'OCA\\TwoFactorBackupCodes\\Listener\\ActivityPublisher' => $baseDir . '/../lib/Listener/ActivityPublisher.php',
|
||||||
'OCA\\TwoFactorBackupCodes\\Listener\\ClearNotifications' => $baseDir . '/../lib/Listener/ClearNotifications.php',
|
'OCA\\TwoFactorBackupCodes\\Listener\\ClearNotifications' => $baseDir . '/../lib/Listener/ClearNotifications.php',
|
||||||
'OCA\\TwoFactorBackupCodes\\Listener\\IListener' => $baseDir . '/../lib/Listener/IListener.php',
|
|
||||||
'OCA\\TwoFactorBackupCodes\\Listener\\ProviderDisabled' => $baseDir . '/../lib/Listener/ProviderDisabled.php',
|
'OCA\\TwoFactorBackupCodes\\Listener\\ProviderDisabled' => $baseDir . '/../lib/Listener/ProviderDisabled.php',
|
||||||
'OCA\\TwoFactorBackupCodes\\Listener\\ProviderEnabled' => $baseDir . '/../lib/Listener/ProviderEnabled.php',
|
'OCA\\TwoFactorBackupCodes\\Listener\\ProviderEnabled' => $baseDir . '/../lib/Listener/ProviderEnabled.php',
|
||||||
'OCA\\TwoFactorBackupCodes\\Listener\\RegistryUpdater' => $baseDir . '/../lib/Listener/RegistryUpdater.php',
|
'OCA\\TwoFactorBackupCodes\\Listener\\RegistryUpdater' => $baseDir . '/../lib/Listener/RegistryUpdater.php',
|
||||||
|
|
|
@ -31,7 +31,6 @@ class ComposerStaticInitTwoFactorBackupCodes
|
||||||
'OCA\\TwoFactorBackupCodes\\Event\\CodesGenerated' => __DIR__ . '/..' . '/../lib/Event/CodesGenerated.php',
|
'OCA\\TwoFactorBackupCodes\\Event\\CodesGenerated' => __DIR__ . '/..' . '/../lib/Event/CodesGenerated.php',
|
||||||
'OCA\\TwoFactorBackupCodes\\Listener\\ActivityPublisher' => __DIR__ . '/..' . '/../lib/Listener/ActivityPublisher.php',
|
'OCA\\TwoFactorBackupCodes\\Listener\\ActivityPublisher' => __DIR__ . '/..' . '/../lib/Listener/ActivityPublisher.php',
|
||||||
'OCA\\TwoFactorBackupCodes\\Listener\\ClearNotifications' => __DIR__ . '/..' . '/../lib/Listener/ClearNotifications.php',
|
'OCA\\TwoFactorBackupCodes\\Listener\\ClearNotifications' => __DIR__ . '/..' . '/../lib/Listener/ClearNotifications.php',
|
||||||
'OCA\\TwoFactorBackupCodes\\Listener\\IListener' => __DIR__ . '/..' . '/../lib/Listener/IListener.php',
|
|
||||||
'OCA\\TwoFactorBackupCodes\\Listener\\ProviderDisabled' => __DIR__ . '/..' . '/../lib/Listener/ProviderDisabled.php',
|
'OCA\\TwoFactorBackupCodes\\Listener\\ProviderDisabled' => __DIR__ . '/..' . '/../lib/Listener/ProviderDisabled.php',
|
||||||
'OCA\\TwoFactorBackupCodes\\Listener\\ProviderEnabled' => __DIR__ . '/..' . '/../lib/Listener/ProviderEnabled.php',
|
'OCA\\TwoFactorBackupCodes\\Listener\\ProviderEnabled' => __DIR__ . '/..' . '/../lib/Listener/ProviderEnabled.php',
|
||||||
'OCA\\TwoFactorBackupCodes\\Listener\\RegistryUpdater' => __DIR__ . '/..' . '/../lib/Listener/RegistryUpdater.php',
|
'OCA\\TwoFactorBackupCodes\\Listener\\RegistryUpdater' => __DIR__ . '/..' . '/../lib/Listener/RegistryUpdater.php',
|
||||||
|
|
|
@ -29,18 +29,16 @@ use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper;
|
||||||
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
||||||
use OCA\TwoFactorBackupCodes\Listener\ActivityPublisher;
|
use OCA\TwoFactorBackupCodes\Listener\ActivityPublisher;
|
||||||
use OCA\TwoFactorBackupCodes\Listener\ClearNotifications;
|
use OCA\TwoFactorBackupCodes\Listener\ClearNotifications;
|
||||||
use OCA\TwoFactorBackupCodes\Listener\IListener;
|
|
||||||
use OCA\TwoFactorBackupCodes\Listener\ProviderDisabled;
|
use OCA\TwoFactorBackupCodes\Listener\ProviderDisabled;
|
||||||
use OCA\TwoFactorBackupCodes\Listener\ProviderEnabled;
|
use OCA\TwoFactorBackupCodes\Listener\ProviderEnabled;
|
||||||
use OCA\TwoFactorBackupCodes\Listener\RegistryUpdater;
|
use OCA\TwoFactorBackupCodes\Listener\RegistryUpdater;
|
||||||
use OCA\TwoFactorBackupCodes\Notifications\Notifier;
|
use OCA\TwoFactorBackupCodes\Notifications\Notifier;
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
||||||
use OCP\Authentication\TwoFactorAuth\RegistryEvent;
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\Notification\IManager;
|
use OCP\Notification\IManager;
|
||||||
use OCP\Util;
|
use OCP\Util;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
||||||
|
|
||||||
class Application extends App {
|
class Application extends App {
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
@ -62,32 +60,14 @@ class Application extends App {
|
||||||
Util::connectHook('OC_User', 'post_deleteUser', $this, 'deleteUser');
|
Util::connectHook('OC_User', 'post_deleteUser', $this, 'deleteUser');
|
||||||
|
|
||||||
$container = $this->getContainer();
|
$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) {
|
/** @var IEventDispatcher $eventDispatcher */
|
||||||
$listener->handle($event);
|
$eventDispatcher = $container->query(IEventDispatcher::class);
|
||||||
}
|
$eventDispatcher->addServiceListener(CodesGenerated::class, ActivityPublisher::class);
|
||||||
});
|
$eventDispatcher->addServiceListener(CodesGenerated::class, RegistryUpdater::class);
|
||||||
|
$eventDispatcher->addServiceListener(CodesGenerated::class, ClearNotifications::class);
|
||||||
$eventDispatcher->addListener(IRegistry::EVENT_PROVIDER_ENABLED, function(RegistryEvent $event) use ($container) {
|
$eventDispatcher->addServiceListener(IRegistry::EVENT_PROVIDER_ENABLED, ProviderEnabled::class);
|
||||||
/** @var IListener $listener */
|
$eventDispatcher->addServiceListener(IRegistry::EVENT_PROVIDER_DISABLED, ProviderDisabled::class);
|
||||||
$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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerNotification() {
|
public function registerNotification() {
|
||||||
|
|
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace OCA\TwoFactorBackupCodes\Event;
|
namespace OCA\TwoFactorBackupCodes\Event;
|
||||||
|
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use Symfony\Component\EventDispatcher\Event;
|
|
||||||
|
|
||||||
class CodesGenerated extends Event {
|
class CodesGenerated extends Event {
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ class CodesGenerated extends Event {
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
public function __construct(IUser $user) {
|
public function __construct(IUser $user) {
|
||||||
|
parent::__construct();
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,11 @@ namespace OCA\TwoFactorBackupCodes\Listener;
|
||||||
use BadMethodCallException;
|
use BadMethodCallException;
|
||||||
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
||||||
use OCP\Activity\IManager;
|
use OCP\Activity\IManager;
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
|
use OCP\EventDispatcher\IEventListener;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use Symfony\Component\EventDispatcher\Event;
|
|
||||||
|
|
||||||
class ActivityPublisher implements IListener {
|
class ActivityPublisher implements IEventListener {
|
||||||
|
|
||||||
/** @var IManager */
|
/** @var IManager */
|
||||||
private $activityManager;
|
private $activityManager;
|
||||||
|
@ -38,7 +39,8 @@ class ActivityPublisher implements IListener {
|
||||||
/** @var ILogger */
|
/** @var ILogger */
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
public function __construct(IManager $activityManager, ILogger $logger) {
|
public function __construct(IManager $activityManager,
|
||||||
|
ILogger $logger) {
|
||||||
$this->activityManager = $activityManager;
|
$this->activityManager = $activityManager;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +48,7 @@ class ActivityPublisher implements IListener {
|
||||||
/**
|
/**
|
||||||
* Push an event to the user's activity stream
|
* Push an event to the user's activity stream
|
||||||
*/
|
*/
|
||||||
public function handle(Event $event) {
|
public function handle(Event $event): void {
|
||||||
if ($event instanceof CodesGenerated) {
|
if ($event instanceof CodesGenerated) {
|
||||||
$activity = $this->activityManager->generateEvent();
|
$activity = $this->activityManager->generateEvent();
|
||||||
$activity->setApp('twofactor_backupcodes')
|
$activity->setApp('twofactor_backupcodes')
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl>
|
* @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl>
|
||||||
*
|
*
|
||||||
|
@ -25,10 +27,11 @@ declare(strict_types=1);
|
||||||
namespace OCA\TwoFactorBackupCodes\Listener;
|
namespace OCA\TwoFactorBackupCodes\Listener;
|
||||||
|
|
||||||
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
|
use OCP\EventDispatcher\IEventListener;
|
||||||
use OCP\Notification\IManager;
|
use OCP\Notification\IManager;
|
||||||
use Symfony\Component\EventDispatcher\Event;
|
|
||||||
|
|
||||||
class ClearNotifications implements IListener {
|
class ClearNotifications implements IEventListener {
|
||||||
|
|
||||||
/** @var IManager */
|
/** @var IManager */
|
||||||
private $manager;
|
private $manager;
|
||||||
|
@ -37,7 +40,7 @@ class ClearNotifications implements IListener {
|
||||||
$this->manager = $manager;
|
$this->manager = $manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(Event $event) {
|
public function handle(Event $event): void {
|
||||||
if (!($event instanceof CodesGenerated)) {
|
if (!($event instanceof CodesGenerated)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
|
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
|
||||||
*
|
*
|
||||||
|
@ -22,16 +24,16 @@ declare(strict_types=1);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
namespace OCA\TwoFactorBackupCodes\Listener;
|
namespace OCA\TwoFactorBackupCodes\Listener;
|
||||||
|
|
||||||
use OCA\TwoFactorBackupCodes\BackgroundJob\RememberBackupCodesJob;
|
use OCA\TwoFactorBackupCodes\BackgroundJob\RememberBackupCodesJob;
|
||||||
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
||||||
use OCP\Authentication\TwoFactorAuth\RegistryEvent;
|
use OCP\Authentication\TwoFactorAuth\RegistryEvent;
|
||||||
use OCP\BackgroundJob\IJobList;
|
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 */
|
/** @var IRegistry */
|
||||||
private $registry;
|
private $registry;
|
||||||
|
@ -45,7 +47,7 @@ class ProviderDisabled implements IListener {
|
||||||
$this->jobList = $jobList;
|
$this->jobList = $jobList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(Event $event) {
|
public function handle(Event $event): void {
|
||||||
if (!($event instanceof RegistryEvent)) {
|
if (!($event instanceof RegistryEvent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,10 @@ use OCA\TwoFactorBackupCodes\BackgroundJob\RememberBackupCodesJob;
|
||||||
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
||||||
use OCP\Authentication\TwoFactorAuth\RegistryEvent;
|
use OCP\Authentication\TwoFactorAuth\RegistryEvent;
|
||||||
use OCP\BackgroundJob\IJobList;
|
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 */
|
/** @var IRegistry */
|
||||||
private $registry;
|
private $registry;
|
||||||
|
@ -44,7 +45,7 @@ class ProviderEnabled implements IListener {
|
||||||
$this->jobList = $jobList;
|
$this->jobList = $jobList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(Event $event) {
|
public function handle(Event $event): void {
|
||||||
if (!($event instanceof RegistryEvent)) {
|
if (!($event instanceof RegistryEvent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,9 +27,10 @@ namespace OCA\TwoFactorBackupCodes\Listener;
|
||||||
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
||||||
use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
|
use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
|
||||||
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
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 */
|
/** @var IRegistry */
|
||||||
private $registry;
|
private $registry;
|
||||||
|
@ -42,9 +43,10 @@ class RegistryUpdater implements IListener {
|
||||||
$this->provider = $provider;
|
$this->provider = $provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(Event $event) {
|
public function handle(Event $event): void {
|
||||||
if ($event instanceof CodesGenerated) {
|
if ($event instanceof CodesGenerated) {
|
||||||
$this->registry->enableProviderFor($this->provider, $event->getUser());
|
$this->registry->enableProviderFor($this->provider, $event->getUser());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ use OCA\TwoFactorBackupCodes\Db\BackupCode;
|
||||||
use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper;
|
use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper;
|
||||||
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
||||||
use OCP\Activity\IManager;
|
use OCP\Activity\IManager;
|
||||||
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\Security\IHasher;
|
use OCP\Security\IHasher;
|
||||||
|
@ -46,13 +47,13 @@ class BackupCodeStorage {
|
||||||
/** @var ISecureRandom */
|
/** @var ISecureRandom */
|
||||||
private $random;
|
private $random;
|
||||||
|
|
||||||
/** @var EventDispatcherInterface */
|
/** @var IEventDispatcher */
|
||||||
private $eventDispatcher;
|
private $eventDispatcher;
|
||||||
|
|
||||||
public function __construct(BackupCodeMapper $mapper,
|
public function __construct(BackupCodeMapper $mapper,
|
||||||
ISecureRandom $random,
|
ISecureRandom $random,
|
||||||
IHasher $hasher,
|
IHasher $hasher,
|
||||||
EventDispatcherInterface $eventDispatcher) {
|
IEventDispatcher $eventDispatcher) {
|
||||||
$this->mapper = $mapper;
|
$this->mapper = $mapper;
|
||||||
$this->hasher = $hasher;
|
$this->hasher = $hasher;
|
||||||
$this->random = $random;
|
$this->random = $random;
|
||||||
|
|
|
@ -28,15 +28,15 @@ use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
||||||
use OCA\TwoFactorBackupCodes\Listener\ActivityPublisher;
|
use OCA\TwoFactorBackupCodes\Listener\ActivityPublisher;
|
||||||
use OCP\Activity\IEvent;
|
use OCP\Activity\IEvent;
|
||||||
use OCP\Activity\IManager;
|
use OCP\Activity\IManager;
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use PHPUnit_Framework_MockObject_MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use Symfony\Component\EventDispatcher\Event;
|
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class ActivityPublisherTest extends TestCase {
|
class ActivityPublisherTest extends TestCase {
|
||||||
|
|
||||||
/** @var IManager|PHPUnit_Framework_MockObject_MockObject */
|
/** @var IManager|MockObject */
|
||||||
private $activityManager;
|
private $activityManager;
|
||||||
|
|
||||||
/** @var ILogger */
|
/** @var ILogger */
|
||||||
|
|
|
@ -26,10 +26,10 @@ namespace OCA\TwoFactorBackupCodes\Tests\Unit\Listener;
|
||||||
|
|
||||||
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
||||||
use OCA\TwoFactorBackupCodes\Listener\ClearNotifications;
|
use OCA\TwoFactorBackupCodes\Listener\ClearNotifications;
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\Notification\IManager;
|
use OCP\Notification\IManager;
|
||||||
use OCP\Notification\INotification;
|
use OCP\Notification\INotification;
|
||||||
use Symfony\Component\EventDispatcher\Event;
|
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class ClearNotificationsTest extends TestCase {
|
class ClearNotificationsTest extends TestCase {
|
||||||
|
|
|
@ -30,8 +30,8 @@ use OCA\TwoFactorBackupCodes\Listener\ProviderDisabled;
|
||||||
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
||||||
use OCP\Authentication\TwoFactorAuth\RegistryEvent;
|
use OCP\Authentication\TwoFactorAuth\RegistryEvent;
|
||||||
use OCP\BackgroundJob\IJobList;
|
use OCP\BackgroundJob\IJobList;
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use Symfony\Component\EventDispatcher\Event;
|
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class ProviderDisabledTest extends TestCase {
|
class ProviderDisabledTest extends TestCase {
|
||||||
|
|
|
@ -29,8 +29,8 @@ use OCA\TwoFactorBackupCodes\Listener\ProviderEnabled;
|
||||||
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
||||||
use OCP\Authentication\TwoFactorAuth\RegistryEvent;
|
use OCP\Authentication\TwoFactorAuth\RegistryEvent;
|
||||||
use OCP\BackgroundJob\IJobList;
|
use OCP\BackgroundJob\IJobList;
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use Symfony\Component\EventDispatcher\Event;
|
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class ProviderEnabledTest extends TestCase {
|
class ProviderEnabledTest extends TestCase {
|
||||||
|
|
|
@ -28,8 +28,8 @@ use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
||||||
use OCA\TwoFactorBackupCodes\Listener\RegistryUpdater;
|
use OCA\TwoFactorBackupCodes\Listener\RegistryUpdater;
|
||||||
use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
|
use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
|
||||||
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use Symfony\Component\EventDispatcher\Event;
|
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class RegistryUpdaterTest extends TestCase {
|
class RegistryUpdaterTest extends TestCase {
|
||||||
|
|
|
@ -26,11 +26,11 @@ use OCA\TwoFactorBackupCodes\Db\BackupCode;
|
||||||
use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper;
|
use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper;
|
||||||
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
|
||||||
use OCA\TwoFactorBackupCodes\Service\BackupCodeStorage;
|
use OCA\TwoFactorBackupCodes\Service\BackupCodeStorage;
|
||||||
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\Security\IHasher;
|
use OCP\Security\IHasher;
|
||||||
use OCP\Security\ISecureRandom;
|
use OCP\Security\ISecureRandom;
|
||||||
use PHPUnit_Framework_MockObject_MockObject;
|
use PHPUnit_Framework_MockObject_MockObject;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class BackupCodeStorageTest extends TestCase {
|
class BackupCodeStorageTest extends TestCase {
|
||||||
|
@ -44,7 +44,7 @@ class BackupCodeStorageTest extends TestCase {
|
||||||
/** @var IHasher|PHPUnit_Framework_MockObject_MockObject */
|
/** @var IHasher|PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $hasher;
|
private $hasher;
|
||||||
|
|
||||||
/** @var EventDispatcherInterface|PHPUnit_Framework_MockObject_MockObject */
|
/** @var IEventDispatcher|PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $eventDispatcher;
|
private $eventDispatcher;
|
||||||
|
|
||||||
/** @var BackupCodeStorage */
|
/** @var BackupCodeStorage */
|
||||||
|
@ -56,7 +56,7 @@ class BackupCodeStorageTest extends TestCase {
|
||||||
$this->mapper = $this->createMock(BackupCodeMapper::class);
|
$this->mapper = $this->createMock(BackupCodeMapper::class);
|
||||||
$this->random = $this->createMock(ISecureRandom::class);
|
$this->random = $this->createMock(ISecureRandom::class);
|
||||||
$this->hasher = $this->createMock(IHasher::class);
|
$this->hasher = $this->createMock(IHasher::class);
|
||||||
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
|
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||||
|
|
||||||
$this->storage = new BackupCodeStorage($this->mapper, $this->random, $this->hasher, $this->eventDispatcher);
|
$this->storage = new BackupCodeStorage($this->mapper, $this->random, $this->hasher, $this->eventDispatcher);
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,6 +169,9 @@ return array(
|
||||||
'OCP\\Encryption\\IFile' => $baseDir . '/lib/public/Encryption/IFile.php',
|
'OCP\\Encryption\\IFile' => $baseDir . '/lib/public/Encryption/IFile.php',
|
||||||
'OCP\\Encryption\\IManager' => $baseDir . '/lib/public/Encryption/IManager.php',
|
'OCP\\Encryption\\IManager' => $baseDir . '/lib/public/Encryption/IManager.php',
|
||||||
'OCP\\Encryption\\Keys\\IStorage' => $baseDir . '/lib/public/Encryption/Keys/IStorage.php',
|
'OCP\\Encryption\\Keys\\IStorage' => $baseDir . '/lib/public/Encryption/Keys/IStorage.php',
|
||||||
|
'OCP\\EventDispatcher\\Event' => $baseDir . '/lib/public/EventDispatcher/Event.php',
|
||||||
|
'OCP\\EventDispatcher\\IEventDispatcher' => $baseDir . '/lib/public/EventDispatcher/IEventDispatcher.php',
|
||||||
|
'OCP\\EventDispatcher\\IEventListener' => $baseDir . '/lib/public/EventDispatcher/IEventListener.php',
|
||||||
'OCP\\Federation\\Exceptions\\ActionNotSupportedException' => $baseDir . '/lib/public/Federation/Exceptions/ActionNotSupportedException.php',
|
'OCP\\Federation\\Exceptions\\ActionNotSupportedException' => $baseDir . '/lib/public/Federation/Exceptions/ActionNotSupportedException.php',
|
||||||
'OCP\\Federation\\Exceptions\\AuthenticationFailedException' => $baseDir . '/lib/public/Federation/Exceptions/AuthenticationFailedException.php',
|
'OCP\\Federation\\Exceptions\\AuthenticationFailedException' => $baseDir . '/lib/public/Federation/Exceptions/AuthenticationFailedException.php',
|
||||||
'OCP\\Federation\\Exceptions\\BadRequestException' => $baseDir . '/lib/public/Federation/Exceptions/BadRequestException.php',
|
'OCP\\Federation\\Exceptions\\BadRequestException' => $baseDir . '/lib/public/Federation/Exceptions/BadRequestException.php',
|
||||||
|
@ -810,6 +813,9 @@ return array(
|
||||||
'OC\\Encryption\\Manager' => $baseDir . '/lib/private/Encryption/Manager.php',
|
'OC\\Encryption\\Manager' => $baseDir . '/lib/private/Encryption/Manager.php',
|
||||||
'OC\\Encryption\\Update' => $baseDir . '/lib/private/Encryption/Update.php',
|
'OC\\Encryption\\Update' => $baseDir . '/lib/private/Encryption/Update.php',
|
||||||
'OC\\Encryption\\Util' => $baseDir . '/lib/private/Encryption/Util.php',
|
'OC\\Encryption\\Util' => $baseDir . '/lib/private/Encryption/Util.php',
|
||||||
|
'OC\\EventDispatcher\\EventDispatcher' => $baseDir . '/lib/private/EventDispatcher/EventDispatcher.php',
|
||||||
|
'OC\\EventDispatcher\\ServiceEventListener' => $baseDir . '/lib/private/EventDispatcher/ServiceEventListener.php',
|
||||||
|
'OC\\EventDispatcher\\SymfonyAdapter' => $baseDir . '/lib/private/EventDispatcher/SymfonyAdapter.php',
|
||||||
'OC\\Federation\\CloudFederationFactory' => $baseDir . '/lib/private/Federation/CloudFederationFactory.php',
|
'OC\\Federation\\CloudFederationFactory' => $baseDir . '/lib/private/Federation/CloudFederationFactory.php',
|
||||||
'OC\\Federation\\CloudFederationNotification' => $baseDir . '/lib/private/Federation/CloudFederationNotification.php',
|
'OC\\Federation\\CloudFederationNotification' => $baseDir . '/lib/private/Federation/CloudFederationNotification.php',
|
||||||
'OC\\Federation\\CloudFederationProviderManager' => $baseDir . '/lib/private/Federation/CloudFederationProviderManager.php',
|
'OC\\Federation\\CloudFederationProviderManager' => $baseDir . '/lib/private/Federation/CloudFederationProviderManager.php',
|
||||||
|
|
|
@ -203,6 +203,9 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
||||||
'OCP\\Encryption\\IFile' => __DIR__ . '/../../..' . '/lib/public/Encryption/IFile.php',
|
'OCP\\Encryption\\IFile' => __DIR__ . '/../../..' . '/lib/public/Encryption/IFile.php',
|
||||||
'OCP\\Encryption\\IManager' => __DIR__ . '/../../..' . '/lib/public/Encryption/IManager.php',
|
'OCP\\Encryption\\IManager' => __DIR__ . '/../../..' . '/lib/public/Encryption/IManager.php',
|
||||||
'OCP\\Encryption\\Keys\\IStorage' => __DIR__ . '/../../..' . '/lib/public/Encryption/Keys/IStorage.php',
|
'OCP\\Encryption\\Keys\\IStorage' => __DIR__ . '/../../..' . '/lib/public/Encryption/Keys/IStorage.php',
|
||||||
|
'OCP\\EventDispatcher\\Event' => __DIR__ . '/../../..' . '/lib/public/EventDispatcher/Event.php',
|
||||||
|
'OCP\\EventDispatcher\\IEventDispatcher' => __DIR__ . '/../../..' . '/lib/public/EventDispatcher/IEventDispatcher.php',
|
||||||
|
'OCP\\EventDispatcher\\IEventListener' => __DIR__ . '/../../..' . '/lib/public/EventDispatcher/IEventListener.php',
|
||||||
'OCP\\Federation\\Exceptions\\ActionNotSupportedException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/ActionNotSupportedException.php',
|
'OCP\\Federation\\Exceptions\\ActionNotSupportedException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/ActionNotSupportedException.php',
|
||||||
'OCP\\Federation\\Exceptions\\AuthenticationFailedException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/AuthenticationFailedException.php',
|
'OCP\\Federation\\Exceptions\\AuthenticationFailedException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/AuthenticationFailedException.php',
|
||||||
'OCP\\Federation\\Exceptions\\BadRequestException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/BadRequestException.php',
|
'OCP\\Federation\\Exceptions\\BadRequestException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/BadRequestException.php',
|
||||||
|
@ -844,6 +847,9 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
||||||
'OC\\Encryption\\Manager' => __DIR__ . '/../../..' . '/lib/private/Encryption/Manager.php',
|
'OC\\Encryption\\Manager' => __DIR__ . '/../../..' . '/lib/private/Encryption/Manager.php',
|
||||||
'OC\\Encryption\\Update' => __DIR__ . '/../../..' . '/lib/private/Encryption/Update.php',
|
'OC\\Encryption\\Update' => __DIR__ . '/../../..' . '/lib/private/Encryption/Update.php',
|
||||||
'OC\\Encryption\\Util' => __DIR__ . '/../../..' . '/lib/private/Encryption/Util.php',
|
'OC\\Encryption\\Util' => __DIR__ . '/../../..' . '/lib/private/Encryption/Util.php',
|
||||||
|
'OC\\EventDispatcher\\EventDispatcher' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/EventDispatcher.php',
|
||||||
|
'OC\\EventDispatcher\\ServiceEventListener' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/ServiceEventListener.php',
|
||||||
|
'OC\\EventDispatcher\\SymfonyAdapter' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/SymfonyAdapter.php',
|
||||||
'OC\\Federation\\CloudFederationFactory' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationFactory.php',
|
'OC\\Federation\\CloudFederationFactory' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationFactory.php',
|
||||||
'OC\\Federation\\CloudFederationNotification' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationNotification.php',
|
'OC\\Federation\\CloudFederationNotification' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationNotification.php',
|
||||||
'OC\\Federation\\CloudFederationProviderManager' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationProviderManager.php',
|
'OC\\Federation\\CloudFederationProviderManager' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationProviderManager.php',
|
||||||
|
|
|
@ -39,7 +39,7 @@ use Doctrine\DBAL\Types\StringType;
|
||||||
use Doctrine\DBAL\Types\Type;
|
use Doctrine\DBAL\Types\Type;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\Security\ISecureRandom;
|
use OCP\Security\ISecureRandom;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
|
||||||
class Migrator {
|
class Migrator {
|
||||||
|
@ -53,7 +53,7 @@ class Migrator {
|
||||||
/** @var IConfig */
|
/** @var IConfig */
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
/** @var EventDispatcher */
|
/** @var EventDispatcherInterface */
|
||||||
private $dispatcher;
|
private $dispatcher;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
|
@ -63,12 +63,12 @@ class Migrator {
|
||||||
* @param \Doctrine\DBAL\Connection|Connection $connection
|
* @param \Doctrine\DBAL\Connection|Connection $connection
|
||||||
* @param ISecureRandom $random
|
* @param ISecureRandom $random
|
||||||
* @param IConfig $config
|
* @param IConfig $config
|
||||||
* @param EventDispatcher $dispatcher
|
* @param EventDispatcherInterface $dispatcher
|
||||||
*/
|
*/
|
||||||
public function __construct(\Doctrine\DBAL\Connection $connection,
|
public function __construct(\Doctrine\DBAL\Connection $connection,
|
||||||
ISecureRandom $random,
|
ISecureRandom $random,
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
EventDispatcher $dispatcher = null) {
|
EventDispatcherInterface $dispatcher = null) {
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
$this->random = $random;
|
$this->random = $random;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
|
*
|
||||||
|
* @author 2019 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 OC\EventDispatcher;
|
||||||
|
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
|
use OCP\IContainer;
|
||||||
|
use OCP\ILogger;
|
||||||
|
use OCP\IServerContainer;
|
||||||
|
use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher;
|
||||||
|
|
||||||
|
class EventDispatcher implements IEventDispatcher {
|
||||||
|
|
||||||
|
/** @var SymfonyDispatcher */
|
||||||
|
private $dispatcher;
|
||||||
|
|
||||||
|
/** @var IContainer */
|
||||||
|
private $container;
|
||||||
|
|
||||||
|
/** @var ILogger */
|
||||||
|
private $logger;
|
||||||
|
|
||||||
|
public function __construct(SymfonyDispatcher $dispatcher,
|
||||||
|
IServerContainer $container,
|
||||||
|
ILogger $logger) {
|
||||||
|
$this->dispatcher = $dispatcher;
|
||||||
|
$this->container = $container;
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addListener(string $eventName,
|
||||||
|
callable $listener,
|
||||||
|
int $priority = 0): void {
|
||||||
|
$this->dispatcher->addListener($eventName, $listener, $priority);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addServiceListener(string $eventName,
|
||||||
|
string $className,
|
||||||
|
int $priority = 0): void {
|
||||||
|
$listener = new ServiceEventListener(
|
||||||
|
$this->container,
|
||||||
|
$className,
|
||||||
|
$this->logger
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->addListener($eventName, $listener, $priority);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dispatch(string $eventName,
|
||||||
|
Event $event): void {
|
||||||
|
|
||||||
|
$this->dispatcher->dispatch($eventName, $event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return SymfonyDispatcher
|
||||||
|
*/
|
||||||
|
public function getSymfonyDispatcher(): SymfonyDispatcher {
|
||||||
|
return $this->dispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
|
*
|
||||||
|
* @author 2019 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 OC\EventDispatcher;
|
||||||
|
|
||||||
|
use OCP\AppFramework\QueryException;
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
|
use OCP\EventDispatcher\IEventListener;
|
||||||
|
use OCP\IContainer;
|
||||||
|
use OCP\ILogger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lazy service event listener
|
||||||
|
*
|
||||||
|
* Makes it possible to lazy-route a dispatched event to a service instance
|
||||||
|
* created by the service container
|
||||||
|
*/
|
||||||
|
final class ServiceEventListener {
|
||||||
|
|
||||||
|
/** @var IContainer */
|
||||||
|
private $container;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
private $class;
|
||||||
|
|
||||||
|
/** @var ILogger */
|
||||||
|
private $logger;
|
||||||
|
|
||||||
|
/** @var null|IEventListener */
|
||||||
|
private $service;
|
||||||
|
|
||||||
|
public function __construct(IContainer $container,
|
||||||
|
string $class,
|
||||||
|
ILogger $logger) {
|
||||||
|
$this->container = $container;
|
||||||
|
$this->class = $class;
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __invoke(Event $event) {
|
||||||
|
if ($this->service === null) {
|
||||||
|
try {
|
||||||
|
$this->service = $this->container->query($this->class);
|
||||||
|
} catch (QueryException $e) {
|
||||||
|
$this->logger->logException($e, [
|
||||||
|
'level' => ILogger::ERROR,
|
||||||
|
'message' => "Could not load event listener service " . $this->class,
|
||||||
|
]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->service->handle($event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,140 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
|
*
|
||||||
|
* @author 2019 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 OC\EventDispatcher;
|
||||||
|
|
||||||
|
use function is_callable;
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
|
use Symfony\Component\EventDispatcher\Event as SymfonyEvent;
|
||||||
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
|
||||||
|
class SymfonyAdapter implements EventDispatcherInterface {
|
||||||
|
|
||||||
|
/** @var EventDispatcher */
|
||||||
|
private $eventDispatcher;
|
||||||
|
|
||||||
|
public function __construct(EventDispatcher $eventDispatcher) {
|
||||||
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatches an event to all registered listeners.
|
||||||
|
*
|
||||||
|
* @param string $eventName The name of the event to dispatch. The name of
|
||||||
|
* the event is the name of the method that is
|
||||||
|
* invoked on listeners.
|
||||||
|
* @param SymfonyEvent|null $event The event to pass to the event handlers/listeners
|
||||||
|
* If not supplied, an empty Event instance is created
|
||||||
|
*
|
||||||
|
* @return SymfonyEvent
|
||||||
|
*/
|
||||||
|
public function dispatch($eventName, SymfonyEvent $event = null) {
|
||||||
|
if ($event instanceof Event) {
|
||||||
|
$this->eventDispatcher->dispatch($eventName, $event);
|
||||||
|
} else {
|
||||||
|
// Legacy event
|
||||||
|
$this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName, $event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an event listener that listens on the specified events.
|
||||||
|
*
|
||||||
|
* @param string $eventName The event to listen on
|
||||||
|
* @param callable $listener The listener
|
||||||
|
* @param int $priority The higher this value, the earlier an event
|
||||||
|
* listener will be triggered in the chain (defaults to 0)
|
||||||
|
*/
|
||||||
|
public function addListener($eventName, $listener, $priority = 0) {
|
||||||
|
if (is_callable($listener)) {
|
||||||
|
$this->eventDispatcher->addListener($eventName, $listener, $priority);
|
||||||
|
} else {
|
||||||
|
// Legacy listener
|
||||||
|
$this->eventDispatcher->getSymfonyDispatcher()->addListener($eventName, $listener, $priority);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an event subscriber.
|
||||||
|
*
|
||||||
|
* The subscriber is asked for all the events it is
|
||||||
|
* interested in and added as a listener for these events.
|
||||||
|
*/
|
||||||
|
public function addSubscriber(EventSubscriberInterface $subscriber) {
|
||||||
|
$this->eventDispatcher->getSymfonyDispatcher()->addSubscriber($subscriber);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes an event listener from the specified events.
|
||||||
|
*
|
||||||
|
* @param string $eventName The event to remove a listener from
|
||||||
|
* @param callable $listener The listener to remove
|
||||||
|
*/
|
||||||
|
public function removeListener($eventName, $listener) {
|
||||||
|
$this->eventDispatcher->getSymfonyDispatcher()->removeListener($eventName, $listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeSubscriber(EventSubscriberInterface $subscriber) {
|
||||||
|
$this->eventDispatcher->getSymfonyDispatcher()->removeSubscriber($subscriber);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the listeners of a specific event or all listeners sorted by descending priority.
|
||||||
|
*
|
||||||
|
* @param string|null $eventName The name of the event
|
||||||
|
*
|
||||||
|
* @return array The event listeners for the specified event, or all event listeners by event name
|
||||||
|
*/
|
||||||
|
public function getListeners($eventName = null) {
|
||||||
|
return $this->eventDispatcher->getSymfonyDispatcher()->getListeners($eventName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the listener priority for a specific event.
|
||||||
|
*
|
||||||
|
* Returns null if the event or the listener does not exist.
|
||||||
|
*
|
||||||
|
* @param string $eventName The name of the event
|
||||||
|
* @param callable $listener The listener
|
||||||
|
*
|
||||||
|
* @return int|null The event listener priority
|
||||||
|
*/
|
||||||
|
public function getListenerPriority($eventName, $listener) {
|
||||||
|
return $this->eventDispatcher->getSymfonyDispatcher()->getListenerPriority($eventName, $listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether an event has any registered listeners.
|
||||||
|
*
|
||||||
|
* @param string|null $eventName The name of the event
|
||||||
|
*
|
||||||
|
* @return bool true if the specified event has any listeners, false otherwise
|
||||||
|
*/
|
||||||
|
public function hasListeners($eventName = null) {
|
||||||
|
return $this->eventDispatcher->getSymfonyDispatcher()->hasListeners($eventName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -128,7 +128,6 @@ use OCA\Theming\ThemingDefaults;
|
||||||
|
|
||||||
use OCP\Accounts\IAccountManager;
|
use OCP\Accounts\IAccountManager;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
use OCP\AppFramework\Utility\ITimeFactory;
|
|
||||||
use OCP\Collaboration\AutoComplete\IManager;
|
use OCP\Collaboration\AutoComplete\IManager;
|
||||||
use OCP\Contacts\ContactsMenu\IContactsStore;
|
use OCP\Contacts\ContactsMenu\IContactsStore;
|
||||||
use OCP\Dashboard\IDashboardManager;
|
use OCP\Dashboard\IDashboardManager;
|
||||||
|
@ -158,7 +157,6 @@ use OCP\Remote\IInstanceFactory;
|
||||||
use OCP\RichObjectStrings\IValidator;
|
use OCP\RichObjectStrings\IValidator;
|
||||||
use OCP\Security\IContentSecurityPolicyManager;
|
use OCP\Security\IContentSecurityPolicyManager;
|
||||||
use OCP\Share\IShareHelper;
|
use OCP\Share\IShareHelper;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
|
||||||
|
@ -989,11 +987,9 @@ class Server extends ServerContainer implements IServerContainer {
|
||||||
$c->getLogger()
|
$c->getLogger()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
$this->registerService(EventDispatcher::class, function () {
|
$this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
|
||||||
return new EventDispatcher();
|
$this->registerAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
|
||||||
});
|
$this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
|
||||||
$this->registerAlias('EventDispatcher', EventDispatcher::class);
|
|
||||||
$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
|
|
||||||
|
|
||||||
$this->registerService('CryptoWrapper', function (Server $c) {
|
$this->registerService('CryptoWrapper', function (Server $c) {
|
||||||
// FIXME: Instantiiated here due to cyclic dependency
|
// FIXME: Instantiiated here due to cyclic dependency
|
||||||
|
@ -1858,7 +1854,7 @@ class Server extends ServerContainer implements IServerContainer {
|
||||||
* @since 8.2.0
|
* @since 8.2.0
|
||||||
*/
|
*/
|
||||||
public function getEventDispatcher() {
|
public function getEventDispatcher() {
|
||||||
return $this->query('EventDispatcher');
|
return $this->query(\OC\EventDispatcher\SymfonyAdapter::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copyright 2017, Roeland Jago Douma <roeland@famdouma.nl>
|
* @copyright 2017, Roeland Jago Douma <roeland@famdouma.nl>
|
||||||
*
|
*
|
||||||
|
@ -21,24 +22,26 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace OC\Share20;
|
namespace OC\Share20;
|
||||||
|
|
||||||
use OCP\Files\File;
|
use OCP\Files\File;
|
||||||
use OCP\Share\IShare;
|
use OCP\Share\IShare;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
use OCP\Share;
|
use OCP\Share;
|
||||||
|
|
||||||
class LegacyHooks {
|
class LegacyHooks {
|
||||||
/** @var EventDispatcher */
|
|
||||||
|
/** @var EventDispatcherInterface */
|
||||||
private $eventDispatcher;
|
private $eventDispatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LegacyHooks constructor.
|
* LegacyHooks constructor.
|
||||||
*
|
*
|
||||||
* @param EventDispatcher $eventDispatcher
|
* @param EventDispatcherInterface $eventDispatcher
|
||||||
*/
|
*/
|
||||||
public function __construct(EventDispatcher $eventDispatcher) {
|
public function __construct(EventDispatcherInterface $eventDispatcher) {
|
||||||
$this->eventDispatcher = $eventDispatcher;
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
|
|
||||||
$this->eventDispatcher->addListener('OCP\Share::preUnshare', [$this, 'preUnshare']);
|
$this->eventDispatcher->addListener('OCP\Share::preUnshare', [$this, 'preUnshare']);
|
||||||
|
|
|
@ -62,7 +62,7 @@ use OCP\Share\Exceptions\ShareNotFound;
|
||||||
use OCP\Share\IManager;
|
use OCP\Share\IManager;
|
||||||
use OCP\Share\IProviderFactory;
|
use OCP\Share\IProviderFactory;
|
||||||
use OCP\Share\IShare;
|
use OCP\Share\IShare;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
use OCP\Share\IShareProvider;
|
use OCP\Share\IShareProvider;
|
||||||
use OCP\Share;
|
use OCP\Share;
|
||||||
|
@ -96,7 +96,7 @@ class Manager implements IManager {
|
||||||
private $rootFolder;
|
private $rootFolder;
|
||||||
/** @var CappedMemoryCache */
|
/** @var CappedMemoryCache */
|
||||||
private $sharingDisabledForUsersCache;
|
private $sharingDisabledForUsersCache;
|
||||||
/** @var EventDispatcher */
|
/** @var EventDispatcherInterface */
|
||||||
private $eventDispatcher;
|
private $eventDispatcher;
|
||||||
/** @var LegacyHooks */
|
/** @var LegacyHooks */
|
||||||
private $legacyHooks;
|
private $legacyHooks;
|
||||||
|
@ -122,7 +122,7 @@ class Manager implements IManager {
|
||||||
* @param IProviderFactory $factory
|
* @param IProviderFactory $factory
|
||||||
* @param IUserManager $userManager
|
* @param IUserManager $userManager
|
||||||
* @param IRootFolder $rootFolder
|
* @param IRootFolder $rootFolder
|
||||||
* @param EventDispatcher $eventDispatcher
|
* @param EventDispatcherInterface $eventDispatcher
|
||||||
* @param IMailer $mailer
|
* @param IMailer $mailer
|
||||||
* @param IURLGenerator $urlGenerator
|
* @param IURLGenerator $urlGenerator
|
||||||
* @param \OC_Defaults $defaults
|
* @param \OC_Defaults $defaults
|
||||||
|
@ -139,7 +139,7 @@ class Manager implements IManager {
|
||||||
IProviderFactory $factory,
|
IProviderFactory $factory,
|
||||||
IUserManager $userManager,
|
IUserManager $userManager,
|
||||||
IRootFolder $rootFolder,
|
IRootFolder $rootFolder,
|
||||||
EventDispatcher $eventDispatcher,
|
EventDispatcherInterface $eventDispatcher,
|
||||||
IMailer $mailer,
|
IMailer $mailer,
|
||||||
IURLGenerator $urlGenerator,
|
IURLGenerator $urlGenerator,
|
||||||
\OC_Defaults $defaults
|
\OC_Defaults $defaults
|
||||||
|
|
|
@ -67,7 +67,7 @@ use OCP\User\Backend\IGetDisplayNameBackend;
|
||||||
use OCP\User\Backend\IGetHomeBackend;
|
use OCP\User\Backend\IGetHomeBackend;
|
||||||
use OCP\User\Backend\ISetDisplayNameBackend;
|
use OCP\User\Backend\ISetDisplayNameBackend;
|
||||||
use OCP\User\Backend\ISetPasswordBackend;
|
use OCP\User\Backend\ISetPasswordBackend;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,7 +84,7 @@ class Database extends ABackend
|
||||||
/** @var CappedMemoryCache */
|
/** @var CappedMemoryCache */
|
||||||
private $cache;
|
private $cache;
|
||||||
|
|
||||||
/** @var EventDispatcher */
|
/** @var EventDispatcherInterface */
|
||||||
private $eventDispatcher;
|
private $eventDispatcher;
|
||||||
|
|
||||||
/** @var IDBConnection */
|
/** @var IDBConnection */
|
||||||
|
@ -96,7 +96,7 @@ class Database extends ABackend
|
||||||
/**
|
/**
|
||||||
* \OC\User\Database constructor.
|
* \OC\User\Database constructor.
|
||||||
*
|
*
|
||||||
* @param EventDispatcher $eventDispatcher
|
* @param EventDispatcherInterface $eventDispatcher
|
||||||
* @param string $table
|
* @param string $table
|
||||||
*/
|
*/
|
||||||
public function __construct($eventDispatcher = null, $table = 'users') {
|
public function __construct($eventDispatcher = null, $table = 'users') {
|
||||||
|
|
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace OCP\Authentication\TwoFactorAuth;
|
namespace OCP\Authentication\TwoFactorAuth;
|
||||||
|
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use Symfony\Component\EventDispatcher\Event;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 15.0.0
|
* @since 15.0.0
|
||||||
|
@ -42,6 +42,7 @@ class RegistryEvent extends Event {
|
||||||
* @since 15.0.0
|
* @since 15.0.0
|
||||||
*/
|
*/
|
||||||
public function __construct(IProvider $provider, IUser $user) {
|
public function __construct(IProvider $provider, IUser $user) {
|
||||||
|
parent::__construct();
|
||||||
$this->provider = $provider;
|
$this->provider = $provider;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
|
*
|
||||||
|
* @author 2019 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 OCP\EventDispatcher;
|
||||||
|
|
||||||
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base event class for the event dispatcher service
|
||||||
|
*
|
||||||
|
* Typically this class isn't instantiated directly but sub classed for specific
|
||||||
|
* event types
|
||||||
|
*
|
||||||
|
* @since 17.0.0
|
||||||
|
*/
|
||||||
|
class Event extends GenericEvent {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
|
*
|
||||||
|
* @author 2019 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 OCP\EventDispatcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event dispatcher service of Nextcloud
|
||||||
|
*
|
||||||
|
* @since 17.0.0
|
||||||
|
*/
|
||||||
|
interface IEventDispatcher {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $eventName preferably the fully-qualified class name of the Event sub class
|
||||||
|
* @param callable $listener the object that is invoked when a matching event is dispatched
|
||||||
|
* @param int $priority
|
||||||
|
*
|
||||||
|
* @since 17.0.0
|
||||||
|
*/
|
||||||
|
public function addListener(string $eventName, callable $listener, int $priority = 0): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $eventName preferably the fully-qualified class name of the Event sub class to listen for
|
||||||
|
* @param string $className fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container
|
||||||
|
* @param int $priority
|
||||||
|
*
|
||||||
|
* @since 17.0.0
|
||||||
|
*/
|
||||||
|
public function addServiceListener(string $eventName, string $className, int $priority = 0): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $eventName
|
||||||
|
* @param Event $event
|
||||||
|
*
|
||||||
|
* @since 17.0.0
|
||||||
|
*/
|
||||||
|
public function dispatch(string $eventName, Event $event): void;
|
||||||
|
|
||||||
|
}
|
|
@ -3,7 +3,9 @@
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
|
*
|
||||||
|
* @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
*
|
*
|
||||||
* @license GNU AGPL version 3 or any later version
|
* @license GNU AGPL version 3 or any later version
|
||||||
*
|
*
|
||||||
|
@ -19,15 +21,20 @@ declare(strict_types=1);
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* 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/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace OCA\TwoFactorBackupCodes\Listener;
|
namespace OCP\EventDispatcher;
|
||||||
|
|
||||||
use Symfony\Component\EventDispatcher\Event;
|
/**
|
||||||
|
* @since 17.0.0
|
||||||
|
*/
|
||||||
|
interface IEventListener {
|
||||||
|
|
||||||
interface IListener {
|
/**
|
||||||
|
* @param Event $event
|
||||||
public function handle(Event $event);
|
*
|
||||||
|
* @since 17.0.0
|
||||||
|
*/
|
||||||
|
public function handle(Event $event): void;
|
||||||
|
|
||||||
}
|
}
|
|
@ -40,7 +40,7 @@ use OCP\IURLGenerator;
|
||||||
use OCP\Lock\ILockingProvider;
|
use OCP\Lock\ILockingProvider;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
use OC\IntegrityCheck\Checker;
|
use OC\IntegrityCheck\Checker;
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ class CheckSetupControllerTest extends TestCase {
|
||||||
private $logger;
|
private $logger;
|
||||||
/** @var Checker|\PHPUnit_Framework_MockObject_MockObject */
|
/** @var Checker|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $checker;
|
private $checker;
|
||||||
/** @var EventDispatcher|\PHPUnit_Framework_MockObject_MockObject */
|
/** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $dispatcher;
|
private $dispatcher;
|
||||||
/** @var Connection|\PHPUnit_Framework_MockObject_MockObject */
|
/** @var Connection|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $db;
|
private $db;
|
||||||
|
@ -105,7 +105,7 @@ class CheckSetupControllerTest extends TestCase {
|
||||||
->will($this->returnCallback(function($message, array $replace) {
|
->will($this->returnCallback(function($message, array $replace) {
|
||||||
return vsprintf($message, $replace);
|
return vsprintf($message, $replace);
|
||||||
}));
|
}));
|
||||||
$this->dispatcher = $this->getMockBuilder(EventDispatcher::class)
|
$this->dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
|
$this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
|
|
|
@ -23,7 +23,6 @@ namespace Test\Share20;
|
||||||
use OC\Files\Mount\MoveableMount;
|
use OC\Files\Mount\MoveableMount;
|
||||||
use OC\HintException;
|
use OC\HintException;
|
||||||
use OC\Share20\DefaultShareProvider;
|
use OC\Share20\DefaultShareProvider;
|
||||||
use OCP\Defaults;
|
|
||||||
use OCP\Files\File;
|
use OCP\Files\File;
|
||||||
use OCP\Files\Folder;
|
use OCP\Files\Folder;
|
||||||
use OCP\Files\IRootFolder;
|
use OCP\Files\IRootFolder;
|
||||||
|
@ -52,7 +51,7 @@ use OCP\Security\ISecureRandom;
|
||||||
use OCP\Security\IHasher;
|
use OCP\Security\IHasher;
|
||||||
use OCP\Files\Mount\IMountManager;
|
use OCP\Files\Mount\IMountManager;
|
||||||
use OCP\IGroupManager;
|
use OCP\IGroupManager;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,7 +88,7 @@ class ManagerTest extends \Test\TestCase {
|
||||||
protected $userManager;
|
protected $userManager;
|
||||||
/** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */
|
/** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $rootFolder;
|
protected $rootFolder;
|
||||||
/** @var EventDispatcher | \PHPUnit_Framework_MockObject_MockObject */
|
/** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $eventDispatcher;
|
protected $eventDispatcher;
|
||||||
/** @var IMailer|\PHPUnit_Framework_MockObject_MockObject */
|
/** @var IMailer|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $mailer;
|
protected $mailer;
|
||||||
|
@ -108,7 +107,7 @@ class ManagerTest extends \Test\TestCase {
|
||||||
$this->groupManager = $this->createMock(IGroupManager::class);
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||||
$this->userManager = $this->createMock(IUserManager::class);
|
$this->userManager = $this->createMock(IUserManager::class);
|
||||||
$this->rootFolder = $this->createMock(IRootFolder::class);
|
$this->rootFolder = $this->createMock(IRootFolder::class);
|
||||||
$this->eventDispatcher = $this->createMock(EventDispatcher::class);
|
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
|
||||||
$this->mailer = $this->createMock(IMailer::class);
|
$this->mailer = $this->createMock(IMailer::class);
|
||||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||||
$this->defaults = $this->createMock(\OC_Defaults::class);
|
$this->defaults = $this->createMock(\OC_Defaults::class);
|
||||||
|
|
Loading…
Reference in New Issue