Skip to content

Commit 262b9eb

Browse files
committed
[Workflow] Deprecate MultipleStateMarkingStore and SingleStateMarkingStore in favor of MethodMarkingStore
1 parent b7e798e commit 262b9eb

17 files changed

+198
-127
lines changed

UPGRADE-4.3.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,46 @@ Workflow
142142
}
143143
}
144144
```
145+
146+
* `MultipleStateMarkingStore` is deprecated. Use `MethodMarkingStore` instead.
147+
148+
Before:
149+
```yaml
150+
framework:
151+
workflows:
152+
article:
153+
marking_store:
154+
type: multiple
155+
```
156+
157+
After:
158+
```yaml
159+
framework:
160+
workflows:
161+
article:
162+
marking_store:
163+
type: method
164+
165+
```
166+
167+
* `SingleStateMarkingStore` is deprecated. Use `MethodMarkingStore` instead.
168+
169+
Before:
170+
```yaml
171+
framework:
172+
workflows:
173+
article:
174+
marking_store:
175+
type: single
176+
```
177+
178+
After:
179+
```yaml
180+
framework:
181+
workflows:
182+
article:
183+
marking_store:
184+
type: method
185+
arguments:
186+
- true
187+
```

UPGRADE-5.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ Workflow
358358
* `SupportStrategyInterface` has been removed, use `WorkflowSupportStrategyInterface` instead.
359359
* `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead.
360360
* `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`.
361+
* `MultipleStateMarkingStore` has been removed.
362+
* `SingleStateMarkingStore` has been removed.
361363

362364
Yaml
363365
----

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,8 +4,10 @@ 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.
9+
* Deprecated the `MultipleStateMarkingStore` class, use the `MethodMarkingStore` instead.
10+
* Deprecated the `SingleStateMarkingStore` class, use the `MethodMarkingStore` instead.
911

1012
4.1.0
1113
-----

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
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/StateMachine.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Workflow;
413

514
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

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)