Skip to content

Instantly share code, notes, and snippets.

@weaverryan
Created October 28, 2021 19:43
Event Subscriber to Reset Encore "Cache" between Async Messenger Messages
<?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