Skip to content

Commit b76b0bb

Browse files
Merge pull request #39485 from nextcloud/bugfix/noid/move-remaining-easy-usages-to-IEventDispatcher
fix(dispatcher): Move remaining simple cases in apps/ folder to IEven…
2 parents 19e7704 + 77bc6c3 commit b76b0bb

10 files changed

Lines changed: 30 additions & 48 deletions

File tree

apps/dav/lib/RootCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function __construct() {
132132
\OC::$server->getSystemTagObjectMapper(),
133133
\OC::$server->getUserSession(),
134134
$groupManager,
135-
\OC::$server->getEventDispatcher()
135+
$dispatcher
136136
);
137137
$systemTagInUseCollection = \OCP\Server::get(SystemTag\SystemTagsInUseCollection::class);
138138
$commentsCollection = new Comments\RootCollection(

apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,22 @@
2626
*/
2727
namespace OCA\DAV\SystemTag;
2828

29+
use OCP\EventDispatcher\IEventDispatcher;
2930
use OCP\IGroupManager;
3031
use OCP\IUserSession;
3132
use OCP\SystemTag\ISystemTagManager;
3233
use OCP\SystemTag\ISystemTagObjectMapper;
3334
use OCP\SystemTag\SystemTagsEntityEvent;
3435
use Sabre\DAV\Exception\Forbidden;
3536
use Sabre\DAV\SimpleCollection;
36-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
3737

3838
class SystemTagsRelationsCollection extends SimpleCollection {
39-
40-
/**
41-
* SystemTagsRelationsCollection constructor.
42-
*
43-
* @param ISystemTagManager $tagManager
44-
* @param ISystemTagObjectMapper $tagMapper
45-
* @param IUserSession $userSession
46-
* @param IGroupManager $groupManager
47-
* @param EventDispatcherInterface $dispatcher
48-
*/
4939
public function __construct(
5040
ISystemTagManager $tagManager,
5141
ISystemTagObjectMapper $tagMapper,
5242
IUserSession $userSession,
5343
IGroupManager $groupManager,
54-
EventDispatcherInterface $dispatcher
44+
IEventDispatcher $dispatcher,
5545
) {
5646
$children = [
5747
new SystemTagsObjectTypeCollection(
@@ -67,8 +57,9 @@ function ($name) {
6757
),
6858
];
6959

70-
$event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY);
60+
$event = new SystemTagsEntityEvent();
7161
$dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event);
62+
$dispatcher->dispatchTyped($event);
7263

7364
foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
7465
$children[] = new SystemTagsObjectTypeCollection(

apps/files/lib/Collaboration/Resources/Listener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
*/
2626
namespace OCA\Files\Collaboration\Resources;
2727

28+
use OCP\EventDispatcher\IEventDispatcher;
2829
use OCP\Server;
2930
use OCP\Collaboration\Resources\IManager;
30-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
3131

3232
class Listener {
33-
public static function register(EventDispatcherInterface $dispatcher): void {
33+
public static function register(IEventDispatcher $dispatcher): void {
3434
$dispatcher->addListener('OCP\Share::postShare', [self::class, 'shareModification']);
3535
$dispatcher->addListener('OCP\Share::postUnshare', [self::class, 'shareModification']);
3636
$dispatcher->addListener('OCP\Share::postUnshareFromSelf', [self::class, 'shareModification']);

apps/files/tests/Controller/ViewControllerTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
use OCP\IUserSession;
5353
use OCP\Share\IManager;
5454
use OCP\Template;
55-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
5655
use Test\TestCase;
5756

5857
/**
@@ -69,7 +68,7 @@ class ViewControllerTest extends TestCase {
6968
private $l10n;
7069
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
7170
private $config;
72-
/** @var EventDispatcherInterface */
71+
/** @var IEventDispatcher */
7372
private $eventDispatcher;
7473
/** @var ViewController|\PHPUnit\Framework\MockObject\MockObject */
7574
private $viewController;

apps/files_external/tests/Controller/StoragesControllerTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
use OCA\Files_External\Lib\StorageConfig;
3535
use OCA\Files_External\NotFoundException;
3636
use OCA\Files_External\Service\GlobalStoragesService;
37+
use OCA\Files_External\Service\UserStoragesService;
3738
use OCP\AppFramework\Http;
39+
use PHPUnit\Framework\MockObject\MockObject;
3840

3941
abstract class StoragesControllerTest extends \Test\TestCase {
4042

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

4648
/**
47-
* @var GlobalStoragesService
49+
* @var GlobalStoragesService|UserStoragesService|MockObject
4850
*/
4951
protected $service;
5052

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

5961
/**
60-
* @return \OCA\Files_External\Lib\Backend\Backend
62+
* @return \OCA\Files_External\Lib\Backend\Backend|MockObject
6163
*/
6264
protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB', $storageClass = '\OCA\Files_External\Lib\Storage\SMB') {
6365
$backend = $this->getMockBuilder(Backend::class)
@@ -73,7 +75,7 @@ protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB'
7375
}
7476

7577
/**
76-
* @return \OCA\Files_External\Lib\Auth\AuthMechanism
78+
* @return \OCA\Files_External\Lib\Auth\AuthMechanism|MockObject
7779
*/
7880
protected function getAuthMechMock($scheme = 'null', $class = '\OCA\Files_External\Lib\Auth\NullMechanism') {
7981
$authMech = $this->getMockBuilder(AuthMechanism::class)

apps/files_sharing/lib/AppInfo/Application.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
use OCA\Files_Sharing\Notification\Notifier;
5252
use OCA\Files\Event\LoadAdditionalScriptsEvent;
5353
use OCA\Files\Event\LoadSidebar;
54-
use OCP\Files\Event\BeforeDirectGetEvent;
5554
use OCA\Files_Sharing\ShareBackend\File;
5655
use OCA\Files_Sharing\ShareBackend\Folder;
5756
use OCA\Files_Sharing\ViewOnly;
@@ -61,7 +60,6 @@
6160
use OCP\AppFramework\Bootstrap\IRegistrationContext;
6261
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
6362
use OCP\EventDispatcher\IEventDispatcher;
64-
use OCP\EventDispatcher\GenericEvent;
6563
use OCP\Federation\ICloudIdManager;
6664
use OCP\Files\Config\IMountProviderCollection;
6765
use OCP\Files\Events\BeforeDirectFileDownloadEvent;
@@ -72,13 +70,10 @@
7270
use OCP\IDBConnection;
7371
use OCP\IGroup;
7472
use OCP\IUserSession;
75-
use OCP\L10N\IFactory;
7673
use OCP\Share\Events\ShareCreatedEvent;
77-
use OCP\Share\IManager;
7874
use OCP\User\Events\UserChangedEvent;
7975
use OCP\Util;
8076
use Psr\Container\ContainerInterface;
81-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
8277
use Symfony\Component\EventDispatcher\GenericEvent as OldGenericEvent;
8378

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

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

150145
// notifications api to accept incoming user shares
151-
$oldDispatcher->addListener('OCP\Share::postShare', function (OldGenericEvent $event) {
146+
$dispatcher->addListener('OCP\Share::postShare', function ($event) {
147+
if (!$event instanceof OldGenericEvent) {
148+
return;
149+
}
152150
/** @var Listener $listener */
153151
$listener = $this->getContainer()->query(Listener::class);
154152
$listener->shareNotification($event);
155153
});
156-
$oldDispatcher->addListener(IGroup::class . '::postAddUser', function (OldGenericEvent $event) {
154+
$dispatcher->addListener(IGroup::class . '::postAddUser', function ($event) {
155+
if (!$event instanceof OldGenericEvent) {
156+
return;
157+
}
157158
/** @var Listener $listener */
158159
$listener = $this->getContainer()->query(Listener::class);
159160
$listener->userAddedToGroup($event);

apps/files_sharing/tests/ApplicationTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,11 @@
2525
use OCP\Files\Events\BeforeDirectFileDownloadEvent;
2626
use OCP\Files\Events\BeforeZipCreatedEvent;
2727
use Psr\Log\LoggerInterface;
28-
use OC\Share20\LegacyHooks;
2928
use OC\Share20\Manager;
3029
use OC\EventDispatcher\EventDispatcher;
3130
use OCA\Files_Sharing\AppInfo\Application;
3231
use OCA\Files_Sharing\SharedStorage;
33-
use OCP\Constants;
34-
use OCP\EventDispatcher\GenericEvent;
3532
use OCP\EventDispatcher\IEventDispatcher;
36-
use OCP\Files\Cache\ICacheEntry;
37-
use OCP\Files\Event\BeforeDirectGetEvent;
3833
use OCP\Files\File;
3934
use OCP\Files\Folder;
4035
use OCP\Files\IRootFolder;
@@ -57,7 +52,8 @@ class ApplicationTest extends TestCase {
5752
/** @var IRootFolder */
5853
private $rootFolder;
5954

60-
/** @var Manager */ private $manager;
55+
/** @var Manager */
56+
private $manager;
6157

6258
protected function setUp(): void {
6359
parent::setUp();

apps/user_ldap/lib/AppInfo/Application.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
use OCP\Share\IManager as IShareManager;
6060
use Psr\Container\ContainerInterface;
6161
use Psr\Log\LoggerInterface;
62-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
6362

6463
class Application extends App implements IBootstrap {
6564
public function __construct() {
@@ -120,7 +119,6 @@ public function boot(IBootContext $context): void {
120119
$context->injectFn(function (
121120
INotificationManager $notificationManager,
122121
IAppContainer $appContainer,
123-
EventDispatcherInterface $legacyDispatcher,
124122
IEventDispatcher $dispatcher,
125123
IGroupManager $groupManager,
126124
User_Proxy $userBackend,
@@ -136,7 +134,7 @@ public function boot(IBootContext $context): void {
136134
$groupManager->addBackend($groupBackend);
137135

138136
$userBackendRegisteredEvent = new UserBackendRegistered($userBackend, $userPluginManager);
139-
$legacyDispatcher->dispatch('OCA\\User_LDAP\\User\\User::postLDAPBackendAdded', $userBackendRegisteredEvent);
137+
$dispatcher->dispatch('OCA\\User_LDAP\\User\\User::postLDAPBackendAdded', $userBackendRegisteredEvent);
140138
$dispatcher->dispatchTyped($userBackendRegisteredEvent);
141139
$groupBackendRegisteredEvent = new GroupBackendRegistered($groupBackend, $groupPluginManager);
142140
$dispatcher->dispatchTyped($groupBackendRegisteredEvent);
@@ -153,7 +151,7 @@ public function boot(IBootContext $context): void {
153151
);
154152
}
155153

156-
private function registerBackendDependents(IAppContainer $appContainer, EventDispatcherInterface $dispatcher) {
154+
private function registerBackendDependents(IAppContainer $appContainer, IEventDispatcher $dispatcher) {
157155
$dispatcher->addListener(
158156
'OCA\\Files_External::loadAdditionalBackends',
159157
function () use ($appContainer) {

apps/workflowengine/tests/ManagerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
use OCP\WorkflowEngine\IManager;
5353
use OCP\WorkflowEngine\IOperation;
5454
use PHPUnit\Framework\MockObject\MockObject;
55-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
5655
use Test\TestCase;
5756

5857
/**

lib/public/SystemTag/SystemTagsEntityEvent.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,22 @@
3333
* Class SystemTagsEntityEvent
3434
*
3535
* @since 9.1.0
36+
* @since 28.0.0 Dispatched as a typed event
3637
*/
3738
class SystemTagsEntityEvent extends Event {
3839
/**
39-
* @deprecated 22.0.0
40+
* @deprecated 22.0.0 Listen to the typed event instead
4041
*/
4142
public const EVENT_ENTITY = 'OCP\SystemTag\ISystemTagManager::registerEntity';
4243

43-
/** @var string */
44-
protected $event;
4544
/** @var \Closure[] */
4645
protected $collections;
4746

4847
/**
49-
* SystemTagsEntityEvent constructor.
50-
*
51-
* @param string $event
5248
* @since 9.1.0
5349
*/
54-
public function __construct(string $event) {
55-
$this->event = $event;
50+
public function __construct() {
51+
parent::__construct();
5652
$this->collections = [];
5753
}
5854

0 commit comments

Comments
 (0)