Skip to content

Commit

Permalink
Merge pull request #39485 from nextcloud/bugfix/noid/move-remaining-e…
Browse files Browse the repository at this point in the history
…asy-usages-to-IEventDispatcher

fix(dispatcher): Move remaining simple cases in apps/ folder to IEven…
  • Loading branch information
nickvergessen authored Jul 26, 2023
2 parents 19e7704 + 77bc6c3 commit b76b0bb
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 48 deletions.
2 changes: 1 addition & 1 deletion apps/dav/lib/RootCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function __construct() {
\OC::$server->getSystemTagObjectMapper(),
\OC::$server->getUserSession(),
$groupManager,
\OC::$server->getEventDispatcher()
$dispatcher
);
$systemTagInUseCollection = \OCP\Server::get(SystemTag\SystemTagsInUseCollection::class);
$commentsCollection = new Comments\RootCollection(
Expand Down
17 changes: 4 additions & 13 deletions apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,22 @@
*/
namespace OCA\DAV\SystemTag;

use OCP\EventDispatcher\IEventDispatcher;
use OCP\IGroupManager;
use OCP\IUserSession;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
use OCP\SystemTag\SystemTagsEntityEvent;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\SimpleCollection;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class SystemTagsRelationsCollection extends SimpleCollection {

/**
* SystemTagsRelationsCollection constructor.
*
* @param ISystemTagManager $tagManager
* @param ISystemTagObjectMapper $tagMapper
* @param IUserSession $userSession
* @param IGroupManager $groupManager
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(
ISystemTagManager $tagManager,
ISystemTagObjectMapper $tagMapper,
IUserSession $userSession,
IGroupManager $groupManager,
EventDispatcherInterface $dispatcher
IEventDispatcher $dispatcher,
) {
$children = [
new SystemTagsObjectTypeCollection(
Expand All @@ -67,8 +57,9 @@ function ($name) {
),
];

$event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY);
$event = new SystemTagsEntityEvent();
$dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event);
$dispatcher->dispatchTyped($event);

foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
$children[] = new SystemTagsObjectTypeCollection(
Expand Down
4 changes: 2 additions & 2 deletions apps/files/lib/Collaboration/Resources/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
*/
namespace OCA\Files\Collaboration\Resources;

use OCP\EventDispatcher\IEventDispatcher;
use OCP\Server;
use OCP\Collaboration\Resources\IManager;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class Listener {
public static function register(EventDispatcherInterface $dispatcher): void {
public static function register(IEventDispatcher $dispatcher): void {
$dispatcher->addListener('OCP\Share::postShare', [self::class, 'shareModification']);
$dispatcher->addListener('OCP\Share::postUnshare', [self::class, 'shareModification']);
$dispatcher->addListener('OCP\Share::postUnshareFromSelf', [self::class, 'shareModification']);
Expand Down
3 changes: 1 addition & 2 deletions apps/files/tests/Controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
use OCP\IUserSession;
use OCP\Share\IManager;
use OCP\Template;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;

/**
Expand All @@ -69,7 +68,7 @@ class ViewControllerTest extends TestCase {
private $l10n;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
private $config;
/** @var EventDispatcherInterface */
/** @var IEventDispatcher */
private $eventDispatcher;
/** @var ViewController|\PHPUnit\Framework\MockObject\MockObject */
private $viewController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\NotFoundException;
use OCA\Files_External\Service\GlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
use OCP\AppFramework\Http;
use PHPUnit\Framework\MockObject\MockObject;

abstract class StoragesControllerTest extends \Test\TestCase {

Expand All @@ -44,7 +46,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
protected $controller;

/**
* @var GlobalStoragesService
* @var GlobalStoragesService|UserStoragesService|MockObject
*/
protected $service;

Expand All @@ -57,7 +59,7 @@ protected function tearDown(): void {
}

/**
* @return \OCA\Files_External\Lib\Backend\Backend
* @return \OCA\Files_External\Lib\Backend\Backend|MockObject
*/
protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB', $storageClass = '\OCA\Files_External\Lib\Storage\SMB') {
$backend = $this->getMockBuilder(Backend::class)
Expand All @@ -73,7 +75,7 @@ protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB'
}

/**
* @return \OCA\Files_External\Lib\Auth\AuthMechanism
* @return \OCA\Files_External\Lib\Auth\AuthMechanism|MockObject
*/
protected function getAuthMechMock($scheme = 'null', $class = '\OCA\Files_External\Lib\Auth\NullMechanism') {
$authMech = $this->getMockBuilder(AuthMechanism::class)
Expand Down
17 changes: 9 additions & 8 deletions apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
use OCA\Files_Sharing\Notification\Notifier;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files\Event\LoadSidebar;
use OCP\Files\Event\BeforeDirectGetEvent;
use OCA\Files_Sharing\ShareBackend\File;
use OCA\Files_Sharing\ShareBackend\Folder;
use OCA\Files_Sharing\ViewOnly;
Expand All @@ -61,7 +60,6 @@
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\EventDispatcher\GenericEvent;
use OCP\Federation\ICloudIdManager;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Events\BeforeDirectFileDownloadEvent;
Expand All @@ -72,13 +70,10 @@
use OCP\IDBConnection;
use OCP\IGroup;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Share\IManager;
use OCP\User\Events\UserChangedEvent;
use OCP\Util;
use Psr\Container\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent as OldGenericEvent;

class Application extends App implements IBootstrap {
Expand Down Expand Up @@ -135,7 +130,7 @@ public function registerMountProviders(IMountProviderCollection $mountProviderCo
$mountProviderCollection->registerProvider($externalMountProvider);
}

public function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher): void {
public function registerEventsScripts(IEventDispatcher $dispatcher): void {
// sidebar and files scripts
$dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
$dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class);
Expand All @@ -148,12 +143,18 @@ public function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatc
});

// notifications api to accept incoming user shares
$oldDispatcher->addListener('OCP\Share::postShare', function (OldGenericEvent $event) {
$dispatcher->addListener('OCP\Share::postShare', function ($event) {
if (!$event instanceof OldGenericEvent) {
return;
}
/** @var Listener $listener */
$listener = $this->getContainer()->query(Listener::class);
$listener->shareNotification($event);
});
$oldDispatcher->addListener(IGroup::class . '::postAddUser', function (OldGenericEvent $event) {
$dispatcher->addListener(IGroup::class . '::postAddUser', function ($event) {
if (!$event instanceof OldGenericEvent) {
return;
}
/** @var Listener $listener */
$listener = $this->getContainer()->query(Listener::class);
$listener->userAddedToGroup($event);
Expand Down
8 changes: 2 additions & 6 deletions apps/files_sharing/tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,11 @@
use OCP\Files\Events\BeforeDirectFileDownloadEvent;
use OCP\Files\Events\BeforeZipCreatedEvent;
use Psr\Log\LoggerInterface;
use OC\Share20\LegacyHooks;
use OC\Share20\Manager;
use OC\EventDispatcher\EventDispatcher;
use OCA\Files_Sharing\AppInfo\Application;
use OCA\Files_Sharing\SharedStorage;
use OCP\Constants;
use OCP\EventDispatcher\GenericEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Event\BeforeDirectGetEvent;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
Expand All @@ -57,7 +52,8 @@ class ApplicationTest extends TestCase {
/** @var IRootFolder */
private $rootFolder;

/** @var Manager */ private $manager;
/** @var Manager */
private $manager;

protected function setUp(): void {
parent::setUp();
Expand Down
6 changes: 2 additions & 4 deletions apps/user_ldap/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
use OCP\Share\IManager as IShareManager;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class Application extends App implements IBootstrap {
public function __construct() {
Expand Down Expand Up @@ -120,7 +119,6 @@ public function boot(IBootContext $context): void {
$context->injectFn(function (
INotificationManager $notificationManager,
IAppContainer $appContainer,
EventDispatcherInterface $legacyDispatcher,
IEventDispatcher $dispatcher,
IGroupManager $groupManager,
User_Proxy $userBackend,
Expand All @@ -136,7 +134,7 @@ public function boot(IBootContext $context): void {
$groupManager->addBackend($groupBackend);

$userBackendRegisteredEvent = new UserBackendRegistered($userBackend, $userPluginManager);
$legacyDispatcher->dispatch('OCA\\User_LDAP\\User\\User::postLDAPBackendAdded', $userBackendRegisteredEvent);
$dispatcher->dispatch('OCA\\User_LDAP\\User\\User::postLDAPBackendAdded', $userBackendRegisteredEvent);
$dispatcher->dispatchTyped($userBackendRegisteredEvent);
$groupBackendRegisteredEvent = new GroupBackendRegistered($groupBackend, $groupPluginManager);
$dispatcher->dispatchTyped($groupBackendRegisteredEvent);
Expand All @@ -153,7 +151,7 @@ public function boot(IBootContext $context): void {
);
}

private function registerBackendDependents(IAppContainer $appContainer, EventDispatcherInterface $dispatcher) {
private function registerBackendDependents(IAppContainer $appContainer, IEventDispatcher $dispatcher) {
$dispatcher->addListener(
'OCA\\Files_External::loadAdditionalBackends',
function () use ($appContainer) {
Expand Down
1 change: 0 additions & 1 deletion apps/workflowengine/tests/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
use OCP\WorkflowEngine\IManager;
use OCP\WorkflowEngine\IOperation;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;

/**
Expand Down
12 changes: 4 additions & 8 deletions lib/public/SystemTag/SystemTagsEntityEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,22 @@
* Class SystemTagsEntityEvent
*
* @since 9.1.0
* @since 28.0.0 Dispatched as a typed event
*/
class SystemTagsEntityEvent extends Event {
/**
* @deprecated 22.0.0
* @deprecated 22.0.0 Listen to the typed event instead
*/
public const EVENT_ENTITY = 'OCP\SystemTag\ISystemTagManager::registerEntity';

/** @var string */
protected $event;
/** @var \Closure[] */
protected $collections;

/**
* SystemTagsEntityEvent constructor.
*
* @param string $event
* @since 9.1.0
*/
public function __construct(string $event) {
$this->event = $event;
public function __construct() {
parent::__construct();
$this->collections = [];
}

Expand Down

0 comments on commit b76b0bb

Please sign in to comment.