Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb776b7

Browse files
committed
[Workflow] Deprecate MultipleStateMarkingStore and SingleStateMarkingStore in favor of MethodMarkingStore
1 parent fc826aa commit bb776b7

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
@@ -156,3 +156,46 @@ Workflow
156156
}
157157
}
158158
```
159+
160+
* `MultipleStateMarkingStore` is deprecated. Use `MethodMarkingStore` instead.
161+
162+
Before:
163+
```yaml
164+
framework:
165+
workflows:
166+
article:
167+
marking_store:
168+
type: multiple
169+
```
170+
171+
After:
172+
```yaml
173+
framework:
174+
workflows:
175+
article:
176+
marking_store:
177+
type: method
178+
179+
```
180+
181+
* `SingleStateMarkingStore` is deprecated. Use `MethodMarkingStore` instead.
182+
183+
Before:
184+
```yaml
185+
framework:
186+
workflows:
187+
article:
188+
marking_store:
189+
type: single
190+
```
191+
192+
After:
193+
```yaml
194+
framework:
195+
workflows:
196+
article:
197+
marking_store:
198+
type: method
199+
arguments:
200+
- true
201+
```

UPGRADE-5.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ Workflow
368368
* `SupportStrategyInterface` has been removed, use `WorkflowSupportStrategyInterface` instead.
369369
* `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead.
370370
* `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`.
371+
* `MultipleStateMarkingStore` has been removed.
372+
* `SingleStateMarkingStore` has been removed.
371373

372374
Yaml
373375
----

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

@@ -26,6 +26,8 @@ CHANGELOG
2626
* Dispatch `EnteredEvent` on `workflow.entered`
2727
* Dispatch `CompletedEvent` on `workflow.completed`
2828
* Dispatch `AnnounceEvent` on `workflow.announce`
29+
* Deprecated the `MultipleStateMarkingStore` class, use the `MethodMarkingStore` instead.
30+
* Deprecated the `SingleStateMarkingStore` class, use the `MethodMarkingStore` instead.
2931

3032
4.1.0
3133
-----

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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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);

0 commit comments

Comments
 (0)