Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use OCP\EventDispatcher\Event over Symfony's deprecated Event #17568

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions apps/dav/tests/unit/Comments/RootCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@

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;
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 {

Expand All @@ -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;
Expand All @@ -67,10 +69,17 @@ public function setUp() {
$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,
Expand Down
2 changes: 1 addition & 1 deletion apps/files_trashbin/lib/Events/MoveToTrashEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


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

/**
* Class MoveToTrashEvent
Expand Down
4 changes: 1 addition & 3 deletions apps/files_versions/lib/Events/CreateVersionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@

namespace OCA\Files_Versions\Events;


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

use OCP\EventDispatcher\Event;

/**
* Class CreateVersionEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,9 @@

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is unused, therefore removed. Or what do you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my nice cleanup emoji :)

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 {
Expand Down
18 changes: 13 additions & 5 deletions lib/private/EventDispatcher/SymfonyAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@

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;

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;
}

/**
Expand All @@ -46,16 +49,21 @@ public function __construct(EventDispatcher $eventDispatcher) {
* @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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/AbstractCacheEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

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;
Expand Down
2 changes: 1 addition & 1 deletion lib/public/App/ManagerEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace OCP\App;

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

/**
* Class ManagerEvent
Expand Down
2 changes: 1 addition & 1 deletion lib/public/Comments/CommentsEntityEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace OCP\Comments;

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

/**
* Class CommentsEntityEvent
Expand Down
2 changes: 1 addition & 1 deletion lib/public/Comments/CommentsEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace OCP\Comments;

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

/**
* Class CommentsEvent
Expand Down
2 changes: 1 addition & 1 deletion lib/public/Console/ConsoleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace OCP\Console;

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

/**
* Class ConsoleEvent
Expand Down
2 changes: 1 addition & 1 deletion lib/public/SabrePluginEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

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

/**
* @since 8.2.0
Expand Down
2 changes: 1 addition & 1 deletion lib/public/SystemTag/ManagerEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace OCP\SystemTag;

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

/**
* Class ManagerEvent
Expand Down
2 changes: 1 addition & 1 deletion lib/public/SystemTag/MapperEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace OCP\SystemTag;

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

/**
* Class MapperEvent
Expand Down
2 changes: 1 addition & 1 deletion lib/public/SystemTag/SystemTagsEntityEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace OCP\SystemTag;

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

/**
* Class SystemTagsEntityEvent
Expand Down