Skip to content

Commit

Permalink
Merge pull request #6154 from wallabag/fix/event-dispatcher
Browse files Browse the repository at this point in the history
Fix EventDispatcher & events
  • Loading branch information
nicosomb committed Dec 16, 2022
2 parents 35c77c1 + d47c208 commit 9c16dd7
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 48 deletions.
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Expand Up @@ -84,18 +84,3 @@ parameters:
message: "#^Property Tests\\\\Wallabag\\\\CoreBundle\\\\Helper\\\\RedirectTest\\:\\:\\$routerMock has unknown class PHPUnit_Framework_MockObject_MockObject as its type\\.$#"
count: 1
path: tests/Wallabag/CoreBundle/Helper/RedirectTest.php

-
message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch()#"
count: 1
path: src/Wallabag/ApiBundle/Controller/UserRestController.php

-
message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch()#"
count: 1
path: src/Wallabag/CoreBundle/Command/InstallCommand.php

-
message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch()#"
count: 1
path: src/Wallabag/UserBundle/Controller/ManageController.php
12 changes: 6 additions & 6 deletions src/Wallabag/ApiBundle/Controller/EntryRestController.php
Expand Up @@ -462,7 +462,7 @@ public function deleteEntriesListAction(Request $request)

if (false !== $entry) {
// entry deleted, dispatch event about it!
$this->get(EventDispatcherInterface::class)->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(new EntryDeletedEvent($entry), EntryDeletedEvent::NAME);

$em = $this->get('doctrine')->getManager();
$em->remove($entry);
Expand Down Expand Up @@ -539,7 +539,7 @@ public function postEntriesListAction(Request $request)
$results[$key]['entry'] = $entry instanceof Entry ? $entry->getId() : false;

// entry saved, dispatch event about it!
$this->get(EventDispatcherInterface::class)->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);
}

return $this->sendResponse($results);
Expand Down Expand Up @@ -760,7 +760,7 @@ public function postEntriesAction(Request $request)
$em->flush();

// entry saved, dispatch event about it!
$this->get(EventDispatcherInterface::class)->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);

return $this->sendResponse($entry);
}
Expand Down Expand Up @@ -976,7 +976,7 @@ public function patchEntriesAction(Entry $entry, Request $request)
$em->flush();

// entry saved, dispatch event about it!
$this->get(EventDispatcherInterface::class)->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);

return $this->sendResponse($entry);
}
Expand Down Expand Up @@ -1032,7 +1032,7 @@ public function patchEntriesReloadAction(Entry $entry)
$em->flush();

// entry saved, dispatch event about it!
$this->get(EventDispatcherInterface::class)->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);

return $this->sendResponse($entry);
}
Expand Down Expand Up @@ -1083,7 +1083,7 @@ public function deleteEntriesAction(Entry $entry, Request $request)
}

// entry deleted, dispatch event about it!
$this->get(EventDispatcherInterface::class)->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(new EntryDeletedEvent($entry), EntryDeletedEvent::NAME);

$em = $this->get('doctrine')->getManager();
$em->remove($entry);
Expand Down
3 changes: 1 addition & 2 deletions src/Wallabag/ApiBundle/Controller/UserRestController.php
Expand Up @@ -11,7 +11,6 @@
use Nelmio\ApiDocBundle\Annotation\Operation;
use Swagger\Annotations as SWG;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
Expand Down Expand Up @@ -160,7 +159,7 @@ public function putUserAction(Request $request)

// dispatch a created event so the associated config will be created
$event = new UserEvent($user, $request);
LegacyEventDispatcherProxy::decorate($this->get(EventDispatcherInterface::class))->dispatch($event, FOSUserEvents::USER_CREATED);
$this->get(EventDispatcherInterface::class)->dispatch($event, FOSUserEvents::USER_CREATED);

return $this->sendUser($user, 'user_api_with_client', JsonResponse::HTTP_CREATED);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Wallabag/CoreBundle/Command/InstallCommand.php
Expand Up @@ -18,7 +18,6 @@
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule;
use Wallabag\CoreBundle\Entity\InternalSetting;
use Wallabag\UserBundle\Entity\User;
Expand Down Expand Up @@ -282,7 +281,7 @@ private function setupAdmin()

// dispatch a created event so the associated config will be created
$event = new UserEvent($user);
LegacyEventDispatcherProxy::decorate($this->getContainer()->get(EventDispatcherInterface::class))->dispatch($event, FOSUserEvents::USER_CREATED);
$this->getContainer()->get(EventDispatcherInterface::class)->dispatch($event, FOSUserEvents::USER_CREATED);

$this->io->text('<info>Administration successfully setup.</info>');

Expand Down
2 changes: 1 addition & 1 deletion src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php
Expand Up @@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$em->persist($entry);
$em->flush();

$dispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$dispatcher->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);
$progressBar->advance();

$em->detach($entry);
Expand Down
10 changes: 5 additions & 5 deletions src/Wallabag/CoreBundle/Controller/EntryController.php
Expand Up @@ -102,7 +102,7 @@ function ($v) {
$entry->removeTag($tag);
}
} elseif ('delete' === $action) {
$this->get(EventDispatcherInterface::class)->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(new EntryDeletedEvent($entry), EntryDeletedEvent::NAME);
$em->remove($entry);
}
}
Expand Down Expand Up @@ -178,7 +178,7 @@ public function addEntryFormAction(Request $request)
$em->flush();

// entry saved, dispatch event about it!
$this->get(EventDispatcherInterface::class)->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);

return $this->redirect($this->generateUrl('homepage'));
}
Expand Down Expand Up @@ -206,7 +206,7 @@ public function addEntryViaBookmarkletAction(Request $request)
$em->flush();

// entry saved, dispatch event about it!
$this->get(EventDispatcherInterface::class)->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);
}

return $this->redirect($this->generateUrl('homepage'));
Expand Down Expand Up @@ -414,7 +414,7 @@ public function reloadAction(Entry $entry)
$em->flush();

// entry saved, dispatch event about it!
$this->get(EventDispatcherInterface::class)->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);

return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
}
Expand Down Expand Up @@ -498,7 +498,7 @@ public function deleteEntryAction(Request $request, Entry $entry)
);

// entry deleted, dispatch event about it!
$this->get(EventDispatcherInterface::class)->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(new EntryDeletedEvent($entry), EntryDeletedEvent::NAME);

$em = $this->get('doctrine')->getManager();
$em->remove($entry);
Expand Down
4 changes: 2 additions & 2 deletions src/Wallabag/CoreBundle/Event/EntryDeletedEvent.php
Expand Up @@ -2,7 +2,7 @@

namespace Wallabag\CoreBundle\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;
use Wallabag\CoreBundle\Entity\Entry;

/**
Expand All @@ -19,7 +19,7 @@ public function __construct(Entry $entry)
$this->entry = $entry;
}

public function getEntry()
public function getEntry(): Entry
{
return $this->entry;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Wallabag/CoreBundle/Event/EntrySavedEvent.php
Expand Up @@ -2,7 +2,7 @@

namespace Wallabag\CoreBundle\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;
use Wallabag\CoreBundle\Entity\Entry;

/**
Expand All @@ -19,7 +19,7 @@ public function __construct(Entry $entry)
$this->entry = $entry;
}

public function getEntry()
public function getEntry(): Entry
{
return $this->entry;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php
Expand Up @@ -72,7 +72,7 @@ protected function handleMessage($body)
$this->em->flush();

// entry saved, dispatch event about it!
$this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->eventDispatcher->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);

// clear only affected entities
$this->em->clear(Entry::class);
Expand Down
4 changes: 2 additions & 2 deletions src/Wallabag/ImportBundle/Import/AbstractImport.php
Expand Up @@ -171,7 +171,7 @@ protected function parseEntries(array $entries)
$this->em->flush();

foreach ($entryToBeFlushed as $entry) {
$this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->eventDispatcher->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);
}

$entryToBeFlushed = [];
Expand All @@ -187,7 +187,7 @@ protected function parseEntries(array $entries)

if (!empty($entryToBeFlushed)) {
foreach ($entryToBeFlushed as $entry) {
$this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->eventDispatcher->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Wallabag/ImportBundle/Import/BrowserImport.php
Expand Up @@ -173,7 +173,7 @@ protected function parseEntries(array $entries)
$this->em->flush();

foreach ($entryToBeFlushed as $entry) {
$this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->eventDispatcher->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);
}

$entryToBeFlushed = [];
Expand All @@ -185,7 +185,7 @@ protected function parseEntries(array $entries)

if (!empty($entryToBeFlushed)) {
foreach ($entryToBeFlushed as $entry) {
$this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->eventDispatcher->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Wallabag/UserBundle/Controller/ManageController.php
Expand Up @@ -11,7 +11,6 @@
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -50,7 +49,7 @@ public function newAction(Request $request)

// dispatch a created event so the associated config will be created
$event = new UserEvent($user, $request);
LegacyEventDispatcherProxy::decorate($this->get(EventDispatcherInterface::class))->dispatch($event, FOSUserEvents::USER_CREATED);
$this->get(EventDispatcherInterface::class)->dispatch($event, FOSUserEvents::USER_CREATED);

$this->get(SessionInterface::class)->getFlashBag()->add(
'notice',
Expand Down
Expand Up @@ -69,8 +69,8 @@ public function testSubscribedEvents()
$dispatcher->addSubscriber($listener);

$dispatcher->dispatch(
KernelEvents::REQUEST,
$event
$event,
KernelEvents::REQUEST
);

$this->assertSame('fr', $request->getLocale());
Expand Down
Expand Up @@ -57,8 +57,8 @@ public function testOnAuthenticationFailure()
);

$this->dispatcher->dispatch(
AuthenticationEvents::AUTHENTICATION_FAILURE,
$event
$event,
AuthenticationEvents::AUTHENTICATION_FAILURE
);

$records = $this->logHandler->getRecords();
Expand Down
Expand Up @@ -72,8 +72,8 @@ public function testWithValidUser()
->method('flush');

$this->dispatcher->dispatch(
FOSUserEvents::REGISTRATION_COMPLETED,
$event
$event,
FOSUserEvents::REGISTRATION_COMPLETED
);
}
}

0 comments on commit 9c16dd7

Please sign in to comment.