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
This PR was merged into the 7.3 branch.
Discussion
----------
[Workflow] Deprecate `Event::getWorkflow()` method
| Q | A
| ------------- | ---
| Branch? | 7.3
| Bug fix? | kind of
| New feature? | no
| Deprecations? | yes
| Issues | Fix#59748
| License | MIT
```diff
+use Symfony\Component\DependencyInjection\Attribute\Target;
class ContinueToState3 implements EventSubscriberInterface
{
+ public function __construct(
+ #[Target('your_workflow_name')]
+ private readonly WorkflowInterface $workflow,
+ ) {
+ }
public static function getSubscribedEvents(): array
{
return [
'workflow.your_workflow_name.completed.to_state2' => ['terminateOrder', \PHP_INT_MIN],
];
}
public function terminateOrder(Event $event): void
{
$subject = $event->getSubject();
- if ($event->getWorkflow()->workflow->can($subject, 'to_state3')) {
- $event->getWorkflow()->apply($subject, 'to_state3');
+ if ($this->workflow->can($subject, 'to_state3')) {
+ $this->workflow->apply($subject, 'to_state3');
}
}
}
```
If one has a listener able to run on many workflow, it need to inject a locator
```php
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
use Symfony\Component\Workflow\Attribute\AsTransitionListener;
use Symfony\Component\Workflow\Event\TransitionEvent;
class GenericListener
{
public function __construct(
#[AutowireLocator('workflow', 'name')]
private ServiceLocator $workflows
) {
}
#[AsTransitionListener()]
public function doSomething(TransitionEvent $event): void
{
$workflow = $this->workflows->get($event->getWorkflowName());
}
}
```
Commits
-------
20fbc9c [Workflow] Deprecate `Event::getWorkflow()` method
Copy file name to clipboardExpand all lines: UPGRADE-7.3.md
+75
Original file line number
Diff line number
Diff line change
@@ -249,3 +249,78 @@ VarExporter
249
249
* Deprecate using `ProxyHelper::generateLazyProxy()` when native lazy proxies can be used - the method should be used to generate abstraction-based lazy decorators only
250
250
* Deprecate `LazyGhostTrait` and `LazyProxyTrait`, use native lazy objects instead
251
251
* Deprecate `ProxyHelper::generateLazyGhost()`, use native lazy objects instead
252
+
253
+
Workflow
254
+
--------
255
+
256
+
* Deprecate `Event::getWorkflow()` method
257
+
258
+
Before:
259
+
260
+
```php
261
+
use Symfony\Component\Workflow\Attribute\AsCompletedListener;
262
+
use Symfony\Component\Workflow\Event\CompletedEvent;
Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Event/Event.php
+5
Original file line number
Diff line number
Diff line change
@@ -46,8 +46,13 @@ public function getTransition(): ?Transition
46
46
return$this->transition;
47
47
}
48
48
49
+
/**
50
+
* @deprecated since Symfony 7.3, inject the workflow in the constructor where you need it
51
+
*/
49
52
publicfunctiongetWorkflow(): WorkflowInterface
50
53
{
54
+
trigger_deprecation('symfony/workflow', '7.3', 'The "%s()" method is deprecated, inject the workflow in the constructor where you need it.', __METHOD__);
0 commit comments