Skip to content

Commit cdddaee

Browse files
committed
[Workfow] Rename current MarkingStore
* ScalarMarkingStore -> SingleStateMarkingStore * PropertyAccessorMarkingStore -> MultipleStateMarkingStore And I also made optionnal the `marking_store` config, to let the componant choose the best marking store depending on the type (state_machine or workflow).
1 parent b374944 commit cdddaee

9 files changed

+42
-31
lines changed

MarkingStore/MarkingStoreInterface.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
use Symfony\Component\Workflow\Marking;
1515

1616
/**
17-
* MarkingStoreInterface.
17+
* MarkingStoreInterface is the interface between the Workflow Component and a
18+
* plain old PHP object: the subject.
19+
*
20+
* It converts the Marking into something understandable by the subject and vice
21+
* versa.
1822
*
1923
* @author Grégoire Pineau <[email protected]>
2024
*/

MarkingStore/PropertyAccessorMarkingStore.php renamed to MarkingStore/MultipleStateMarkingStore.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@
1616
use Symfony\Component\Workflow\Marking;
1717

1818
/**
19-
* PropertyAccessorMarkingStore.
19+
* MultipleStateMarkingStore stores the marking into a property of the
20+
* subject.
21+
*
22+
* This store deals with a "multiple state" Marking. It means a subject can be
23+
* in many state at the same time.
2024
*
2125
* @author Grégoire Pineau <[email protected]>
2226
*/
23-
class PropertyAccessorMarkingStore implements MarkingStoreInterface
27+
class MultipleStateMarkingStore implements MarkingStoreInterface
2428
{
2529
private $property;
2630
private $propertyAccessor;
2731

2832
/**
29-
* PropertyAccessorMarkingStore constructor.
33+
* MultipleStateMarkingStore constructor.
3034
*
3135
* @param string $property
3236
* @param PropertyAccessorInterface|null $propertyAccessor

MarkingStore/ScalarMarkingStore.php renamed to MarkingStore/SingleStateMarkingStore.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@
1616
use Symfony\Component\Workflow\Marking;
1717

1818
/**
19-
* ScalarMarkingStore.
19+
* SingleStateMarkingStore stores the marking into a property of the subject.
20+
*
21+
* This store deals with a "single state" Marking. It means a subject can be in
22+
* one and only state at the same time.
2023
*
2124
* @author Grégoire Pineau <[email protected]>
2225
*/
23-
class ScalarMarkingStore implements MarkingStoreInterface
26+
class SingleStateMarkingStore implements MarkingStoreInterface
2427
{
2528
private $property;
2629
private $propertyAccessor;
2730

2831
/**
29-
* ScalarMarkingStore constructor.
32+
* SingleStateMarkingStore constructor.
3033
*
3134
* @param string $property
3235
* @param PropertyAccessorInterface|null $propertyAccessor

StateMachine.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
66
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
7-
use Symfony\Component\Workflow\MarkingStore\ScalarMarkingStore;
7+
use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore;
88

99
/**
1010
* @author Tobias Nyholm <[email protected]>
@@ -13,6 +13,6 @@ class StateMachine extends Workflow
1313
{
1414
public function __construct(Definition $definition, MarkingStoreInterface $markingStore = null, EventDispatcherInterface $dispatcher = null, $name = 'unnamed')
1515
{
16-
parent::__construct($definition, $markingStore ?: new ScalarMarkingStore(), $dispatcher, $name);
16+
parent::__construct($definition, $markingStore ?: new SingleStateMarkingStore(), $dispatcher, $name);
1717
}
1818
}

Tests/EventListener/AuditTrailListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Symfony\Component\EventDispatcher\EventDispatcher;
77
use Symfony\Component\Workflow\Definition;
88
use Symfony\Component\Workflow\EventListener\AuditTrailListener;
9-
use Symfony\Component\Workflow\MarkingStore\PropertyAccessorMarkingStore;
9+
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
1010
use Symfony\Component\Workflow\Transition;
1111
use Symfony\Component\Workflow\Workflow;
1212

@@ -29,7 +29,7 @@ public function testItWorks()
2929
$ed = new EventDispatcher();
3030
$ed->addSubscriber(new AuditTrailListener($logger));
3131

32-
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore(), $ed);
32+
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $ed);
3333

3434
$workflow->apply($object, 't1');
3535

Tests/MarkingStore/PropertyAccessorMarkingStoreTest.php renamed to Tests/MarkingStore/MultipleStateMarkingStoreTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
namespace Symfony\Component\Workflow\Tests\MarkingStore;
44

55
use Symfony\Component\Workflow\Marking;
6-
use Symfony\Component\Workflow\MarkingStore\PropertyAccessorMarkingStore;
6+
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
77

8-
class PropertyAccessorMarkingStoreTest extends \PHPUnit_Framework_TestCase
8+
class MultipleStateMarkingStoreTest extends \PHPUnit_Framework_TestCase
99
{
1010
public function testGetSetMarking()
1111
{
1212
$subject = new \stdClass();
1313
$subject->myMarks = null;
1414

15-
$markingStore = new PropertyAccessorMarkingStore('myMarks');
15+
$markingStore = new MultipleStateMarkingStore('myMarks');
1616

1717
$marking = $markingStore->getMarking($subject);
1818

Tests/MarkingStore/ScalarMarkingStoreTest.php renamed to Tests/MarkingStore/SingleStateMarkingStoreTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
namespace Symfony\Component\Workflow\Tests\MarkingStore;
44

55
use Symfony\Component\Workflow\Marking;
6-
use Symfony\Component\Workflow\MarkingStore\ScalarMarkingStore;
6+
use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore;
77

8-
class ScalarMarkingStoreTest extends \PHPUnit_Framework_TestCase
8+
class SingleStateMarkingStoreTest extends \PHPUnit_Framework_TestCase
99
{
1010
public function testGetSetMarking()
1111
{
1212
$subject = new \stdClass();
1313
$subject->myMarks = null;
1414

15-
$markingStore = new ScalarMarkingStore('myMarks');
15+
$markingStore = new SingleStateMarkingStore('myMarks');
1616

1717
$marking = $markingStore->getMarking($subject);
1818

Tests/WorkflowTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Symfony\Component\Workflow\Event\GuardEvent;
99
use Symfony\Component\Workflow\Marking;
1010
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
11-
use Symfony\Component\Workflow\MarkingStore\PropertyAccessorMarkingStore;
11+
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
1212
use Symfony\Component\Workflow\Transition;
1313
use Symfony\Component\Workflow\Workflow;
1414

@@ -35,7 +35,7 @@ public function testGetMarkingWithEmptyDefinition()
3535
{
3636
$subject = new \stdClass();
3737
$subject->marking = null;
38-
$workflow = new Workflow(new Definition(array(), array()), new PropertyAccessorMarkingStore());
38+
$workflow = new Workflow(new Definition(array(), array()), new MultipleStateMarkingStore());
3939

4040
$workflow->getMarking($subject);
4141
}
@@ -49,7 +49,7 @@ public function testGetMarkingWithImpossiblePlace()
4949
$subject = new \stdClass();
5050
$subject->marking = null;
5151
$subject->marking = array('nope' => true);
52-
$workflow = new Workflow(new Definition(array(), array()), new PropertyAccessorMarkingStore());
52+
$workflow = new Workflow(new Definition(array(), array()), new MultipleStateMarkingStore());
5353

5454
$workflow->getMarking($subject);
5555
}
@@ -59,7 +59,7 @@ public function testGetMarkingWithEmptyInitialMarking()
5959
$definition = $this->createComplexWorkflow();
6060
$subject = new \stdClass();
6161
$subject->marking = null;
62-
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore());
62+
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
6363

6464
$marking = $workflow->getMarking($subject);
6565

@@ -74,7 +74,7 @@ public function testGetMarkingWithExistingMarking()
7474
$subject = new \stdClass();
7575
$subject->marking = null;
7676
$subject->marking = array('b' => 1, 'c' => 1);
77-
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore());
77+
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
7878

7979
$marking = $workflow->getMarking($subject);
8080

@@ -92,7 +92,7 @@ public function testCanWithUnexistingTransition()
9292
$definition = $this->createComplexWorkflow();
9393
$subject = new \stdClass();
9494
$subject->marking = null;
95-
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore());
95+
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
9696

9797
$workflow->can($subject, 'foobar');
9898
}
@@ -102,7 +102,7 @@ public function testCan()
102102
$definition = $this->createComplexWorkflow();
103103
$subject = new \stdClass();
104104
$subject->marking = null;
105-
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore());
105+
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
106106

107107
$this->assertTrue($workflow->can($subject, 't1'));
108108
$this->assertFalse($workflow->can($subject, 't2'));
@@ -117,7 +117,7 @@ public function testCanWithGuard()
117117
$eventDispatcher->addListener('workflow.workflow_name.guard.t1', function (GuardEvent $event) {
118118
$event->setBlocked(true);
119119
});
120-
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore(), $eventDispatcher, 'workflow_name');
120+
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
121121

122122
$this->assertFalse($workflow->can($subject, 't1'));
123123
}
@@ -131,7 +131,7 @@ public function testApplyWithImpossibleTransition()
131131
$definition = $this->createComplexWorkflow();
132132
$subject = new \stdClass();
133133
$subject->marking = null;
134-
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore());
134+
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
135135

136136
$workflow->apply($subject, 't2');
137137
}
@@ -141,7 +141,7 @@ public function testApply()
141141
$definition = $this->createComplexWorkflow();
142142
$subject = new \stdClass();
143143
$subject->marking = null;
144-
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore());
144+
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
145145

146146
$marking = $workflow->apply($subject, 't1');
147147

@@ -157,7 +157,7 @@ public function testApplyWithEventDispatcher()
157157
$subject = new \stdClass();
158158
$subject->marking = null;
159159
$eventDispatcher = new EventDispatcherMock();
160-
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore(), $eventDispatcher, 'workflow_name');
160+
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
161161

162162
$eventNameExpected = array(
163163
'workflow.guard',
@@ -194,7 +194,7 @@ public function testGetEnabledTransitions()
194194
$eventDispatcher->addListener('workflow.workflow_name.guard.t1', function (GuardEvent $event) {
195195
$event->setBlocked(true);
196196
});
197-
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore(), $eventDispatcher, 'workflow_name');
197+
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
198198

199199
$this->assertEmpty($workflow->getEnabledTransitions($subject));
200200

Workflow.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\Workflow\Event\GuardEvent;
1717
use Symfony\Component\Workflow\Exception\LogicException;
1818
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
19-
use Symfony\Component\Workflow\MarkingStore\PropertyAccessorMarkingStore;
19+
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
2020

2121
/**
2222
* @author Fabien Potencier <[email protected]>
@@ -33,7 +33,7 @@ class Workflow
3333
public function __construct(Definition $definition, MarkingStoreInterface $markingStore = null, EventDispatcherInterface $dispatcher = null, $name = 'unnamed')
3434
{
3535
$this->definition = $definition;
36-
$this->markingStore = $markingStore ?: new PropertyAccessorMarkingStore();
36+
$this->markingStore = $markingStore ?: new MultipleStateMarkingStore();
3737
$this->dispatcher = $dispatcher;
3838
$this->name = $name;
3939
}

0 commit comments

Comments
 (0)