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

Skip to content

Commit cde1f17

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

16 files changed

+192
-124
lines changed

UPGRADE-4.3.md

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

UPGRADE-5.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ Workflow
353353
* `SupportStrategyInterface` has been removed, use `WorkflowSupportStrategyInterface` instead.
354354
* `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead.
355355
* `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`.
356+
* `MultipleStateMarkingStore` has been removed.
357+
* `SingleStateMarkingStore` has been removed.
356358

357359
Yaml
358360
----

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

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,23 @@ protected function setUp()
5454
$registry = new Registry();
5555
$addWorkflow = method_exists($registry, 'addWorkflow') ? 'addWorkflow' : 'add';
5656
$supportStrategy = class_exists(InstanceOfSupportStrategy::class)
57-
? new InstanceOfSupportStrategy(\stdClass::class)
58-
: new ClassInstanceSupportStrategy(\stdClass::class);
57+
? new InstanceOfSupportStrategy(Subject::class)
58+
: new ClassInstanceSupportStrategy(Subject::class);
5959
$registry->$addWorkflow($workflow, $supportStrategy);
6060
$this->extension = new WorkflowExtension($registry);
6161
}
6262

6363
public function testCanTransition()
6464
{
65-
$subject = new \stdClass();
66-
$subject->marking = [];
65+
$subject = new Subject();
6766

6867
$this->assertTrue($this->extension->canTransition($subject, 't1'));
6968
$this->assertFalse($this->extension->canTransition($subject, 't2'));
7069
}
7170

7271
public function testGetEnabledTransitions()
7372
{
74-
$subject = new \stdClass();
75-
$subject->marking = [];
73+
$subject = new Subject();
7674

7775
$transitions = $this->extension->getEnabledTransitions($subject);
7876

@@ -83,9 +81,7 @@ public function testGetEnabledTransitions()
8381

8482
public function testHasMarkedPlace()
8583
{
86-
$subject = new \stdClass();
87-
$subject->marking = [];
88-
$subject->marking = ['ordered' => 1, 'waiting_for_payment' => 1];
84+
$subject = new Subject(['ordered' => 1, 'waiting_for_payment' => 1]);
8985

9086
$this->assertTrue($this->extension->hasMarkedPlace($subject, 'ordered'));
9187
$this->assertTrue($this->extension->hasMarkedPlace($subject, 'waiting_for_payment'));
@@ -94,21 +90,18 @@ public function testHasMarkedPlace()
9490

9591
public function testGetMarkedPlaces()
9692
{
97-
$subject = new \stdClass();
98-
$subject->marking = [];
99-
$subject->marking = ['ordered' => 1, 'waiting_for_payment' => 1];
93+
$subject = new Subject(['ordered' => 1, 'waiting_for_payment' => 1]);
10094

10195
$this->assertSame(['ordered', 'waiting_for_payment'], $this->extension->getMarkedPlaces($subject));
102-
$this->assertSame($subject->marking, $this->extension->getMarkedPlaces($subject, false));
96+
$this->assertSame($subject->getMarking(), $this->extension->getMarkedPlaces($subject, false));
10397
}
10498

10599
public function testGetMetadata()
106100
{
107101
if (!class_exists(InMemoryMetadataStore::class)) {
108102
$this->markTestSkipped('This test requires symfony/workflow:4.1.');
109103
}
110-
$subject = new \stdClass();
111-
$subject->marking = [];
104+
$subject = new Subject();
112105

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

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 <[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
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
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;
615
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
7-
use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore;
16+
use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore;
817

918
/**
1019
* @author Tobias Nyholm <[email protected]>
@@ -13,6 +22,6 @@ class StateMachine extends Workflow
1322
{
1423
public function __construct(Definition $definition, MarkingStoreInterface $markingStore = null, EventDispatcherInterface $dispatcher = null, string $name = 'unnamed')
1524
{
16-
parent::__construct($definition, $markingStore ?: new SingleStateMarkingStore(), $dispatcher, $name);
25+
parent::__construct($definition, $markingStore ?: new MethodMarkingStore(true), $dispatcher, $name);
1726
}
1827
}

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/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)