Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit178a01e

Browse files
committed
[Workflow] DeprecateEvent::getWorkflow() method
1 parentc16162f commit178a01e

File tree

4 files changed

+89
-3
lines changed

4 files changed

+89
-3
lines changed

‎UPGRADE-7.3.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,78 @@ VarExporter
249249
* Deprecate using`ProxyHelper::generateLazyProxy()` when native lazy proxies can be used - the method should be used to generate abstraction-based lazy decorators only
250250
* Deprecate`LazyGhostTrait` and`LazyProxyTrait`, use native lazy objects instead
251251
* 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;
263+
264+
class MyListener
265+
{
266+
#[AsCompletedListener('my_workflow', 'to_state2')]
267+
public function terminateOrder(CompletedEvent $event): void
268+
{
269+
$subject = $event->getSubject();
270+
if ($event->getWorkflow()->can($subject, 'to_state3')) {
271+
$event->getWorkflow()->apply($subject, 'to_state3');
272+
}
273+
}
274+
}
275+
```
276+
277+
After:
278+
279+
```php
280+
use Symfony\Component\DependencyInjection\Attribute\Target;
281+
use Symfony\Component\Workflow\Attribute\AsCompletedListener;
282+
use Symfony\Component\Workflow\Event\CompletedEvent;
283+
use Symfony\Component\Workflow\WorkflowInterface;
284+
285+
class MyListener
286+
{
287+
public function __construct(
288+
#[Target('your_workflow_name')]
289+
private readonly WorkflowInterface $workflow,
290+
) {
291+
}
292+
293+
#[AsCompletedListener('your_workflow_name', 'to_state2')]
294+
public function terminateOrder(CompletedEvent $event): void
295+
{
296+
$subject = $event->getSubject();
297+
if ($this->workflow->can($subject, 'to_state3')) {
298+
$this->workflow->apply($subject, 'to_state3');
299+
}
300+
}
301+
}
302+
```
303+
304+
Or:
305+
306+
```php
307+
use Symfony\Component\DependencyInjection\ServiceLocator;
308+
use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
309+
use Symfony\Component\Workflow\Attribute\AsTransitionListener;
310+
use Symfony\Component\Workflow\Event\TransitionEvent;
311+
312+
class GenericListener
313+
{
314+
public function __construct(
315+
#[AutowireLocator('workflow', 'name')]
316+
private ServiceLocator $workflows
317+
) {
318+
}
319+
320+
#[AsTransitionListener()]
321+
public function doSomething(TransitionEvent $event): void
322+
{
323+
$workflow = $this->workflows->get($event->getWorkflowName());
324+
}
325+
}
326+
```

‎src/Symfony/Component/Workflow/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
CHANGELOG
22
=========
33

4+
7.3
5+
---
6+
7+
* Deprecate`Event::getWorkflow()` method
8+
49
7.1
510
---
611

712
* Add method`getEnabledTransition()` to`WorkflowInterface`
813
* Automatically register places from transitions
914
* Add support for workflows that need to store many tokens in the marking
10-
* Add method`getName()` in event classes to build event names in subscribers
15+
* Add method`getName()` in event classes to build event names in subscribers
1116

1217
7.0
1318
---

‎src/Symfony/Component/Workflow/Event/Event.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ public function getTransition(): ?Transition
4646
return$this->transition;
4747
}
4848

49+
/**
50+
* @deprecated since Symfony 7.3, inject the workflow in the constructor where you need it
51+
*/
4952
publicfunctiongetWorkflow():WorkflowInterface
5053
{
54+
trigger_deprecation('symfony/workflow','7.3','The "%s()" method is deprecated, inject the workflow in the constructor where you need it.',__METHOD__);
55+
5156
return$this->workflow;
5257
}
5358

‎src/Symfony/Component/Workflow/composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
"require-dev": {
2626
"psr/log":"^1|^2|^3",
2727
"symfony/dependency-injection":"^6.4|^7.0",
28-
"symfony/event-dispatcher":"^6.4|^7.0",
28+
"symfony/deprecation-contracts":"2.5|^3",
2929
"symfony/error-handler":"^6.4|^7.0",
30-
"symfony/http-kernel":"^6.4|^7.0",
30+
"symfony/event-dispatcher":"^6.4|^7.0",
3131
"symfony/expression-language":"^6.4|^7.0",
32+
"symfony/http-kernel":"^6.4|^7.0",
3233
"symfony/security-core":"^6.4|^7.0",
3334
"symfony/stopwatch":"^6.4|^7.0",
3435
"symfony/validator":"^6.4|^7.0"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp