Add event dispatcher to OCP

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2019-05-28 19:46:36 +02:00
parent 817bdc47c8
commit 3174012adf
37 changed files with 524 additions and 123 deletions

View File

@ -32,7 +32,7 @@ use OCA\DAV\CardDAV\SyncService;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Util;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class HookManager {
@ -57,14 +57,14 @@ class HookManager {
/** @var array */
private $addressBooksToDelete = [];
/** @var EventDispatcher */
/** @var EventDispatcherInterface */
private $eventDispatcher;
public function __construct(IUserManager $userManager,
SyncService $syncService,
CalDavBackend $calDav,
CardDavBackend $cardDav,
EventDispatcher $eventDispatcher) {
EventDispatcherInterface $eventDispatcher) {
$this->userManager = $userManager;
$this->syncService = $syncService;
$this->calDav = $calDav;

View File

@ -32,7 +32,6 @@ use OCP\IDBConnection;
use OCP\IImage;
use OCP\IUser;
use PHPUnit_Framework_MockObject_MockObject;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Test\TestCase;
class ConverterTest extends TestCase {
@ -40,19 +39,10 @@ class ConverterTest extends TestCase {
/** @var AccountManager | PHPUnit_Framework_MockObject_MockObject */
private $accountManager;
/** @var EventDispatcher | PHPUnit_Framework_MockObject_MockObject */
private $eventDispatcher;
/** @var IDBConnection | PHPUnit_Framework_MockObject_MockObject */
private $databaseConnection;
public function setUp() {
parent::setUp();
$this->databaseConnection = $this->getMockBuilder(IDBConnection::class)->getMock();
$this->eventDispatcher = $this->getMockBuilder(EventDispatcher::class)
->disableOriginalConstructor()->getMock();
$this->accountManager = $this->getMockBuilder(AccountManager::class)
->disableOriginalConstructor()->getMock();
$this->accountManager = $this->createMock(AccountManager::class);
}
public function getAccountManager(IUser $user) {

View File

@ -36,19 +36,19 @@ use OCA\DAV\HookManager;
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
class HookManagerTest extends TestCase {
/** @var IL10N */
private $l10n;
/** @var EventDispatcher | \PHPUnit_Framework_MockObject_MockObject */
/** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */
private $eventDispatcher;
public function 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
->expects($this->any())

View File

@ -38,7 +38,7 @@ use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node;
use OCP\ILogger;
use OCP\IUserManager;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class Storage extends Wrapper {
/** @var IMountPoint */
@ -50,7 +50,7 @@ class Storage extends Wrapper {
/** @var ILogger */
private $logger;
/** @var EventDispatcher */
/** @var EventDispatcherInterface */
private $eventDispatcher;
/** @var IRootFolder */
@ -66,7 +66,7 @@ class Storage extends Wrapper {
* @param ITrashManager $trashManager
* @param IUserManager|null $userManager
* @param ILogger|null $logger
* @param EventDispatcher|null $eventDispatcher
* @param EventDispatcherInterface|null $eventDispatcher
* @param IRootFolder|null $rootFolder
*/
public function __construct(
@ -74,7 +74,7 @@ class Storage extends Wrapper {
ITrashManager $trashManager = null,
IUserManager $userManager = null,
ILogger $logger = null,
EventDispatcher $eventDispatcher = null,
EventDispatcherInterface $eventDispatcher = null,
IRootFolder $rootFolder = null
) {
$this->mountPoint = $parameters['mountPoint'];

View File

@ -40,7 +40,7 @@ use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\ILogger;
use OCP\IUserManager;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Class Storage
@ -543,8 +543,7 @@ class StorageTest extends \Test\TestCase {
$userManager->expects($this->any())
->method('userExists')->willReturn($userExists);
$logger = $this->getMockBuilder(ILogger::class)->getMock();
$eventDispatcher = $this->getMockBuilder(EventDispatcher::class)
->disableOriginalConstructor()->getMock();
$eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$rootFolder = $this->createMock(IRootFolder::class);
$node = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock();
$trashManager = $this->createMock(ITrashManager::class);

View File

@ -16,7 +16,6 @@ return array(
'OCA\\TwoFactorBackupCodes\\Event\\CodesGenerated' => $baseDir . '/../lib/Event/CodesGenerated.php',
'OCA\\TwoFactorBackupCodes\\Listener\\ActivityPublisher' => $baseDir . '/../lib/Listener/ActivityPublisher.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\\ProviderEnabled' => $baseDir . '/../lib/Listener/ProviderEnabled.php',
'OCA\\TwoFactorBackupCodes\\Listener\\RegistryUpdater' => $baseDir . '/../lib/Listener/RegistryUpdater.php',

View File

@ -31,7 +31,6 @@ class ComposerStaticInitTwoFactorBackupCodes
'OCA\\TwoFactorBackupCodes\\Event\\CodesGenerated' => __DIR__ . '/..' . '/../lib/Event/CodesGenerated.php',
'OCA\\TwoFactorBackupCodes\\Listener\\ActivityPublisher' => __DIR__ . '/..' . '/../lib/Listener/ActivityPublisher.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\\ProviderEnabled' => __DIR__ . '/..' . '/../lib/Listener/ProviderEnabled.php',
'OCA\\TwoFactorBackupCodes\\Listener\\RegistryUpdater' => __DIR__ . '/..' . '/../lib/Listener/RegistryUpdater.php',

View File

@ -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() {

View File

@ -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;
}

View File

@ -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')

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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());
}
}
}

View File

@ -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;

View File

@ -28,15 +28,15 @@ use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
use OCA\TwoFactorBackupCodes\Listener\ActivityPublisher;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\EventDispatcher\Event;
use OCP\ILogger;
use OCP\IUser;
use PHPUnit_Framework_MockObject_MockObject;
use Symfony\Component\EventDispatcher\Event;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ActivityPublisherTest extends TestCase {
/** @var IManager|PHPUnit_Framework_MockObject_MockObject */
/** @var IManager|MockObject */
private $activityManager;
/** @var ILogger */

View File

@ -26,10 +26,10 @@ namespace OCA\TwoFactorBackupCodes\Tests\Unit\Listener;
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
use OCA\TwoFactorBackupCodes\Listener\ClearNotifications;
use OCP\EventDispatcher\Event;
use OCP\IUser;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
use Symfony\Component\EventDispatcher\Event;
use Test\TestCase;
class ClearNotificationsTest extends TestCase {

View File

@ -30,8 +30,8 @@ use OCA\TwoFactorBackupCodes\Listener\ProviderDisabled;
use OCP\Authentication\TwoFactorAuth\IRegistry;
use OCP\Authentication\TwoFactorAuth\RegistryEvent;
use OCP\BackgroundJob\IJobList;
use OCP\EventDispatcher\Event;
use OCP\IUser;
use Symfony\Component\EventDispatcher\Event;
use Test\TestCase;
class ProviderDisabledTest extends TestCase {

View File

@ -29,8 +29,8 @@ use OCA\TwoFactorBackupCodes\Listener\ProviderEnabled;
use OCP\Authentication\TwoFactorAuth\IRegistry;
use OCP\Authentication\TwoFactorAuth\RegistryEvent;
use OCP\BackgroundJob\IJobList;
use OCP\EventDispatcher\Event;
use OCP\IUser;
use Symfony\Component\EventDispatcher\Event;
use Test\TestCase;
class ProviderEnabledTest extends TestCase {

View File

@ -28,8 +28,8 @@ use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
use OCA\TwoFactorBackupCodes\Listener\RegistryUpdater;
use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
use OCP\Authentication\TwoFactorAuth\IRegistry;
use OCP\EventDispatcher\Event;
use OCP\IUser;
use Symfony\Component\EventDispatcher\Event;
use Test\TestCase;
class RegistryUpdaterTest extends TestCase {

View File

@ -26,11 +26,11 @@ use OCA\TwoFactorBackupCodes\Db\BackupCode;
use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper;
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
use OCA\TwoFactorBackupCodes\Service\BackupCodeStorage;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
use PHPUnit_Framework_MockObject_MockObject;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
class BackupCodeStorageTest extends TestCase {
@ -44,7 +44,7 @@ class BackupCodeStorageTest extends TestCase {
/** @var IHasher|PHPUnit_Framework_MockObject_MockObject */
private $hasher;
/** @var EventDispatcherInterface|PHPUnit_Framework_MockObject_MockObject */
/** @var IEventDispatcher|PHPUnit_Framework_MockObject_MockObject */
private $eventDispatcher;
/** @var BackupCodeStorage */
@ -56,7 +56,7 @@ class BackupCodeStorageTest extends TestCase {
$this->mapper = $this->createMock(BackupCodeMapper::class);
$this->random = $this->createMock(ISecureRandom::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);
}

View File

@ -169,6 +169,9 @@ return array(
'OCP\\Encryption\\IFile' => $baseDir . '/lib/public/Encryption/IFile.php',
'OCP\\Encryption\\IManager' => $baseDir . '/lib/public/Encryption/IManager.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\\AuthenticationFailedException' => $baseDir . '/lib/public/Federation/Exceptions/AuthenticationFailedException.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\\Update' => $baseDir . '/lib/private/Encryption/Update.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\\CloudFederationNotification' => $baseDir . '/lib/private/Federation/CloudFederationNotification.php',
'OC\\Federation\\CloudFederationProviderManager' => $baseDir . '/lib/private/Federation/CloudFederationProviderManager.php',

View File

@ -203,6 +203,9 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Encryption\\IFile' => __DIR__ . '/../../..' . '/lib/public/Encryption/IFile.php',
'OCP\\Encryption\\IManager' => __DIR__ . '/../../..' . '/lib/public/Encryption/IManager.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\\AuthenticationFailedException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/AuthenticationFailedException.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\\Update' => __DIR__ . '/../../..' . '/lib/private/Encryption/Update.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\\CloudFederationNotification' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationNotification.php',
'OC\\Federation\\CloudFederationProviderManager' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationProviderManager.php',

View File

@ -39,7 +39,7 @@ use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Types\Type;
use OCP\IConfig;
use OCP\Security\ISecureRandom;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class Migrator {
@ -53,7 +53,7 @@ class Migrator {
/** @var IConfig */
protected $config;
/** @var EventDispatcher */
/** @var EventDispatcherInterface */
private $dispatcher;
/** @var bool */
@ -63,12 +63,12 @@ class Migrator {
* @param \Doctrine\DBAL\Connection|Connection $connection
* @param ISecureRandom $random
* @param IConfig $config
* @param EventDispatcher $dispatcher
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(\Doctrine\DBAL\Connection $connection,
ISecureRandom $random,
IConfig $config,
EventDispatcher $dispatcher = null) {
EventDispatcherInterface $dispatcher = null) {
$this->connection = $connection;
$this->random = $random;
$this->config = $config;

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -128,7 +128,6 @@ use OCA\Theming\ThemingDefaults;
use OCP\Accounts\IAccountManager;
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Collaboration\AutoComplete\IManager;
use OCP\Contacts\ContactsMenu\IContactsStore;
use OCP\Dashboard\IDashboardManager;
@ -158,7 +157,6 @@ use OCP\Remote\IInstanceFactory;
use OCP\RichObjectStrings\IValidator;
use OCP\Security\IContentSecurityPolicyManager;
use OCP\Share\IShareHelper;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
@ -989,11 +987,9 @@ class Server extends ServerContainer implements IServerContainer {
$c->getLogger()
);
});
$this->registerService(EventDispatcher::class, function () {
return new EventDispatcher();
});
$this->registerAlias('EventDispatcher', EventDispatcher::class);
$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
$this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
$this->registerAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
$this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
$this->registerService('CryptoWrapper', function (Server $c) {
// FIXME: Instantiiated here due to cyclic dependency
@ -1858,7 +1854,7 @@ class Server extends ServerContainer implements IServerContainer {
* @since 8.2.0
*/
public function getEventDispatcher() {
return $this->query('EventDispatcher');
return $this->query(\OC\EventDispatcher\SymfonyAdapter::class);
}
/**

View File

@ -1,4 +1,5 @@
<?php
/**
* @copyright 2017, Roeland Jago Douma <roeland@famdouma.nl>
*
@ -21,24 +22,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Share20;
use OCP\Files\File;
use OCP\Share\IShare;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use OCP\Share;
class LegacyHooks {
/** @var EventDispatcher */
/** @var EventDispatcherInterface */
private $eventDispatcher;
/**
* LegacyHooks constructor.
*
* @param EventDispatcher $eventDispatcher
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(EventDispatcher $eventDispatcher) {
public function __construct(EventDispatcherInterface $eventDispatcher) {
$this->eventDispatcher = $eventDispatcher;
$this->eventDispatcher->addListener('OCP\Share::preUnshare', [$this, 'preUnshare']);

View File

@ -62,7 +62,7 @@ use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use OCP\Share\IShareProvider;
use OCP\Share;
@ -96,7 +96,7 @@ class Manager implements IManager {
private $rootFolder;
/** @var CappedMemoryCache */
private $sharingDisabledForUsersCache;
/** @var EventDispatcher */
/** @var EventDispatcherInterface */
private $eventDispatcher;
/** @var LegacyHooks */
private $legacyHooks;
@ -122,7 +122,7 @@ class Manager implements IManager {
* @param IProviderFactory $factory
* @param IUserManager $userManager
* @param IRootFolder $rootFolder
* @param EventDispatcher $eventDispatcher
* @param EventDispatcherInterface $eventDispatcher
* @param IMailer $mailer
* @param IURLGenerator $urlGenerator
* @param \OC_Defaults $defaults
@ -139,7 +139,7 @@ class Manager implements IManager {
IProviderFactory $factory,
IUserManager $userManager,
IRootFolder $rootFolder,
EventDispatcher $eventDispatcher,
EventDispatcherInterface $eventDispatcher,
IMailer $mailer,
IURLGenerator $urlGenerator,
\OC_Defaults $defaults

View File

@ -67,7 +67,7 @@ use OCP\User\Backend\IGetDisplayNameBackend;
use OCP\User\Backend\IGetHomeBackend;
use OCP\User\Backend\ISetDisplayNameBackend;
use OCP\User\Backend\ISetPasswordBackend;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
@ -84,7 +84,7 @@ class Database extends ABackend
/** @var CappedMemoryCache */
private $cache;
/** @var EventDispatcher */
/** @var EventDispatcherInterface */
private $eventDispatcher;
/** @var IDBConnection */
@ -96,7 +96,7 @@ class Database extends ABackend
/**
* \OC\User\Database constructor.
*
* @param EventDispatcher $eventDispatcher
* @param EventDispatcherInterface $eventDispatcher
* @param string $table
*/
public function __construct($eventDispatcher = null, $table = 'users') {

View File

@ -24,8 +24,8 @@ declare(strict_types=1);
namespace OCP\Authentication\TwoFactorAuth;
use OCP\EventDispatcher\Event;
use OCP\IUser;
use Symfony\Component\EventDispatcher\Event;
/**
* @since 15.0.0
@ -42,6 +42,7 @@ class RegistryEvent extends Event {
* @since 15.0.0
*/
public function __construct(IProvider $provider, IUser $user) {
parent::__construct();
$this->provider = $provider;
$this->user = $user;
}

View File

@ -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 {
}

View File

@ -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;
}

View File

@ -3,7 +3,9 @@
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
*
@ -19,15 +21,20 @@ declare(strict_types=1);
*
* 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;
namespace OCP\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;
/**
* @since 17.0.0
*/
interface IEventListener {
interface IListener {
public function handle(Event $event);
/**
* @param Event $event
*
* @since 17.0.0
*/
public function handle(Event $event): void;
}

View File

@ -40,7 +40,7 @@ use OCP\IURLGenerator;
use OCP\Lock\ILockingProvider;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
use OC\IntegrityCheck\Checker;
@ -67,7 +67,7 @@ class CheckSetupControllerTest extends TestCase {
private $logger;
/** @var Checker|\PHPUnit_Framework_MockObject_MockObject */
private $checker;
/** @var EventDispatcher|\PHPUnit_Framework_MockObject_MockObject */
/** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */
private $dispatcher;
/** @var Connection|\PHPUnit_Framework_MockObject_MockObject */
private $db;
@ -105,7 +105,7 @@ class CheckSetupControllerTest extends TestCase {
->will($this->returnCallback(function($message, array $replace) {
return vsprintf($message, $replace);
}));
$this->dispatcher = $this->getMockBuilder(EventDispatcher::class)
$this->dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)
->disableOriginalConstructor()->getMock();
$this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
->disableOriginalConstructor()->getMock();

View File

@ -23,7 +23,6 @@ namespace Test\Share20;
use OC\Files\Mount\MoveableMount;
use OC\HintException;
use OC\Share20\DefaultShareProvider;
use OCP\Defaults;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
@ -52,7 +51,7 @@ use OCP\Security\ISecureRandom;
use OCP\Security\IHasher;
use OCP\Files\Mount\IMountManager;
use OCP\IGroupManager;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
@ -89,7 +88,7 @@ class ManagerTest extends \Test\TestCase {
protected $userManager;
/** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */
protected $rootFolder;
/** @var EventDispatcher | \PHPUnit_Framework_MockObject_MockObject */
/** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */
protected $eventDispatcher;
/** @var IMailer|\PHPUnit_Framework_MockObject_MockObject */
protected $mailer;
@ -108,7 +107,7 @@ class ManagerTest extends \Test\TestCase {
$this->groupManager = $this->createMock(IGroupManager::class);
$this->userManager = $this->createMock(IUserManager::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->urlGenerator = $this->createMock(IURLGenerator::class);
$this->defaults = $this->createMock(\OC_Defaults::class);