Quite new to Symfony Messenger but experimenting with it. If I have something like this:
abstract class AbstractEditPage implements MessageSubscriberInterface
{
public static function getHandledMessages(): iterable
{
return [
PreSaveEvent::class => ['method' => 'preSave'],
PostSaveEvent::class => ['method' => 'postSave'],
];
}
public function preSave(PreSaveEvent $e)
{
// prestuff
}
public function postSave(PostSaveEvent $e)
{
// poststuff
}
public function save()
{
$this->bus->dispatch(new PreSaveEvent());
// stuff
$this->bus->dispatch(new PreSaveEvent());
}
}
And I have several pages that extend it, then all of them will handle both events when 'save' is executed.
I'm aware that I could pass some context into the event and then, in the handlers, filter using that context - but that doesn't feel like the right approach.
Am I approaching this wrong? Is there a better approach for this type of thing that doesn't involve dispatching different message types which would involve changing the save code to dispatch different things determined by the concrete class implementation?