Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>tags/v17.0.0beta1
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 { | ||||
/** @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; |
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 { | ||||
/** @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) | |||||
->disableOriginalConstructor()->getMock(); | |||||
$this->accountManager = $this->getMockBuilder(AccountManager::class) | |||||
->disableOriginalConstructor()->getMock(); | |||||
$this->accountManager = $this->createMock(AccountManager::class); | |||||
} | } | ||||
public function getAccountManager(IUser $user) { | public function getAccountManager(IUser $user) { |
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()) |
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 */ | ||||
/** @var ILogger */ | /** @var ILogger */ | ||||
private $logger; | private $logger; | ||||
/** @var EventDispatcher */ | |||||
/** @var EventDispatcherInterface */ | |||||
private $eventDispatcher; | private $eventDispatcher; | ||||
/** @var IRootFolder */ | /** @var IRootFolder */ | ||||
* @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( | ||||
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']; |
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 | ||||
$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) | |||||
->disableOriginalConstructor()->getMock(); | |||||
$eventDispatcher = $this->createMock(EventDispatcherInterface::class); | |||||
$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); |
'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', |
'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', |
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() { | ||||
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) { | |||||
$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() { | public function registerNotification() { |
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 { | ||||
private $user; | private $user; | ||||
public function __construct(IUser $user) { | public function __construct(IUser $user) { | ||||
parent::__construct(); | |||||
$this->user = $user; | $this->user = $user; | ||||
} | } | ||||
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; | ||||
/** @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; | ||||
} | } | ||||
/** | /** | ||||
* 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') |
<?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> | ||||
* | * | ||||
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; | ||||
$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; | ||||
} | } |
<?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> | ||||
* | * | ||||
* | * | ||||
*/ | */ | ||||
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; | ||||
$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; | ||||
} | } |
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; | ||||
$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; | ||||
} | } |
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; | ||||
$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()); | ||||
} | } | ||||
} | } | ||||
} | } |
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; | ||||
/** @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; |
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 Symfony\Component\EventDispatcher\Event; | |||||
use PHPUnit\Framework\MockObject\MockObject; | |||||
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 */ |
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 { |
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 { |
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 { |
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 { |
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 { | ||||
/** @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 */ | ||||
$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); | ||||
} | } |
'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', | ||||
'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', |
'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', | ||||
'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', |
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 { | ||||
/** @var IConfig */ | /** @var IConfig */ | ||||
protected $config; | protected $config; | ||||
/** @var EventDispatcher */ | |||||
/** @var EventDispatcherInterface */ | |||||
private $dispatcher; | private $dispatcher; | ||||
/** @var bool */ | /** @var bool */ | ||||
* @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; |
<?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; | |||||
} | |||||
} |
<?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); | |||||
} | |||||
} |
<?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); | |||||
} | |||||
} |
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; | ||||
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; | ||||
$c->getLogger() | $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) { | $this->registerService('CryptoWrapper', function (Server $c) { | ||||
// FIXME: Instantiiated here due to cyclic dependency | // FIXME: Instantiiated here due to cyclic dependency | ||||
* @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); | |||||
} | } | ||||
/** | /** |
<?php | <?php | ||||
/** | /** | ||||
* @copyright 2017, Roeland Jago Douma <roeland@famdouma.nl> | * @copyright 2017, Roeland Jago Douma <roeland@famdouma.nl> | ||||
* | * | ||||
* 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']); |
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; | ||||
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; | ||||
* @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 | ||||
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 |
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; | ||||
/** | /** | ||||
/** @var CappedMemoryCache */ | /** @var CappedMemoryCache */ | ||||
private $cache; | private $cache; | ||||
/** @var EventDispatcher */ | |||||
/** @var EventDispatcherInterface */ | |||||
private $eventDispatcher; | private $eventDispatcher; | ||||
/** @var IDBConnection */ | /** @var IDBConnection */ | ||||
/** | /** | ||||
* \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') { |
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 | ||||
* @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; | ||||
} | } |
<?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 { | |||||
} |
<?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; | |||||
} |
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 | ||||
* | * | ||||
* | * | ||||
* 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; | |||||
use Symfony\Component\EventDispatcher\Event; | |||||
namespace OCP\EventDispatcher; | |||||
interface IListener { | |||||
/** | |||||
* @since 17.0.0 | |||||
*/ | |||||
interface IEventListener { | |||||
public function handle(Event $event); | |||||
/** | |||||
* @param Event $event | |||||
* | |||||
* @since 17.0.0 | |||||
*/ | |||||
public function handle(Event $event): void; | |||||
} | } |
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; | ||||
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; | ||||
->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(); |
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; | ||||
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; | ||||
/** | /** | ||||
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; | ||||
$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); |