Created
October 28, 2021 19:43
-
-
Save weaverryan/dfdb3861e6a409c7380c425ca2ca42fa to your computer and use it in GitHub Desktop.
Event Subscriber to Reset Encore "Cache" between Async Messenger Messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// src/EventSubscriber/MessengerResetEncoreSubscriber.php | |
namespace App\EventSubscriber; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
use Symfony\Component\Mailer\Messenger\SendEmailMessage; | |
use Symfony\Component\Messenger\Event\WorkerMessageReceivedEvent; | |
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface; | |
class MessengerResetEncoreSubscriber implements EventSubscriberInterface | |
{ | |
private $entrypointLookup; | |
public function __construct(EntrypointLookupInterface $entrypointLookup) | |
{ | |
$this->entrypointLookup = $entrypointLookup; | |
} | |
public function onMessageReceived(WorkerMessageReceivedEvent $event) | |
{ | |
if (!$event->getEnvelope()->getMessage() instanceof SendEmailMessage) { | |
return; | |
} | |
$this->entrypointLookup->reset(); | |
} | |
public static function getSubscribedEvents(): array | |
{ | |
return [ | |
WorkerMessageReceivedEvent::class => 'onMessageReceived', | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment