Closed
Description
Symfony version(s) affected
5.4.2
Description
Hello,
As a follow up of #38960, when a transition is made, a guard event is sent for every possible transition we are getting from.
However in our case those guard event listeners are quite resource-intensive (lots of checks are made in the DB).
Would there a way to not fire all of them when we know we will be doing only one transition?
How to reproduce
A sample I borrowed in #38960
signature:
type: 'state_machine'
audit_trail:
enabled: true
marking_store:
type: 'method'
property: 'state'
initial_marking: created
supports:
- App\Entity\Signature
places:
- created
- code_sent
- signed
transitions:
send_code:
from: created
to: code_sent
sign:
from: code_sent
to: signed
And the listener:
<?php
namespace App\Workflow\Guard;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Workflow\Event\GuardEvent;
class ReservationInProgressGuard implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
'workflow.reservation.guard.send_code' => 'OnEvent',
'workflow.reservation.guard.sign' => 'OnEvent',
];
}
public function OnEvent(GuardEvent $event): void
{
// Some heavy process which should be done only once per transition
}
}
Possible Solution
It is stated in the doc guard events are always fired, but wouldn't it be possible to not fire them, or have an info in the even which states "OK I was called for the transition you listened to, let's not continue further" ?
Additional Context
No response