Browse Source

Merge pull request #17568 from nextcloud/fix/noid/move-away-from-deprecated-event

use OCP\EventDispatcher\Event over Symfony's deprecated Event
tags/v18.0.0beta1
blizzz 4 years ago
parent
commit
923735021b
No account linked to committer's email address

+ 12
- 3
apps/dav/tests/unit/Comments/RootCollectionTest.php View File

@@ -25,6 +25,8 @@

namespace OCA\DAV\Tests\unit\Comments;

use OC\EventDispatcher\EventDispatcher;
use OC\EventDispatcher\SymfonyAdapter;
use OCA\DAV\Comments\EntityTypeCollection as EntityTypeCollectionImplementation;
use OCP\Comments\CommentsEntityEvent;
use OCP\Comments\ICommentsManager;
@@ -32,7 +34,7 @@ use OCP\ILogger;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class RootCollectionTest extends \Test\TestCase {

@@ -46,7 +48,7 @@ class RootCollectionTest extends \Test\TestCase {
protected $collection;
/** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */
protected $userSession;
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */
/** @var EventDispatcherInterface */
protected $dispatcher;
/** @var \OCP\IUser|\PHPUnit_Framework_MockObject_MockObject */
protected $user;
@@ -67,10 +69,17 @@ class RootCollectionTest extends \Test\TestCase {
$this->userSession = $this->getMockBuilder(IUserSession::class)
->disableOriginalConstructor()
->getMock();
$this->dispatcher = new EventDispatcher();
$this->logger = $this->getMockBuilder(ILogger::class)
->disableOriginalConstructor()
->getMock();
$this->dispatcher = new SymfonyAdapter(
new EventDispatcher(
new \Symfony\Component\EventDispatcher\EventDispatcher(),
\OC::$server,
$this->logger
),
$this->logger
);

$this->collection = new \OCA\DAV\Comments\RootCollection(
$this->commentsManager,

+ 1
- 1
apps/files_trashbin/lib/Events/MoveToTrashEvent.php View File

@@ -26,7 +26,7 @@ namespace OCA\Files_Trashbin\Events;


use OCP\Files\Node;
use Symfony\Component\EventDispatcher\Event;
use OCP\EventDispatcher\Event;

/**
* Class MoveToTrashEvent

+ 1
- 3
apps/files_versions/lib/Events/CreateVersionEvent.php View File

@@ -24,10 +24,8 @@

namespace OCA\Files_Versions\Events;


use OCP\Files\Node;
use Symfony\Component\EventDispatcher\Event;

use OCP\EventDispatcher\Event;

/**
* Class CreateVersionEvent

+ 0
- 6
apps/twofactor_backupcodes/tests/Unit/Migration/CheckBackupCodeTest.php View File

@@ -23,15 +23,9 @@ declare(strict_types=1);

namespace OCA\TwoFactorBackupCodes\Tests\Unit\Migration;

use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
use OCA\TwoFactorBackupCodes\Listener\RegistryUpdater;
use OCA\TwoFactorBackupCodes\Migration\CheckBackupCodes;
use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
use OCP\Authentication\TwoFactorAuth\IRegistry;
use OCP\BackgroundJob\IJobList;
use OCP\IUser;
use OCP\Migration\IOutput;
use Symfony\Component\EventDispatcher\Event;
use Test\TestCase;

class CheckBackupCodeTest extends TestCase {

+ 13
- 5
lib/private/EventDispatcher/SymfonyAdapter.php View File

@@ -25,9 +25,9 @@ declare(strict_types=1);

namespace OC\EventDispatcher;

use OCP\ILogger;
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;

@@ -35,9 +35,12 @@ class SymfonyAdapter implements EventDispatcherInterface {

/** @var EventDispatcher */
private $eventDispatcher;
/** @var ILogger */
private $logger;

public function __construct(EventDispatcher $eventDispatcher) {
public function __construct(EventDispatcher $eventDispatcher, ILogger $logger) {
$this->eventDispatcher = $eventDispatcher;
$this->logger = $logger;
}

/**
@@ -46,16 +49,21 @@ class SymfonyAdapter implements EventDispatcherInterface {
* @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
* @param Event|null $event The event to pass to the event handlers/listeners
* If not supplied, an empty Event instance is created
*
* @return SymfonyEvent
* @return void
*/
public function dispatch($eventName, SymfonyEvent $event = null) {
public function dispatch($eventName, $event = null) {
// type hinting is not possible, due to usage of GenericEvent
if ($event instanceof Event) {
$this->eventDispatcher->dispatch($eventName, $event);
} else {
// Legacy event
$this->logger->info(
'Deprecated event type for {name}: {class}',
[ 'name' => $eventName, 'class' => is_object($event) ? get_class($event) : 'null' ]
);
$this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName, $event);
}
}

+ 1
- 1
lib/private/Files/Cache/AbstractCacheEvent.php View File

@@ -23,7 +23,7 @@ namespace OC\Files\Cache;

use OCP\Files\Cache\ICacheEvent;
use OCP\Files\Storage\IStorage;
use Symfony\Component\EventDispatcher\Event;
use OCP\EventDispatcher\Event;

class AbstractCacheEvent extends Event implements ICacheEvent {
protected $storage;

+ 1
- 1
lib/public/App/ManagerEvent.php View File

@@ -23,7 +23,7 @@

namespace OCP\App;

use Symfony\Component\EventDispatcher\Event;
use OCP\EventDispatcher\Event;

/**
* Class ManagerEvent

+ 1
- 1
lib/public/Comments/CommentsEntityEvent.php View File

@@ -22,7 +22,7 @@

namespace OCP\Comments;

use Symfony\Component\EventDispatcher\Event;
use OCP\EventDispatcher\Event;

/**
* Class CommentsEntityEvent

+ 1
- 1
lib/public/Comments/CommentsEvent.php View File

@@ -23,7 +23,7 @@

namespace OCP\Comments;

use Symfony\Component\EventDispatcher\Event;
use OCP\EventDispatcher\Event;

/**
* Class CommentsEvent

+ 1
- 1
lib/public/Console/ConsoleEvent.php View File

@@ -22,7 +22,7 @@

namespace OCP\Console;

use Symfony\Component\EventDispatcher\Event;
use OCP\EventDispatcher\Event;

/**
* Class ConsoleEvent

+ 1
- 1
lib/public/SabrePluginEvent.php View File

@@ -26,7 +26,7 @@ namespace OCP;

use OCP\AppFramework\Http;
use Sabre\DAV\Server;
use Symfony\Component\EventDispatcher\Event;
use OCP\EventDispatcher\Event;

/**
* @since 8.2.0

+ 1
- 1
lib/public/SystemTag/ManagerEvent.php View File

@@ -24,7 +24,7 @@ declare(strict_types=1);

namespace OCP\SystemTag;

use Symfony\Component\EventDispatcher\Event;
use OCP\EventDispatcher\Event;

/**
* Class ManagerEvent

+ 1
- 1
lib/public/SystemTag/MapperEvent.php View File

@@ -23,7 +23,7 @@ declare(strict_types=1);

namespace OCP\SystemTag;

use Symfony\Component\EventDispatcher\Event;
use OCP\EventDispatcher\Event;

/**
* Class MapperEvent

+ 1
- 1
lib/public/SystemTag/SystemTagsEntityEvent.php View File

@@ -23,7 +23,7 @@ declare(strict_types=1);

namespace OCP\SystemTag;

use Symfony\Component\EventDispatcher\Event;
use OCP\EventDispatcher\Event;

/**
* Class SystemTagsEntityEvent

Loading…
Cancel
Save