diff --git a/apps/dav/lib/Connector/Sabre/Auth.php b/apps/dav/lib/Connector/Sabre/Auth.php index 69e3946bb1152..75e3f61fded65 100644 --- a/apps/dav/lib/Connector/Sabre/Auth.php +++ b/apps/dav/lib/Connector/Sabre/Auth.php @@ -37,7 +37,6 @@ use OC\Authentication\Exceptions\PasswordLoginForbiddenException; use OC\Authentication\TwoFactorAuth\Manager; use OC\Security\Bruteforce\Throttler; -use OC\User\LoginException; use OC\User\Session; use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden; use OCA\DAV\Connector\Sabre\Exception\TooManyRequests; diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index b881d37440e9f..88044fbf7b6f5 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -59,7 +59,6 @@ use OCP\IUserSession; use OCP\Settings\IManager as ISettingsManager; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; class AppManager implements IAppManager { /** @@ -79,7 +78,6 @@ class AppManager implements IAppManager { private AppConfig $appConfig; private IGroupManager $groupManager; private ICacheFactory $memCacheFactory; - private EventDispatcherInterface $legacyDispatcher; private IEventDispatcher $dispatcher; private LoggerInterface $logger; @@ -110,7 +108,6 @@ public function __construct(IUserSession $userSession, AppConfig $appConfig, IGroupManager $groupManager, ICacheFactory $memCacheFactory, - EventDispatcherInterface $legacyDispatcher, IEventDispatcher $dispatcher, LoggerInterface $logger) { $this->userSession = $userSession; @@ -118,7 +115,6 @@ public function __construct(IUserSession $userSession, $this->appConfig = $appConfig; $this->groupManager = $groupManager; $this->memCacheFactory = $memCacheFactory; - $this->legacyDispatcher = $legacyDispatcher; $this->dispatcher = $dispatcher; $this->logger = $logger; } @@ -543,7 +539,7 @@ public function enableApp(string $appId, bool $forceEnable = false): void { $this->installedAppsCache[$appId] = 'yes'; $this->appConfig->setValue($appId, 'enabled', 'yes'); $this->dispatcher->dispatchTyped(new AppEnableEvent($appId)); - $this->legacyDispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent( + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent( ManagerEvent::EVENT_APP_ENABLE, $appId )); $this->clearAppsCache(); @@ -597,7 +593,7 @@ public function enableAppForGroups(string $appId, array $groups, bool $forceEnab $this->installedAppsCache[$appId] = json_encode($groupIds); $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds)); $this->dispatcher->dispatchTyped(new AppEnableEvent($appId, $groupIds)); - $this->legacyDispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent( + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent( ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups )); $this->clearAppsCache(); @@ -633,7 +629,7 @@ public function disableApp($appId, $automaticDisabled = false) { } $this->dispatcher->dispatchTyped(new AppDisableEvent($appId)); - $this->legacyDispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent( + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent( ManagerEvent::EVENT_APP_DISABLE, $appId )); $this->clearAppsCache(); diff --git a/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php b/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php index ec52dde0ecd26..f3f9b07f2a87a 100644 --- a/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php +++ b/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php @@ -32,44 +32,19 @@ use OCP\AppFramework\Http\StandaloneTemplateResponse; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Middleware; -use OCP\AppFramework\PublicShareController; -use OCP\EventDispatcher\GenericEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\IUserSession; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; class AdditionalScriptsMiddleware extends Middleware { - /** @var EventDispatcherInterface */ - private $legacyDispatcher; - /** @var IUserSession */ - private $userSession; - /** @var IEventDispatcher */ - private $dispatcher; - - public function __construct(EventDispatcherInterface $legacyDispatcher, IUserSession $userSession, IEventDispatcher $dispatcher) { - $this->legacyDispatcher = $legacyDispatcher; - $this->userSession = $userSession; - $this->dispatcher = $dispatcher; + public function __construct( + private IUserSession $userSession, + private IEventDispatcher $dispatcher, + ) { } public function afterController($controller, $methodName, Response $response): Response { if ($response instanceof TemplateResponse) { - if (!$controller instanceof PublicShareController) { - /* - * The old event was not dispatched on the public share controller as there was - * OCA\Files_Sharing::loadAdditionalScripts for that. This is kept for compatibility reasons - * only for the old event as this is now also included in BeforeTemplateRenderedEvent - */ - $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, new GenericEvent()); - } - - if (!($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn()) { - $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, new GenericEvent()); - $isLoggedIn = true; - } else { - $isLoggedIn = false; - } - + $isLoggedIn = !($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn(); $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response)); } diff --git a/lib/private/Authentication/TwoFactorAuth/Manager.php b/lib/private/Authentication/TwoFactorAuth/Manager.php index 17937de4e44eb..8ae08ca65ae25 100644 --- a/lib/private/Authentication/TwoFactorAuth/Manager.php +++ b/lib/private/Authentication/TwoFactorAuth/Manager.php @@ -46,8 +46,6 @@ use OCP\IUser; use OCP\Session\Exceptions\SessionNotAvailableException; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\GenericEvent; use function array_diff; use function array_filter; @@ -87,9 +85,6 @@ class Manager { /** @var IEventDispatcher */ private $dispatcher; - /** @var EventDispatcherInterface */ - private $legacyDispatcher; - /** @psalm-var array */ private $userIsTwoFactorAuthenticated = []; @@ -102,8 +97,7 @@ public function __construct(ProviderLoader $providerLoader, LoggerInterface $logger, TokenProvider $tokenProvider, ITimeFactory $timeFactory, - IEventDispatcher $eventDispatcher, - EventDispatcherInterface $legacyDispatcher) { + IEventDispatcher $eventDispatcher) { $this->providerLoader = $providerLoader; $this->providerRegistry = $providerRegistry; $this->mandatoryTwoFactor = $mandatoryTwoFactor; @@ -114,7 +108,6 @@ public function __construct(ProviderLoader $providerLoader, $this->tokenProvider = $tokenProvider; $this->timeFactory = $timeFactory; $this->dispatcher = $eventDispatcher; - $this->legacyDispatcher = $legacyDispatcher; } /** @@ -284,9 +277,6 @@ public function verifyChallenge(string $providerId, IUser $user, string $challen $tokenId = $token->getId(); $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', (string)$tokenId); - $dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]); - $this->legacyDispatcher->dispatch(IProvider::EVENT_SUCCESS, $dispatchEvent); - $this->dispatcher->dispatchTyped(new TwoFactorProviderForUserEnabled($user, $provider)); $this->dispatcher->dispatchTyped(new TwoFactorProviderChallengePassed($user, $provider)); @@ -294,9 +284,6 @@ public function verifyChallenge(string $providerId, IUser $user, string $challen 'provider' => $provider->getDisplayName(), ]); } else { - $dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]); - $this->legacyDispatcher->dispatch(IProvider::EVENT_FAILED, $dispatchEvent); - $this->dispatcher->dispatchTyped(new TwoFactorProviderForUserDisabled($user, $provider)); $this->dispatcher->dispatchTyped(new TwoFactorProviderChallengeFailed($user, $provider)); diff --git a/lib/private/Files/Node/HookConnector.php b/lib/private/Files/Node/HookConnector.php index c61e098c22771..a8e76d95c22c4 100644 --- a/lib/private/Files/Node/HookConnector.php +++ b/lib/private/Files/Node/HookConnector.php @@ -46,7 +46,6 @@ use OCP\Files\FileInfo; use OCP\Files\IRootFolder; use OCP\Util; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; class HookConnector { /** @var IRootFolder */ @@ -58,26 +57,15 @@ class HookConnector { /** @var FileInfo[] */ private $deleteMetaCache = []; - /** @var EventDispatcherInterface */ - private $legacyDispatcher; - /** @var IEventDispatcher */ private $dispatcher; - /** - * HookConnector constructor. - * - * @param Root $root - * @param View $view - */ public function __construct( IRootFolder $root, View $view, - EventDispatcherInterface $legacyDispatcher, IEventDispatcher $dispatcher) { $this->root = $root; $this->view = $view; - $this->legacyDispatcher = $legacyDispatcher; $this->dispatcher = $dispatcher; } @@ -106,7 +94,7 @@ public function viewToNode() { public function write($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->root->emit('\OC\Files', 'preWrite', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::preWrite', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::preWrite', new GenericEvent($node)); $event = new BeforeNodeWrittenEvent($node); $this->dispatcher->dispatchTyped($event); @@ -115,7 +103,7 @@ public function write($arguments) { public function postWrite($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->root->emit('\OC\Files', 'postWrite', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::postWrite', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::postWrite', new GenericEvent($node)); $event = new NodeWrittenEvent($node); $this->dispatcher->dispatchTyped($event); @@ -124,7 +112,7 @@ public function postWrite($arguments) { public function create($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->root->emit('\OC\Files', 'preCreate', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::preCreate', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::preCreate', new GenericEvent($node)); $event = new BeforeNodeCreatedEvent($node); $this->dispatcher->dispatchTyped($event); @@ -133,7 +121,7 @@ public function create($arguments) { public function postCreate($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->root->emit('\OC\Files', 'postCreate', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::postCreate', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::postCreate', new GenericEvent($node)); $event = new NodeCreatedEvent($node); $this->dispatcher->dispatchTyped($event); @@ -143,7 +131,7 @@ public function delete($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->deleteMetaCache[$node->getPath()] = $node->getFileInfo(); $this->root->emit('\OC\Files', 'preDelete', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::preDelete', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::preDelete', new GenericEvent($node)); $event = new BeforeNodeDeletedEvent($node); $this->dispatcher->dispatchTyped($event); @@ -153,7 +141,7 @@ public function postDelete($arguments) { $node = $this->getNodeForPath($arguments['path']); unset($this->deleteMetaCache[$node->getPath()]); $this->root->emit('\OC\Files', 'postDelete', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::postDelete', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::postDelete', new GenericEvent($node)); $event = new NodeDeletedEvent($node); $this->dispatcher->dispatchTyped($event); @@ -162,7 +150,7 @@ public function postDelete($arguments) { public function touch($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->root->emit('\OC\Files', 'preTouch', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::preTouch', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::preTouch', new GenericEvent($node)); $event = new BeforeNodeTouchedEvent($node); $this->dispatcher->dispatchTyped($event); @@ -171,7 +159,7 @@ public function touch($arguments) { public function postTouch($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->root->emit('\OC\Files', 'postTouch', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::postTouch', new GenericEvent($node)); + $this->dispatcher->dispatch('\OCP\Files::postTouch', new GenericEvent($node)); $event = new NodeTouchedEvent($node); $this->dispatcher->dispatchTyped($event); @@ -181,7 +169,7 @@ public function rename($arguments) { $source = $this->getNodeForPath($arguments['oldpath']); $target = $this->getNodeForPath($arguments['newpath']); $this->root->emit('\OC\Files', 'preRename', [$source, $target]); - $this->legacyDispatcher->dispatch('\OCP\Files::preRename', new GenericEvent([$source, $target])); + $this->dispatcher->dispatch('\OCP\Files::preRename', new GenericEvent([$source, $target])); $event = new BeforeNodeRenamedEvent($source, $target); $this->dispatcher->dispatchTyped($event); @@ -191,7 +179,7 @@ public function postRename($arguments) { $source = $this->getNodeForPath($arguments['oldpath']); $target = $this->getNodeForPath($arguments['newpath']); $this->root->emit('\OC\Files', 'postRename', [$source, $target]); - $this->legacyDispatcher->dispatch('\OCP\Files::postRename', new GenericEvent([$source, $target])); + $this->dispatcher->dispatch('\OCP\Files::postRename', new GenericEvent([$source, $target])); $event = new NodeRenamedEvent($source, $target); $this->dispatcher->dispatchTyped($event); @@ -201,7 +189,7 @@ public function copy($arguments) { $source = $this->getNodeForPath($arguments['oldpath']); $target = $this->getNodeForPath($arguments['newpath']); $this->root->emit('\OC\Files', 'preCopy', [$source, $target]); - $this->legacyDispatcher->dispatch('\OCP\Files::preCopy', new GenericEvent([$source, $target])); + $this->dispatcher->dispatch('\OCP\Files::preCopy', new GenericEvent([$source, $target])); $event = new BeforeNodeCopiedEvent($source, $target); $this->dispatcher->dispatchTyped($event); @@ -211,7 +199,7 @@ public function postCopy($arguments) { $source = $this->getNodeForPath($arguments['oldpath']); $target = $this->getNodeForPath($arguments['newpath']); $this->root->emit('\OC\Files', 'postCopy', [$source, $target]); - $this->legacyDispatcher->dispatch('\OCP\Files::postCopy', new GenericEvent([$source, $target])); + $this->dispatcher->dispatch('\OCP\Files::postCopy', new GenericEvent([$source, $target])); $event = new NodeCopiedEvent($source, $target); $this->dispatcher->dispatchTyped($event); @@ -220,7 +208,7 @@ public function postCopy($arguments) { public function read($arguments) { $node = $this->getNodeForPath($arguments['path']); $this->root->emit('\OC\Files', 'read', [$node]); - $this->legacyDispatcher->dispatch('\OCP\Files::read', new GenericEvent([$node])); + $this->dispatcher->dispatch('\OCP\Files::read', new GenericEvent([$node])); $event = new BeforeNodeReadEvent($node); $this->dispatcher->dispatchTyped($event); diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index c9949c82a9767..4e4571f08570d 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -44,8 +44,6 @@ use OCP\Preview\BeforePreviewFetchedEvent; use OCP\Preview\IProviderV2; use OCP\Preview\IVersionedPreviewFile; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\GenericEvent; class Generator { public const SEMAPHORE_ID_ALL = 0x0a11; @@ -59,8 +57,6 @@ class Generator { private $appData; /** @var GeneratorHelper */ private $helper; - /** @var EventDispatcherInterface */ - private $legacyEventDispatcher; /** @var IEventDispatcher */ private $eventDispatcher; @@ -69,14 +65,12 @@ public function __construct( IPreview $previewManager, IAppData $appData, GeneratorHelper $helper, - EventDispatcherInterface $legacyEventDispatcher, IEventDispatcher $eventDispatcher ) { $this->config = $config; $this->previewManager = $previewManager; $this->appData = $appData; $this->helper = $helper; - $this->legacyEventDispatcher = $legacyEventDispatcher; $this->eventDispatcher = $eventDispatcher; } @@ -104,10 +98,6 @@ public function getPreview(File $file, $width = -1, $height = -1, $crop = false, 'mode' => $mode, ]; - $this->legacyEventDispatcher->dispatch( - IPreview::EVENT, - new GenericEvent($file, $specification) - ); $this->eventDispatcher->dispatchTyped(new BeforePreviewFetchedEvent( $file, $width, diff --git a/lib/private/PreviewManager.php b/lib/private/PreviewManager.php index 814235f421287..3af6848686ee7 100644 --- a/lib/private/PreviewManager.php +++ b/lib/private/PreviewManager.php @@ -46,7 +46,6 @@ use OCP\IPreview; use OCP\IServerContainer; use OCP\Preview\IProviderV2; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use function array_key_exists; class PreviewManager implements IPreview { @@ -54,7 +53,6 @@ class PreviewManager implements IPreview { protected IRootFolder $rootFolder; protected IAppData $appData; protected IEventDispatcher $eventDispatcher; - protected EventDispatcherInterface $legacyEventDispatcher; private ?Generator $generator = null; private GeneratorHelper $helper; protected bool $providerListDirty = false; @@ -81,7 +79,6 @@ public function __construct( IRootFolder $rootFolder, IAppData $appData, IEventDispatcher $eventDispatcher, - EventDispatcherInterface $legacyEventDispatcher, GeneratorHelper $helper, ?string $userId, Coordinator $bootstrapCoordinator, @@ -93,7 +90,6 @@ public function __construct( $this->rootFolder = $rootFolder; $this->appData = $appData; $this->eventDispatcher = $eventDispatcher; - $this->legacyEventDispatcher = $legacyEventDispatcher; $this->helper = $helper; $this->userId = $userId; $this->bootstrapCoordinator = $bootstrapCoordinator; @@ -161,7 +157,6 @@ private function getGenerator(): Generator { $this->rootFolder, $this->config ), - $this->legacyEventDispatcher, $this->eventDispatcher ); } diff --git a/lib/private/Server.php b/lib/private/Server.php index 03c03e1b6ed4a..86f5192a39df9 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -340,7 +340,6 @@ public function __construct($webRoot, \OC\Config $config) { $c->get(SystemConfig::class) ), $c->get(IEventDispatcher::class), - $c->get(SymfonyAdapter::class), $c->get(GeneratorHelper::class), $c->get(ISession::class)->get('user_id'), $c->get(Coordinator::class), @@ -466,7 +465,6 @@ public function __construct($webRoot, \OC\Config $config) { return new HookConnector( $c->get(IRootFolder::class), new View(), - $c->get(\OC\EventDispatcher\SymfonyAdapter::class), $c->get(IEventDispatcher::class) ); }); @@ -940,7 +938,6 @@ public function __construct($webRoot, \OC\Config $config) { $c->get(\OC\AppConfig::class), $c->get(IGroupManager::class), $c->get(ICacheFactory::class), - $c->get(SymfonyAdapter::class), $c->get(IEventDispatcher::class), $c->get(LoggerInterface::class) ); diff --git a/lib/private/Share20/LegacyHooks.php b/lib/private/Share20/LegacyHooks.php index feb4604e8848e..688b22733840a 100644 --- a/lib/private/Share20/LegacyHooks.php +++ b/lib/private/Share20/LegacyHooks.php @@ -26,34 +26,46 @@ */ namespace OC\Share20; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; use OCP\Share; use OCP\Share\IShare; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; class LegacyHooks { - /** @var EventDispatcherInterface */ + /** @var IEventDispatcher */ private $eventDispatcher; - /** - * LegacyHooks constructor. - * - * @param EventDispatcherInterface $eventDispatcher - */ - public function __construct(EventDispatcherInterface $eventDispatcher) { + public function __construct(IEventDispatcher $eventDispatcher) { $this->eventDispatcher = $eventDispatcher; - $this->eventDispatcher->addListener('OCP\Share::preUnshare', [$this, 'preUnshare']); - $this->eventDispatcher->addListener('OCP\Share::postUnshare', [$this, 'postUnshare']); - $this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', [$this, 'postUnshareFromSelf']); - $this->eventDispatcher->addListener('OCP\Share::preShare', [$this, 'preShare']); - $this->eventDispatcher->addListener('OCP\Share::postShare', [$this, 'postShare']); + $this->eventDispatcher->addListener('OCP\Share::preUnshare', function ($event) { + if ($event instanceof GenericEvent) { + $this->preUnshare($event); + } + }); + $this->eventDispatcher->addListener('OCP\Share::postUnshare', function ($event) { + if ($event instanceof GenericEvent) { + $this->postUnshare($event); + } + }); + $this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', function ($event) { + if ($event instanceof GenericEvent) { + $this->postUnshareFromSelf($event); + } + }); + $this->eventDispatcher->addListener('OCP\Share::preShare', function ($event) { + if ($event instanceof GenericEvent) { + $this->preShare($event); + } + }); + $this->eventDispatcher->addListener('OCP\Share::postShare', function ($event) { + if ($event instanceof GenericEvent) { + $this->postShare($event); + } + }); } - /** - * @param GenericEvent $e - */ public function preUnshare(GenericEvent $e) { /** @var IShare $share */ $share = $e->getSubject(); @@ -62,9 +74,6 @@ public function preUnshare(GenericEvent $e) { \OC_Hook::emit(Share::class, 'pre_unshare', $formatted); } - /** - * @param GenericEvent $e - */ public function postUnshare(GenericEvent $e) { /** @var IShare $share */ $share = $e->getSubject(); @@ -83,9 +92,6 @@ public function postUnshare(GenericEvent $e) { \OC_Hook::emit(Share::class, 'post_unshare', $formatted); } - /** - * @param GenericEvent $e - */ public function postUnshareFromSelf(GenericEvent $e) { /** @var IShare $share */ $share = $e->getSubject(); diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 732bd5bb97d39..3f5dbd7cd289a 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -157,7 +157,7 @@ public function __construct( $this->sharingDisabledForUsersCache = new CappedMemoryCache(); // The constructor of LegacyHooks registers the listeners of share events // do not remove if those are not properly migrated - $this->legacyHooks = new LegacyHooks($this->legacyDispatcher); + $this->legacyHooks = new LegacyHooks($dispatcher); $this->mailer = $mailer; $this->urlGenerator = $urlGenerator; $this->defaults = $defaults; @@ -194,7 +194,7 @@ protected function verifyPassword($password) { // Let others verify the password try { - $this->legacyDispatcher->dispatch(new ValidatePasswordPolicyEvent($password)); + $this->dispatcher->dispatchTyped(new ValidatePasswordPolicyEvent($password)); } catch (HintException $e) { throw new \Exception($e->getHint()); } diff --git a/lib/private/SystemTag/ManagerFactory.php b/lib/private/SystemTag/ManagerFactory.php index ca0508fe19b17..6670922407e37 100644 --- a/lib/private/SystemTag/ManagerFactory.php +++ b/lib/private/SystemTag/ManagerFactory.php @@ -26,6 +26,7 @@ */ namespace OC\SystemTag; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IServerContainer; use OCP\SystemTag\ISystemTagManager; use OCP\SystemTag\ISystemTagManagerFactory; @@ -64,7 +65,7 @@ public function getManager(): ISystemTagManager { return new SystemTagManager( $this->serverContainer->getDatabaseConnection(), $this->serverContainer->getGroupManager(), - $this->serverContainer->getEventDispatcher() + $this->serverContainer->get(IEventDispatcher::class), ); } @@ -79,7 +80,7 @@ public function getObjectMapper(): ISystemTagObjectMapper { return new SystemTagObjectMapper( $this->serverContainer->getDatabaseConnection(), $this->getManager(), - $this->serverContainer->getEventDispatcher() + $this->serverContainer->get(IEventDispatcher::class), ); } } diff --git a/lib/private/SystemTag/SystemTagManager.php b/lib/private/SystemTag/SystemTagManager.php index 1d5bc10fc2c7d..c52c350b6f810 100644 --- a/lib/private/SystemTag/SystemTagManager.php +++ b/lib/private/SystemTag/SystemTagManager.php @@ -31,6 +31,7 @@ use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IUser; @@ -39,7 +40,6 @@ use OCP\SystemTag\ManagerEvent; use OCP\SystemTag\TagAlreadyExistsException; use OCP\SystemTag\TagNotFoundException; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Manager class for system tags @@ -48,15 +48,6 @@ class SystemTagManager implements ISystemTagManager { public const TAG_TABLE = 'systemtag'; public const TAG_GROUP_TABLE = 'systemtag_group'; - /** @var IDBConnection */ - protected $connection; - - /** @var EventDispatcherInterface */ - protected $dispatcher; - - /** @var IGroupManager */ - protected $groupManager; - /** * Prepared query for selecting tags directly * @@ -64,22 +55,11 @@ class SystemTagManager implements ISystemTagManager { */ private $selectTagQuery; - /** - * Constructor. - * - * @param IDBConnection $connection database connection - * @param IGroupManager $groupManager - * @param EventDispatcherInterface $dispatcher - */ public function __construct( - IDBConnection $connection, - IGroupManager $groupManager, - EventDispatcherInterface $dispatcher + protected IDBConnection $connection, + protected IGroupManager $groupManager, + protected IEventDispatcher $dispatcher, ) { - $this->connection = $connection; - $this->groupManager = $groupManager; - $this->dispatcher = $dispatcher; - $query = $this->connection->getQueryBuilder(); $this->selectTagQuery = $query->select('*') ->from(self::TAG_TABLE) diff --git a/lib/private/SystemTag/SystemTagObjectMapper.php b/lib/private/SystemTag/SystemTagObjectMapper.php index 864ba3e91a898..66a21e5860991 100644 --- a/lib/private/SystemTag/SystemTagObjectMapper.php +++ b/lib/private/SystemTag/SystemTagObjectMapper.php @@ -29,37 +29,22 @@ use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IDBConnection; use OCP\SystemTag\ISystemTag; use OCP\SystemTag\ISystemTagManager; use OCP\SystemTag\ISystemTagObjectMapper; use OCP\SystemTag\MapperEvent; use OCP\SystemTag\TagNotFoundException; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; class SystemTagObjectMapper implements ISystemTagObjectMapper { public const RELATION_TABLE = 'systemtag_object_mapping'; - /** @var ISystemTagManager */ - protected $tagManager; - - /** @var IDBConnection */ - protected $connection; - - /** @var EventDispatcherInterface */ - protected $dispatcher; - - /** - * Constructor. - * - * @param IDBConnection $connection database connection - * @param ISystemTagManager $tagManager system tag manager - * @param EventDispatcherInterface $dispatcher - */ - public function __construct(IDBConnection $connection, ISystemTagManager $tagManager, EventDispatcherInterface $dispatcher) { - $this->connection = $connection; - $this->tagManager = $tagManager; - $this->dispatcher = $dispatcher; + public function __construct( + protected IDBConnection $connection, + protected ISystemTagManager $tagManager, + protected IEventDispatcher $dispatcher, + ) { } /** diff --git a/lib/private/User/User.php b/lib/private/User/User.php index dc4cdec1235b0..2530173bea444 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -271,8 +271,6 @@ public function updateLastLoginTimestamp() { * @return bool */ public function delete() { - /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ - $this->legacyDispatcher->dispatch(IUser::class . '::preDelete', new GenericEvent($this)); if ($this->emitter) { /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ $this->emitter->emit('\OC\User', 'preDelete', [$this]); @@ -310,8 +308,6 @@ public function delete() { $accountManager = \OCP\Server::get(AccountManager::class); $accountManager->deleteUser($this); - /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ - $this->legacyDispatcher->dispatch(IUser::class . '::postDelete', new GenericEvent($this)); if ($this->emitter) { /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ $this->emitter->emit('\OC\User', 'postDelete', [$this]); diff --git a/lib/public/AppFramework/Http/TemplateResponse.php b/lib/public/AppFramework/Http/TemplateResponse.php index 0364ba10e505b..627906fcc203e 100644 --- a/lib/public/AppFramework/Http/TemplateResponse.php +++ b/lib/public/AppFramework/Http/TemplateResponse.php @@ -65,15 +65,6 @@ class TemplateResponse extends Response { */ public const RENDER_AS_PUBLIC = 'public'; - /** - * @deprecated 20.0.0 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent - */ - public const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts'; - /** - * @deprecated 20.0.0 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent - */ - public const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class . '::loadAdditionalScriptsLoggedIn'; - /** * name of the template * @var string diff --git a/lib/public/Authentication/TwoFactorAuth/IProvider.php b/lib/public/Authentication/TwoFactorAuth/IProvider.php index 09fa7a56f5ce9..7cb6c83bdf645 100644 --- a/lib/public/Authentication/TwoFactorAuth/IProvider.php +++ b/lib/public/Authentication/TwoFactorAuth/IProvider.php @@ -32,17 +32,6 @@ * @since 9.1.0 */ interface IProvider { - /** - * @since 14.0.0 - * @deprecated 22.0.0 - */ - public const EVENT_SUCCESS = self::class . '::success'; - - /** - * @deprecated 22.0.0 - */ - public const EVENT_FAILED = self::class . '::failed'; - /** * Get unique identifier of this 2FA provider * diff --git a/lib/public/IPreview.php b/lib/public/IPreview.php index 8483587d60e33..2758eba8d63ce 100644 --- a/lib/public/IPreview.php +++ b/lib/public/IPreview.php @@ -38,12 +38,6 @@ * @since 6.0.0 */ interface IPreview { - /** - * @since 9.2.0 - * @deprecated 22.0.0 - */ - public const EVENT = self::class . ':' . 'PreviewRequested'; - public const MODE_FILL = 'fill'; public const MODE_COVER = 'cover'; diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php index d597b21604111..4717da008a49e 100644 --- a/tests/lib/App/AppManagerTest.php +++ b/tests/lib/App/AppManagerTest.php @@ -27,7 +27,6 @@ use OCP\IUserSession; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; /** @@ -93,9 +92,6 @@ protected function getAppConfig() { /** @var ICacheFactory|MockObject */ protected $cacheFactory; - /** @var EventDispatcherInterface|MockObject */ - protected $legacyEventDispatcher; - /** @var IEventDispatcher|MockObject */ protected $eventDispatcher; @@ -114,7 +110,6 @@ protected function setUp(): void { $this->appConfig = $this->getAppConfig(); $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->cache = $this->createMock(ICache::class); - $this->legacyEventDispatcher = $this->createMock(EventDispatcherInterface::class); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $this->logger = $this->createMock(LoggerInterface::class); $this->cacheFactory->expects($this->any()) @@ -127,7 +122,6 @@ protected function setUp(): void { $this->appConfig, $this->groupManager, $this->cacheFactory, - $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger ); @@ -176,7 +170,7 @@ public function testEnableAppForGroups() { /** @var AppManager|MockObject $manager */ $manager = $this->getMockBuilder(AppManager::class) ->setConstructorArgs([ - $this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger + $this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger ]) ->setMethods([ 'getAppPath', @@ -224,7 +218,7 @@ public function testEnableAppForGroupsAllowedTypes(array $appInfo) { /** @var AppManager|MockObject $manager */ $manager = $this->getMockBuilder(AppManager::class) ->setConstructorArgs([ - $this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger + $this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger ]) ->setMethods([ 'getAppPath', @@ -280,7 +274,7 @@ public function testEnableAppForGroupsForbiddenTypes($type) { /** @var AppManager|MockObject $manager */ $manager = $this->getMockBuilder(AppManager::class) ->setConstructorArgs([ - $this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger + $this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger ]) ->setMethods([ 'getAppPath', @@ -476,7 +470,7 @@ public function testGetAppsForUser() { public function testGetAppsNeedingUpgrade() { /** @var AppManager|MockObject $manager */ $manager = $this->getMockBuilder(AppManager::class) - ->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger]) + ->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger]) ->setMethods(['getAppInfo']) ->getMock(); @@ -527,7 +521,7 @@ function ($appId) use ($appInfos) { public function testGetIncompatibleApps() { /** @var AppManager|MockObject $manager */ $manager = $this->getMockBuilder(AppManager::class) - ->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger]) + ->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger]) ->setMethods(['getAppInfo']) ->getMock(); diff --git a/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php b/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php index 1cd6b614aade7..d37c1c4760972 100644 --- a/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php @@ -35,11 +35,8 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\IUserSession; use PHPUnit\Framework\MockObject\MockObject; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; class AdditionalScriptsMiddlewareTest extends \Test\TestCase { - /** @var EventDispatcherInterface|MockObject */ - private $legacyDispatcher; /** @var IUserSession|MockObject */ private $userSession; @@ -54,11 +51,9 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->legacyDispatcher = $this->createMock(EventDispatcherInterface::class); $this->userSession = $this->createMock(IUserSession::class); $this->dispatcher = $this->createMock(IEventDispatcher::class); $this->middleWare = new AdditionalScriptsMiddleware( - $this->legacyDispatcher, $this->userSession, $this->dispatcher ); @@ -67,8 +62,6 @@ protected function setUp(): void { } public function testNoTemplateResponse() { - $this->legacyDispatcher->expects($this->never()) - ->method($this->anything()); $this->userSession->expects($this->never()) ->method($this->anything()); $this->dispatcher->expects($this->never()) @@ -78,8 +71,6 @@ public function testNoTemplateResponse() { } public function testPublicShareController() { - $this->legacyDispatcher->expects($this->never()) - ->method($this->anything()); $this->userSession->expects($this->never()) ->method($this->anything()); $this->dispatcher->expects($this->never()) @@ -89,15 +80,6 @@ public function testPublicShareController() { } public function testStandaloneTemplateResponse() { - $this->legacyDispatcher->expects($this->once()) - ->method('dispatch') - ->willReturnCallback(function ($eventName) { - if ($eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS) { - return; - } - - $this->fail('Wrong event dispatched'); - }); $this->userSession->expects($this->never()) ->method($this->anything()); $this->dispatcher->expects($this->once()) @@ -114,15 +96,6 @@ public function testStandaloneTemplateResponse() { } public function testTemplateResponseNotLoggedIn() { - $this->legacyDispatcher->expects($this->once()) - ->method('dispatch') - ->willReturnCallback(function ($eventName) { - if ($eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS) { - return; - } - - $this->fail('Wrong event dispatched'); - }); $this->userSession->method('isLoggedIn') ->willReturn(false); $this->dispatcher->expects($this->once()) @@ -141,17 +114,6 @@ public function testTemplateResponseNotLoggedIn() { public function testTemplateResponseLoggedIn() { $events = []; - $this->legacyDispatcher->expects($this->exactly(2)) - ->method('dispatch') - ->willReturnCallback(function ($eventName) use (&$events) { - if ($eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS || - $eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN) { - $events[] = $eventName; - return; - } - - $this->fail('Wrong event dispatched'); - }); $this->userSession->method('isLoggedIn') ->willReturn(true); $this->dispatcher->expects($this->once()) @@ -165,8 +127,5 @@ public function testTemplateResponseLoggedIn() { }); $this->middleWare->afterController($this->controller, 'myMethod', $this->createMock(TemplateResponse::class)); - - $this->assertContains(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, $events); - $this->assertContains(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, $events); } } diff --git a/tests/lib/AppTest.php b/tests/lib/AppTest.php index 5cdee5e120068..12fbdb011d902 100644 --- a/tests/lib/AppTest.php +++ b/tests/lib/AppTest.php @@ -560,7 +560,6 @@ private function registerAppConfig(AppConfig $appConfig) { $appConfig, \OC::$server->getGroupManager(), \OC::$server->getMemCacheFactory(), - \OC::$server->getEventDispatcher(), \OC::$server->get(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class) )); diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php index da11b11e53780..7647e3bda7df1 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php @@ -40,7 +40,6 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use function reset; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; class ManagerTest extends TestCase { @@ -84,10 +83,7 @@ class ManagerTest extends TestCase { private $timeFactory; /** @var IEventDispatcher|MockObject */ - private $newDispatcher; - - /** @var EventDispatcherInterface|MockObject */ - private $eventDispatcher; + private $dispatcher; protected function setUp(): void { parent::setUp(); @@ -102,8 +98,7 @@ protected function setUp(): void { $this->logger = $this->createMock(LoggerInterface::class); $this->tokenProvider = $this->createMock(TokenProvider::class); $this->timeFactory = $this->createMock(ITimeFactory::class); - $this->newDispatcher = $this->createMock(IEventDispatcher::class); - $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->dispatcher = $this->createMock(IEventDispatcher::class); $this->manager = new Manager( $this->providerLoader, @@ -115,8 +110,7 @@ protected function setUp(): void { $this->logger, $this->tokenProvider, $this->timeFactory, - $this->newDispatcher, - $this->eventDispatcher + $this->dispatcher, ); $this->fakeProvider = $this->createMock(IProvider::class); @@ -530,8 +524,7 @@ public function testNeedsSecondFactor() { $this->logger, $this->tokenProvider, $this->timeFactory, - $this->newDispatcher, - $this->eventDispatcher + $this->dispatcher, ]) ->setMethods(['loadTwoFactorApp', 'isTwoFactorAuthenticated'])// Do not actually load the apps ->getMock(); diff --git a/tests/lib/Files/Node/HookConnectorTest.php b/tests/lib/Files/Node/HookConnectorTest.php index 9704c7b89f120..0501c175a5f6a 100644 --- a/tests/lib/Files/Node/HookConnectorTest.php +++ b/tests/lib/Files/Node/HookConnectorTest.php @@ -31,9 +31,7 @@ use OCP\Files\Events\Node\NodeWrittenEvent; use OCP\Files\Node; use OCP\IUserManager; -use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; use Test\TestCase; use Test\Traits\MountProviderTrait; @@ -50,9 +48,6 @@ class HookConnectorTest extends TestCase { use UserTrait; use MountProviderTrait; - /** @var EventDispatcherInterface|MockObject */ - protected $legacyDispatcher; - /** @var IEventDispatcher */ protected $eventDispatcher; @@ -82,7 +77,6 @@ protected function setUp(): void { $this->createMock(IUserManager::class), $this->createMock(IEventDispatcher::class) ); - $this->legacyDispatcher = \OC::$server->getEventDispatcher(); $this->eventDispatcher = \OC::$server->query(IEventDispatcher::class); } @@ -149,7 +143,7 @@ public function viewToNodeProvider() { * @dataProvider viewToNodeProvider */ public function testViewToNode(callable $operation, $expectedHook, $expectedLegacyEvent, $expectedEvent) { - $connector = new HookConnector($this->root, $this->view, $this->legacyDispatcher, $this->eventDispatcher); + $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher); $connector->viewToNode(); $hookCalled = false; /** @var Node $hookNode */ @@ -163,7 +157,7 @@ public function testViewToNode(callable $operation, $expectedHook, $expectedLega $dispatcherCalled = false; /** @var Node $dispatcherNode */ $dispatcherNode = null; - $this->legacyDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherCalled, &$dispatcherNode) { + $this->eventDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherCalled, &$dispatcherNode) { /** @var GenericEvent|APIGenericEvent $event */ $dispatcherCalled = true; $dispatcherNode = $event->getSubject(); @@ -218,7 +212,7 @@ public function viewToNodeProviderCopyRename() { * @dataProvider viewToNodeProviderCopyRename */ public function testViewToNodeCopyRename(callable $operation, $expectedHook, $expectedLegacyEvent, $expectedEvent) { - $connector = new HookConnector($this->root, $this->view, $this->legacyDispatcher, $this->eventDispatcher); + $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher); $connector->viewToNode(); $hookCalled = false; /** @var Node $hookSourceNode */ @@ -237,7 +231,7 @@ public function testViewToNodeCopyRename(callable $operation, $expectedHook, $ex $dispatcherSourceNode = null; /** @var Node $dispatcherTargetNode */ $dispatcherTargetNode = null; - $this->legacyDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherSourceNode, &$dispatcherTargetNode, &$dispatcherCalled) { + $this->eventDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherSourceNode, &$dispatcherTargetNode, &$dispatcherCalled) { /** @var GenericEvent|APIGenericEvent $event */ $dispatcherCalled = true; [$dispatcherSourceNode, $dispatcherTargetNode] = $event->getSubject(); @@ -273,7 +267,7 @@ public function testViewToNodeCopyRename(callable $operation, $expectedHook, $ex } public function testPostDeleteMeta() { - $connector = new HookConnector($this->root, $this->view, $this->legacyDispatcher, $this->eventDispatcher); + $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher); $connector->viewToNode(); $hookCalled = false; /** @var Node $hookNode */ @@ -287,7 +281,7 @@ public function testPostDeleteMeta() { $dispatcherCalled = false; /** @var Node $dispatcherNode */ $dispatcherNode = null; - $this->legacyDispatcher->addListener('\OCP\Files::postDelete', function ($event) use (&$dispatcherCalled, &$dispatcherNode) { + $this->eventDispatcher->addListener('\OCP\Files::postDelete', function ($event) use (&$dispatcherCalled, &$dispatcherNode) { /** @var GenericEvent|APIGenericEvent $event */ $dispatcherCalled = true; $dispatcherNode = $event->getSubject(); diff --git a/tests/lib/Preview/GeneratorTest.php b/tests/lib/Preview/GeneratorTest.php index 2216674a34c2a..c7ffab2759235 100644 --- a/tests/lib/Preview/GeneratorTest.php +++ b/tests/lib/Preview/GeneratorTest.php @@ -35,8 +35,6 @@ use OCP\IPreview; use OCP\Preview\BeforePreviewFetchedEvent; use OCP\Preview\IProviderV2; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\GenericEvent; class GeneratorTest extends \Test\TestCase { /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ @@ -54,9 +52,6 @@ class GeneratorTest extends \Test\TestCase { /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ private $eventDispatcher; - /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */ - private $legacyEventDispatcher; - /** @var Generator */ private $generator; @@ -68,14 +63,12 @@ protected function setUp(): void { $this->appData = $this->createMock(IAppData::class); $this->helper = $this->createMock(GeneratorHelper::class); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); - $this->legacyEventDispatcher = $this->createMock(EventDispatcherInterface::class); $this->generator = new Generator( $this->config, $this->previewManager, $this->appData, $this->helper, - $this->legacyEventDispatcher, $this->eventDispatcher ); } @@ -112,17 +105,6 @@ public function testGetCachedPreview() { $previewFolder->method('getDirectoryListing') ->willReturn([$maxPreview, $previewFile]); - $this->legacyEventDispatcher->expects($this->once()) - ->method('dispatch') - ->with( - $this->equalTo(IPreview::EVENT), - $this->callback(function (GenericEvent $event) use ($file) { - return $event->getSubject() === $file && - $event->getArgument('width') === 100 && - $event->getArgument('height') === 100; - }) - ); - $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped') ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL)); @@ -251,17 +233,6 @@ public function testGetNewPreview() { ->method('putContent') ->with('my resized data'); - $this->legacyEventDispatcher->expects($this->once()) - ->method('dispatch') - ->with( - $this->equalTo(IPreview::EVENT), - $this->callback(function (GenericEvent $event) use ($file) { - return $event->getSubject() === $file && - $event->getArgument('width') === 100 && - $event->getArgument('height') === 100; - }) - ); - $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped') ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL)); @@ -301,19 +272,6 @@ public function testInvalidMimeType() { ->with($this->equalTo('1024-512-crop.png')) ->willThrowException(new NotFoundException()); - $this->legacyEventDispatcher->expects($this->once()) - ->method('dispatch') - ->with( - $this->equalTo(IPreview::EVENT), - $this->callback(function (GenericEvent $event) use ($file) { - return $event->getSubject() === $file && - $event->getArgument('width') === 1024 && - $event->getArgument('height') === 512 && - $event->getArgument('crop') === true && - $event->getArgument('mode') === IPreview::MODE_COVER; - }) - ); - $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped') ->with(new BeforePreviewFetchedEvent($file, 1024, 512, true, IPreview::MODE_COVER)); @@ -351,19 +309,6 @@ public function testReturnCachedPreviewsWithoutCheckingSupportedMimetype() { $this->previewManager->expects($this->never()) ->method('isMimeSupported'); - $this->legacyEventDispatcher->expects($this->once()) - ->method('dispatch') - ->with( - $this->equalTo(IPreview::EVENT), - $this->callback(function (GenericEvent $event) use ($file) { - return $event->getSubject() === $file && - $event->getArgument('width') === 1024 && - $event->getArgument('height') === 512 && - $event->getArgument('crop') === true && - $event->getArgument('mode') === IPreview::MODE_COVER; - }) - ); - $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped') ->with(new BeforePreviewFetchedEvent($file, 1024, 512, true, IPreview::MODE_COVER)); @@ -392,17 +337,6 @@ public function testNoProvider() { $this->previewManager->method('getProviders') ->willReturn([]); - $this->legacyEventDispatcher->expects($this->once()) - ->method('dispatch') - ->with( - $this->equalTo(IPreview::EVENT), - $this->callback(function (GenericEvent $event) use ($file) { - return $event->getSubject() === $file && - $event->getArgument('width') === 100 && - $event->getArgument('height') === 100; - }) - ); - $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped') ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL)); @@ -528,19 +462,6 @@ public function testCorrectSize($maxX, $maxY, $reqX, $reqY, $crop, $mode, $expec ->with($this->equalTo($filename)) ->willReturn($preview); - $this->legacyEventDispatcher->expects($this->once()) - ->method('dispatch') - ->with( - $this->equalTo(IPreview::EVENT), - $this->callback(function (GenericEvent $event) use ($file, $reqX, $reqY, $crop, $mode) { - return $event->getSubject() === $file && - $event->getArgument('width') === $reqX && - $event->getArgument('height') === $reqY && - $event->getArgument('crop') === $crop && - $event->getArgument('mode') === $mode; - }) - ); - $this->eventDispatcher->expects($this->once()) ->method('dispatchTyped') ->with(new BeforePreviewFetchedEvent($file, $reqX, $reqY, $crop, $mode)); diff --git a/tests/lib/Share20/LegacyHooksTest.php b/tests/lib/Share20/LegacyHooksTest.php index b8b005abd4e28..54d8e0be72534 100644 --- a/tests/lib/Share20/LegacyHooksTest.php +++ b/tests/lib/Share20/LegacyHooksTest.php @@ -27,12 +27,12 @@ use OC\Share20\LegacyHooks; use OC\Share20\Manager; use OCP\Constants; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Cache\ICacheEntry; use OCP\Files\File; use OCP\IServerContainer; use OCP\Share\IShare; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\GenericEvent; use Test\TestCase; @@ -40,7 +40,7 @@ class LegacyHooksTest extends TestCase { /** @var LegacyHooks */ private $hooks; - /** @var EventDispatcher */ + /** @var IEventDispatcher */ private $eventDispatcher; /** @var Manager */ @@ -53,7 +53,7 @@ protected function setUp(): void { $logger = $this->createMock(LoggerInterface::class); $eventDispatcher = new \OC\EventDispatcher\EventDispatcher($symfonyDispatcher, \OC::$server->get(IServerContainer::class), $logger); $this->eventDispatcher = new SymfonyAdapter($eventDispatcher, $logger); - $this->hooks = new LegacyHooks($this->eventDispatcher); + $this->hooks = new LegacyHooks($eventDispatcher); $this->manager = \OC::$server->getShareManager(); } diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 0e56592e1a524..a23aa6023af33 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -545,7 +545,7 @@ public function testVerifyPasswordHook() { ['core', 'shareapi_enforce_links_password', 'no', 'no'], ]); - $this->eventDispatcher->expects($this->once())->method('dispatch') + $this->dispatcher->expects($this->once())->method('dispatchTyped') ->willReturnCallback(function (Event $event) { $this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event); /** @var ValidatePasswordPolicyEvent $event */ @@ -567,7 +567,7 @@ public function testVerifyPasswordHookFails() { ['core', 'shareapi_enforce_links_password', 'no', 'no'], ]); - $this->eventDispatcher->expects($this->once())->method('dispatch') + $this->dispatcher->expects($this->once())->method('dispatchTyped') ->willReturnCallback(function (Event $event) { $this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event); /** @var ValidatePasswordPolicyEvent $event */ diff --git a/tests/lib/SystemTag/SystemTagManagerTest.php b/tests/lib/SystemTag/SystemTagManagerTest.php index e261a68aaf796..e4610ede9bf36 100644 --- a/tests/lib/SystemTag/SystemTagManagerTest.php +++ b/tests/lib/SystemTag/SystemTagManagerTest.php @@ -12,12 +12,12 @@ use OC\SystemTag\SystemTagManager; use OC\SystemTag\SystemTagObjectMapper; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IUser; use OCP\SystemTag\ISystemTag; use OCP\SystemTag\ISystemTagManager; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; /** @@ -43,7 +43,7 @@ class SystemTagManagerTest extends TestCase { private $groupManager; /** - * @var EventDispatcherInterface + * @var IEventDispatcher */ private $dispatcher; @@ -52,10 +52,8 @@ protected function setUp(): void { $this->connection = \OC::$server->getDatabaseConnection(); - $this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface') - ->getMock(); - - $this->groupManager = $this->getMockBuilder(IGroupManager::class)->getMock(); + $this->dispatcher = $this->createMock(IEventDispatcher::class); + $this->groupManager = $this->createMock(IGroupManager::class); $this->tagManager = new SystemTagManager( $this->connection, diff --git a/tests/lib/SystemTag/SystemTagObjectMapperTest.php b/tests/lib/SystemTag/SystemTagObjectMapperTest.php index e77709c781fcc..2c838e0a6b364 100644 --- a/tests/lib/SystemTag/SystemTagObjectMapperTest.php +++ b/tests/lib/SystemTag/SystemTagObjectMapperTest.php @@ -13,12 +13,12 @@ use OC\SystemTag\SystemTag; use OC\SystemTag\SystemTagManager; use OC\SystemTag\SystemTagObjectMapper; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IDBConnection; use OCP\SystemTag\ISystemTag; use OCP\SystemTag\ISystemTagManager; use OCP\SystemTag\ISystemTagObjectMapper; use OCP\SystemTag\TagNotFoundException; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; /** @@ -44,7 +44,7 @@ class SystemTagObjectMapperTest extends TestCase { private $connection; /** - * @var EventDispatcherInterface + * @var IEventDispatcher */ private $dispatcher; @@ -69,11 +69,8 @@ protected function setUp(): void { $this->connection = \OC::$server->getDatabaseConnection(); $this->pruneTagsTables(); - $this->tagManager = $this->getMockBuilder('OCP\SystemTag\ISystemTagManager') - ->getMock(); - - $this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface') - ->getMock(); + $this->tagManager = $this->createMock(ISystemTagManager::class); + $this->dispatcher = $this->createMock(IEventDispatcher::class); $this->tagMapper = new SystemTagObjectMapper( $this->connection,