10000 [Workflow] Remove deprecated `Event::getWorkflow()` by mttsch · Pull Request #60989 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Workflow] Remove deprecated Event::getWorkflow() #60989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 8.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions UPGRADE-8.0.md
10000
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,78 @@ VarExporter
* Remove `LazyGhostTrait` and `LazyProxyTrait`, use native lazy objects instead
* Remove `ProxyHelper::generateLazyGhost()`, use native lazy objects instead

Workflow
--------

* Remove `Event::getWorkflow()` method

*Before*
```php
use Symfony\Component\Workflow\Attribute\AsCompletedListener;
use Symfony\Component\Workflow\Event\CompletedEvent;

class MyListener
{
#[AsCompletedListener('my_workflow', 'to_state2')]
public function terminateOrder(CompletedEvent $event): void
{
$subject = $event->getSubject();
if ($event->getWorkflow()->can($subject, 'to_state3')) {
$event->getWorkflow()->apply($subject, 'to_state3');
}
}
}
```

*After*
```php
use Symfony\Component\DependencyInjection\Attribute\Target;
use Symfony\Component\Workflow\Attribute\AsCompletedListener;
use Symfony\Component\Workflow\Event\CompletedEvent;
use Symfony\Component\Workflow\WorkflowInterface;

class MyListener
{
public function __construct(
#[Target('my_workflow')]
private readonly WorkflowInterface $workflow,
) {
}

#[AsCompletedListener('my_workflow', 'to_state2')]
public function terminateOrder(CompletedEvent $event): void
{
$subject = $event->getSubject();
if ($this->workflow->can($subject, 'to_state3')) {
$this->workflow->apply($subject, 'to_state3');
}
}
}
```

*Or*
```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());
}
}
```

Yaml
----

Expand Down
72 changes: 72 additions & 0 deletions src/Symfony/Component/Workflow/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,78 @@
CHANGELOG
=========

8.0
---

* Remove `Event::getWorkflow()` method

*Before*
```php
use Symfony\Component\Workflow\Attribute\AsCompletedListener;
use Symfony\Component\Workflow\Event\CompletedEvent;

class MyListener
{
#[AsCompletedListener('my_workflow', 'to_state2')]
public function terminateOrder(CompletedEvent $event): void
{
$subject = $event->getSubject();
if ($event->getWorkflow()->can($subject, 'to_state3')) {
$event->getWorkflow()->apply($subject, 'to_state3');
}
}
}
```

*After*
```php
use Symfony\Component\DependencyInjection\Attribute\Target;
use Symfony\Component\Workflow\Attribute\AsCompletedListener;
use Symfony\Component\Workflow\Event\CompletedEvent;
use Symfony\Component\Workflow\WorkflowInterface;

class MyListener
{
public function __construct(
#[Target('my_workflow')]
private readonly WorkflowInterface $workflow,
) {
}

#[AsCompletedListener('my_workflow', 'to_state2')]
public function terminateOrder(CompletedEvent $event): void
{
$subject = $event->getSubject();
if ($this->workflow->can($subject, 'to_state3')) {
$this->workflow->apply($subject, 'to_state3');
}
}
}
```

*Or*
```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());
}
}
```

7.3
---

Expand Down
10 changes: 0 additions & 10 deletions src/Symfony/Component/Workflow/Event/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ public function getTransition(): ?Transition
return $this->transition;
}

/**
* @deprecated since Symfony 7.3, inject the workflow in the constructor where you need it
*/
public function getWorkflow(): WorkflowInterface
{
trigger_deprecation('symfony/workflow', '7.3', 'The "%s()" method is deprecated, inject the workflow in the constructor where you need it.', __METHOD__);

return $this->workflow;
}

public function getWorkflowName(): string
{
return $this->workflow->getName();
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Workflow/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
}
],
"require": {
"php": ">=8.4",
"symfony/deprecation-contracts": "2.5|^3"
"php": ">=8.4"
},
"require-dev": {
"psr/log": "^1|^2|^3",
Expand Down
Loading
0