Skip to content

Commit 59f20ad

Browse files
committed
minor #30551 [Workflow] Deprecate MultipleStateMarkingStore and SingleStateMarkingStore in favor of MethodMarkingStore (lyrixx)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Workflow] Deprecate MultipleStateMarkingStore and SingleStateMarkingStore in favor of MethodMarkingStore | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- 4d58beb [Workflow] Deprecate MultipleStateMarkingStore and SingleStateMarkingStore in favor of MethodMarkingStore
2 parents 9354c8e + 4d58beb commit 59f20ad

16 files changed

+189
-127
lines changed

UPGRADE-4.3.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,46 @@ Workflow
177177
}
178178
}
179179
```
180+
181+
* `MultipleStateMarkingStore` is deprecated. Use `MethodMarkingStore` instead.
182+
183+
Before:
184+
```yaml
185+
framework:
186+
workflows:
187+
article:
188+
marking_store:
189+
type: multiple
190+
```
191+
192+
After:
193+
```yaml
194+
framework:
195+
workflows:
196+
article:
197+
marking_store:
198+
type: method
199+
200+
```
201+
202+
* `SingleStateMarkingStore` is deprecated. Use `MethodMarkingStore` instead.
203+
204+
Before:
205+
```yaml
206+
framework:
207+
workflows:
208+
article:
209+
marking_store:
210+
type: single
211+
```
212+
213+
After:
214+
```yaml
215+
framework:
216+
workflows:
217+
article:
218+
marking_store:
219+
type: method
220+
arguments:
221+
- true
222+
```

UPGRADE-5.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ Workflow
369369
* `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead.
370370
* `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`.
371371
* Removed support of `initial_place`. Use `initial_places` instead.
372+
* `MultipleStateMarkingStore` has been removed.
373+
* `SingleStateMarkingStore` has been removed.
372374

373375
Yaml
374376
----

src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\Twig\Extension\WorkflowExtension;
1616
use Symfony\Component\Workflow\Definition;
17+
use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore;
1718
use Symfony\Component\Workflow\Metadata\InMemoryMetadataStore;
1819
use Symfony\Component\Workflow\Registry;
1920
use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy;
@@ -49,30 +50,28 @@ protected function setUp()
4950
);
5051
}
5152
$definition = new Definition($places, $transitions, null, $metadataStore);
52-
$workflow = new Workflow($definition);
53+
$workflow = new Workflow($definition, new MethodMarkingStore());
5354

5455
$registry = new Registry();
5556
$addWorkflow = method_exists($registry, 'addWorkflow') ? 'addWorkflow' : 'add';
5657
$supportStrategy = class_exists(InstanceOfSupportStrategy::class)
57-
? new InstanceOfSupportStrategy(\stdClass::class)
58-
: new ClassInstanceSupportStrategy(\stdClass::class);
58+
? new InstanceOfSupportStrategy(Subject::class)
59+
: new ClassInstanceSupportStrategy(Subject::class);
5960
$registry->$addWorkflow($workflow, $supportStrategy);
6061
$this->extension = new WorkflowExtension($registry);
6162
}
6263

6364
public function testCanTransition()
6465
{
65-
$subject = new \stdClass();
66-
$subject->marking = [];
66+
$subject = new Subject();
6767

6868
$this->assertTrue($this->extension->canTransition($subject, 't1'));
6969
$this->assertFalse($this->extension->canTransition($subject, 't2'));
7070
}
7171

7272
public function testGetEnabledTransitions()
7373
{
74-
$subject = new \stdClass();
75-
$subject->marking = [];
74+
$subject = new Subject();
7675

7776
$transitions = $this->extension->getEnabledTransitions($subject);
7877

@@ -83,9 +82,7 @@ public function testGetEnabledTransitions()
8382

8483
public function testHasMarkedPlace()
8584
{
86-
$subject = new \stdClass();
87-
$subject->marking = [];
88-
$subject->marking = ['ordered' => 1, 'waiting_for_payment' => 1];
85+
$subject = new Subject(['ordered' => 1, 'waiting_for_payment' => 1]);
8986

9087
$this->assertTrue($this->extension->hasMarkedPlace($subject, 'ordered'));
9188
$this->assertTrue($this->extension->hasMarkedPlace($subject, 'waiting_for_payment'));
@@ -94,21 +91,18 @@ public function testHasMarkedPlace()
9491

9592
public function testGetMarkedPlaces()
9693
{
97-
$subject = new \stdClass();
98-
$subject->marking = [];
99-
$subject->marking = ['ordered' => 1, 'waiting_for_payment' => 1];
94+
$subject = new Subject(['ordered' => 1, 'waiting_for_payment' => 1]);
10095

10196
$this->assertSame(['ordered', 'waiting_for_payment'], $this->extension->getMarkedPlaces($subject));
102-
$this->assertSame($subject->marking, $this->extension->getMarkedPlaces($subject, false));
97+
$this->assertSame($subject->getMarking(), $this->extension->getMarkedPlaces($subject, false));
10398
}
10499

105100
public function testGetMetadata()
106101
{
107102
if (!class_exists(InMemoryMetadataStore::class)) {
108103
$this->markTestSkipped('This test requires symfony/workflow:4.1.');
109104
}
110-
$subject = new \stdClass();
111-
$subject->marking = [];
105+
$subject = new Subject();
112106

113107
$this->assertSame('workflow title', $this->extension->getMetadata($subject, 'title'));
114108
$this->assertSame('ordered title', $this->extension->getMetadata($subject, 'title', 'orderer'));
@@ -117,3 +111,23 @@ public function testGetMetadata()
117111
$this->assertNull($this->extension->getMetadata($subject, 'not found', $this->t1));
118112
}
119113
}
114+
115+
final class Subject
116+
{
117+
private $marking;
118+
119+
public function __construct($marking = null)
120+
{
121+
$this->marking = $marking;
122+
}
123+
124+
public function getMarking()
125+
{
126+
return $this->marking;
127+
}
128+
129+
public function setMarking($marking)
130+
{
131+
$this->marking = $marking;
132+
}
133+
}

src/Symfony/Bridge/Twig/composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@
4141
"symfony/var-dumper": "~3.4|~4.0",
4242
"symfony/expression-language": "~3.4|~4.0",
4343
"symfony/web-link": "~3.4|~4.0",
44-
"symfony/workflow": "~3.4|~4.0"
44+
"symfony/workflow": "~4.3"
4545
},
4646
"conflict": {
4747
"symfony/console": "<3.4",
4848
"symfony/form": "<4.3",
49-
"symfony/translation": "<4.2"
49+
"symfony/translation": "<4.2",
50+
"symfony/workflow": "<4.3"
5051
},
5152
"suggest": {
5253
"symfony/finder": "",

src/Symfony/Component/Workflow/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CHANGELOG
44
4.3.0
55
-----
66

7-
* Trigger `entered` event for subject entering in the Workflow for the first time
7+
* Trigger `entered` event for subject entering in the Workflow for the first time.
88
* Added a context to `Workflow::apply()`. The `MethodMarkingStore` could be used to leverage this feature.
99
* Add style to transitions by declaring metadata:
1010

@@ -27,6 +27,8 @@ CHANGELOG
2727
* Dispatch `CompletedEvent` on `workflow.completed`
2828
* Dispatch `AnnounceEvent` on `workflow.announce`
2929
* Added support for many `initialPlaces`
30+
* Deprecated the `MultipleStateMarkingStore` class, use the `MethodMarkingStore` instead.
31+
* Deprecated the `SingleStateMarkingStore` class, use the `MethodMarkingStore` instead.
3032

3133
4.1.0
3234
-----

src/Symfony/Component/Workflow/MarkingStore/MethodMarkingStore.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
*
2020
* This store deals with a "single state" or "multiple state" Marking.
2121
*
22+
* "single state" Marking means a subject can be in one and only one state at
23+
* the same time. Use it with state machine or specific workflow.
24+
*
25+
* "multiple state" Marking means a subject can be in many states at the same
26+
* time. Use it with workflow.
27+
*
2228
* @author Grégoire Pineau <lyrixx@lyrixx.info>
2329
*/
2430
final class MethodMarkingStore implements MarkingStoreInterface

src/Symfony/Component/Workflow/MarkingStore/MultipleStateMarkingStore.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Workflow\MarkingStore;
1313

14+
@trigger_error(sprintf('"%s" is deprecated since Symfony 4.3, use "%s" instead.', MultipleStateMarkingStore::class, MethodMarkingStore::class), E_USER_DEPRECATED);
15+
1416
use Symfony\Component\PropertyAccess\PropertyAccess;
1517
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
1618
use Symfony\Component\Workflow\Marking;
@@ -22,6 +24,8 @@
2224
* This store deals with a "multiple state" Marking. It means a subject can be
2325
* in many states at the same time.
2426
*
27+
* @deprecated since Symfony 4.3, use MethodMarkingStore instead.
28+
*
2529
* @author Grégoire Pineau <lyrixx@lyrixx.info>
2630
*/
2731
class MultipleStateMarkingStore implements MarkingStoreInterface

src/Symfony/Component/Workflow/MarkingStore/SingleStateMarkingStore.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Workflow\MarkingStore;
1313

14+
@trigger_error(sprintf('"%s" is deprecated since Symfony 4.3, use "%s" instead.', SingleStateMarkingStore::class, MethodMarkingStore::class), E_USER_DEPRECATED);
15+
1416
use Symfony\Component\PropertyAccess\PropertyAccess;
1517
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
1618
use Symfony\Component\Workflow\Marking;
@@ -21,6 +23,8 @@
2123
* This store deals with a "single state" Marking. It means a subject can be in
2224
* one and only one state at the same time.
2325
*
26+
* @deprecated since Symfony 4.3, use MethodMarkingStore instead.
27+
*
2428
* @author Grégoire Pineau <lyrixx@lyrixx.info>
2529
*/
2630
class SingleStateMarkingStore implements MarkingStoreInterface

src/Symfony/Component/Workflow/Tests/EventListener/AuditTrailListenerTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
use Psr\Log\AbstractLogger;
77
use Symfony\Component\EventDispatcher\EventDispatcher;
88
use Symfony\Component\Workflow\EventListener\AuditTrailListener;
9-
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
9+
use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore;
10+
use Symfony\Component\Workflow\Tests\Subject;
1011
use Symfony\Component\Workflow\Tests\WorkflowBuilderTrait;
1112
use Symfony\Component\Workflow\Workflow;
1213

@@ -18,22 +19,21 @@ public function testItWorks()
1819
{
1920
$definition = $this->createSimpleWorkflowDefinition();
2021

21-
$object = new \stdClass();
22-
$object->marking = null;
22+
$object = new Subject();
2323

2424
$logger = new Logger();
2525

2626
$ed = new EventDispatcher();
2727
$ed->addSubscriber(new AuditTrailListener($logger));
2828

29-
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $ed);
29+
$workflow = new Workflow($definition, new MethodMarkingStore(), $ed);
3030

3131
$workflow->apply($object, 't1');
3232

3333
$expected = [
34-
'Leaving "a" for subject of class "stdClass" in workflow "unnamed".',
35-
'Transition "t1" for subject of class "stdClass" in workflow "unnamed".',
36-
'Entering "b" for subject of class "stdClass" in workflow "unnamed".',
34+
'Leaving "a" for subject of class "Symfony\Component\Workflow\Tests\Subject" in workflow "unnamed".',
35+
'Transition "t1" for subject of class "Symfony\Component\Workflow\Tests\Subject" in workflow "unnamed".',
36+
'Entering "b" for subject of class "Symfony\Component\Workflow\Tests\Subject" in workflow "unnamed".',
3737
];
3838

3939
$this->assertSame($expected, $logger->logs);

src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Symfony\Component\Workflow\EventListener\GuardExpression;
1414
use Symfony\Component\Workflow\EventListener\GuardListener;
1515
use Symfony\Component\Workflow\Marking;
16+
use Symfony\Component\Workflow\Tests\Subject;
1617
use Symfony\Component\Workflow\Transition;
1718
use Symfony\Component\Workflow\WorkflowInterface;
1819

@@ -130,13 +131,12 @@ public function testGuardExpressionBlocks()
130131

131132
private function createEvent(Transition $transition = null)
132133
{
133-
$subject = new \stdClass();
134-
$subject->marking = new Marking();
134+
$subject = new Subject();
135135
$transition = $transition ?: new Transition('name', 'from', 'to');
136136

137137
$workflow = $this->getMockBuilder(WorkflowInterface::class)->getMock();
138138

139-
return new GuardEvent($subject, $subject->marking, $transition, $workflow);
139+
return new GuardEvent($subject, new Marking($subject->getMarking() ?? []), $transition, $workflow);
140140
}
141141

142142
private function configureAuthenticationChecker($isUsed, $granted = true)

src/Symfony/Component/Workflow/Tests/MarkingStore/MethodMarkingStoreTest.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPUnit\Framework\TestCase;
66
use Symfony\Component\Workflow\Marking;
77
use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore;
8+
use Symfony\Component\Workflow\Tests\Subject;
89

910
class MethodMarkingStoreTest extends TestCase
1011
{
@@ -52,23 +53,3 @@ public function testGetSetMarkingWithSingleState()
5253
$this->assertEquals($marking, $marking2);
5354
}
5455
}
55-
56-
final class Subject
57-
{
58-
private $marking;
59-
60-
public function __construct($marking = null)
61-
{
62-
$this->marking = $marking;
63-
}
64-
65-
public function getMarking()
66-
{
67-
return $this->marking;
68-
}
69-
70-
public function setMarking($marking)
71-
{
72-
$this->marking = $marking;
73-
}
74-
}

src/Symfony/Component/Workflow/Tests/MarkingStore/MultipleStateMarkingStoreTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Symfony\Component\Workflow\Marking;
77
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
88

9+
/** @group legacy*/
910
class MultipleStateMarkingStoreTest extends TestCase
1011
{
1112
public function testGetSetMarking()

src/Symfony/Component/Workflow/Tests/MarkingStore/SingleStateMarkingStoreTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Symfony\Component\Workflow\Marking;
77
use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore;
88

9+
/** @group legacy*/
910
class SingleStateMarkingStoreTest extends TestCase
1011
{
1112
public function testGetSetMarking()

0 commit comments

Comments
 (0)