Skip to content

Instantly share code, notes, and snippets.

@weaverryan
Created October 28, 2021 19:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weaverryan/dfdb3861e6a409c7380c425ca2ca42fa to your computer and use it in GitHub Desktop.
Save weaverryan/dfdb3861e6a409c7380c425ca2ca42fa to your computer and use it in GitHub Desktop.
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