You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #51210 [Workflow] Add PHP attributes to register listeners and guards (lyrixx)
This PR was merged into the 6.4 branch.
Discussion
----------
[Workflow] Add PHP attributes to register listeners and guards
| Q | A
| ------------- | ---
| Branch? | 6.4
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Tickets |
| License | MIT
| Doc PR |
---
Allow this:
```diff
diff --git a/src/EventSubscriber/TransitionEventSubscriber.php b/src/EventSubscriber/TransitionEventSubscriber.php
index 3897e54..4ea0d46 100644
--- a/src/EventSubscriber/TransitionEventSubscriber.php
+++ b/src/EventSubscriber/TransitionEventSubscriber.php
@@ -2,18 +2,19 @@
namespace App\EventSubscriber;
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\User\UserInterface;
+use Symfony\Component\Workflow\Attribute\AsTransitionListener;
use Symfony\Component\Workflow\Event\TransitionEvent;
-class TransitionEventSubscriber implements EventSubscriberInterface
+class TransitionEventSubscriber
{
public function __construct(
private readonly TokenStorageInterface $tokenStorage,
) {
}
+ #[AsTransitionListener()]
public function onWorkflowArticleTransition(TransitionEvent $event): void
{
$context = $event->getContext();
```
All theses syntax are supported:
```php
#[AsTransitionListener()]
#[AsTransitionListener(workflow: 'my-workflow')]
#[AsTransitionListener(workflow: 'my-workflow', transition: 'some-transition')]
public function onWorkflowArticleTransition(TransitionEvent $event): void
```
---
Note: This is not possible to validate the workflow name,nor the transition name, because workflow can be build dynamically
Commits
-------
dcc3ce4cba [Workflow] Add some PHP attributes to register listeners and guards
0 commit comments