Permalink
Browse files

[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).
  • Loading branch information...
lyrixx committed Nov 9, 2016
1 parent 61b1334 commit 08464c9f2c059c5292fc9bfe991d6b74437389c9
@@ -241,10 +241,9 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->defaultValue('workflow')
->end()
->arrayNode('marking_store')
->isRequired()
->children()
->enumNode('type')
->values(array('property_accessor', 'scalar'))
->values(array('multiple_state', 'single_state'))
->end()
->arrayNode('arguments')
->beforeNormalization()
@@ -18,8 +18,8 @@
<argument /> <!-- name -->
</service>
<service id="workflow.marking_store.property_accessor" class="Symfony\Component\Workflow\MarkingStore\PropertyAccessorMarkingStore" abstract="true" />
<service id="workflow.marking_store.scalar" class="Symfony\Component\Workflow\MarkingStore\ScalarMarkingStore" abstract="true" />
<service id="workflow.marking_store.multiple_state" class="Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore" abstract="true" />
<service id="workflow.marking_store.single_state" class="Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore" abstract="true" />
<service id="workflow.registry" class="Symfony\Component\Workflow\Registry" />
@@ -6,7 +6,7 @@
'workflows' => array(
'my_workflow' => array(
'marking_store' => array(
'type' => 'property_accessor',
'type' => 'multiple_state',
),
'supports' => array(
FrameworkExtensionTest::class,
@@ -10,7 +10,7 @@
<framework:workflows>
<framework:workflow name="my_workflow">
<framework:marking-store>
<framework:type>property_accessor</framework:type>
<framework:type>multiple_state</framework:type>
<framework:arguments>a</framework:arguments>
<framework:arguments>a</framework:arguments>
</framework:marking-store>
@@ -2,7 +2,7 @@ framework:
workflows:
my_workflow:
marking_store:
type: property_accessor
type: multiple_state
supports:
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
places:
@@ -14,7 +14,11 @@
use Symfony\Component\Workflow\Marking;
/**
* MarkingStoreInterface.
* MarkingStoreInterface is the interface between the Workflow Component and a
* plain old PHP object: the subject.
*
* It converts the Marking into something understandable by the subject and vice
* versa.
*
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*/
@@ -16,17 +16,21 @@
use Symfony\Component\Workflow\Marking;
/**
* PropertyAccessorMarkingStore.
* MultipleStateMarkingStore stores the marking into a property of the
* subject.
*
* This store deals with a "multiple state" Marking. It means a subject can be
* in many state at the same time.
*
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*/
class PropertyAccessorMarkingStore implements MarkingStoreInterface
class MultipleStateMarkingStore implements MarkingStoreInterface
{
private $property;
private $propertyAccessor;
/**
* PropertyAccessorMarkingStore constructor.
* MultipleStateMarkingStore constructor.
*
* @param string $property
* @param PropertyAccessorInterface|null $propertyAccessor
@@ -16,17 +16,20 @@
use Symfony\Component\Workflow\Marking;
/**
* ScalarMarkingStore.
* SingleStateMarkingStore stores the marking into a property of the subject.
*
* This store deals with a "single state" Marking. It means a subject can be in
* one and only state at the same time.
*
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*/
class ScalarMarkingStore implements MarkingStoreInterface
class SingleStateMarkingStore implements MarkingStoreInterface
{
private $property;
private $propertyAccessor;
/**
* ScalarMarkingStore constructor.
* SingleStateMarkingStore constructor.
*
* @param string $property
* @param PropertyAccessorInterface|null $propertyAccessor
@@ -4,7 +4,7 @@
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
use Symfony\Component\Workflow\MarkingStore\ScalarMarkingStore;
use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore;
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
@@ -13,6 +13,6 @@ class StateMachine extends Workflow
{
public function __construct(Definition $definition, MarkingStoreInterface $markingStore = null, EventDispatcherInterface $dispatcher = null, $name = 'unnamed')
{
parent::__construct($definition, $markingStore ?: new ScalarMarkingStore(), $dispatcher, $name);
parent::__construct($definition, $markingStore ?: new SingleStateMarkingStore(), $dispatcher, $name);
}
}
@@ -6,7 +6,7 @@
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Workflow\Definition;
use Symfony\Component\Workflow\EventListener\AuditTrailListener;
use Symfony\Component\Workflow\MarkingStore\PropertyAccessorMarkingStore;
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
use Symfony\Component\Workflow\Transition;
use Symfony\Component\Workflow\Workflow;
@@ -29,7 +29,7 @@ public function testItWorks()
$ed = new EventDispatcher();
$ed->addSubscriber(new AuditTrailListener($logger));
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore(), $ed);
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $ed);
$workflow->apply($object, 't1');
@@ -3,16 +3,16 @@
namespace Symfony\Component\Workflow\Tests\MarkingStore;
use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\MarkingStore\PropertyAccessorMarkingStore;
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
class PropertyAccessorMarkingStoreTest extends \PHPUnit_Framework_TestCase
class MultipleStateMarkingStoreTest extends \PHPUnit_Framework_TestCase
{
public function testGetSetMarking()
{
$subject = new \stdClass();
$subject->myMarks = null;
$markingStore = new PropertyAccessorMarkingStore('myMarks');
$markingStore = new MultipleStateMarkingStore('myMarks');
$marking = $markingStore->getMarking($subject);
@@ -3,16 +3,16 @@
namespace Symfony\Component\Workflow\Tests\MarkingStore;
use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\MarkingStore\ScalarMarkingStore;
use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore;
class ScalarMarkingStoreTest extends \PHPUnit_Framework_TestCase
class SingleStateMarkingStoreTest extends \PHPUnit_Framework_TestCase
{
public function testGetSetMarking()
{
$subject = new \stdClass();
$subject->myMarks = null;
$markingStore = new ScalarMarkingStore('myMarks');
$markingStore = new SingleStateMarkingStore('myMarks');
$marking = $markingStore->getMarking($subject);
@@ -8,7 +8,7 @@
use Symfony\Component\Workflow\Event\GuardEvent;
use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
use Symfony\Component\Workflow\MarkingStore\PropertyAccessorMarkingStore;
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
use Symfony\Component\Workflow\Transition;
use Symfony\Component\Workflow\Workflow;
@@ -35,7 +35,7 @@ public function testGetMarkingWithEmptyDefinition()
{
$subject = new \stdClass();
$subject->marking = null;
$workflow = new Workflow(new Definition(array(), array()), new PropertyAccessorMarkingStore());
$workflow = new Workflow(new Definition(array(), array()), new MultipleStateMarkingStore());
$workflow->getMarking($subject);
}
@@ -49,7 +49,7 @@ public function testGetMarkingWithImpossiblePlace()
$subject = new \stdClass();
$subject->marking = null;
$subject->marking = array('nope' => true);
$workflow = new Workflow(new Definition(array(), array()), new PropertyAccessorMarkingStore());
$workflow = new Workflow(new Definition(array(), array()), new MultipleStateMarkingStore());
$workflow->getMarking($subject);
}
@@ -59,7 +59,7 @@ public function testGetMarkingWithEmptyInitialMarking()
$definition = $this->createComplexWorkflow();
$subject = new \stdClass();
$subject->marking = null;
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore());
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
$marking = $workflow->getMarking($subject);
@@ -74,7 +74,7 @@ public function testGetMarkingWithExistingMarking()
$subject = new \stdClass();
$subject->marking = null;
$subject->marking = array('b' => 1, 'c' => 1);
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore());
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
$marking = $workflow->getMarking($subject);
@@ -92,7 +92,7 @@ public function testCanWithUnexistingTransition()
$definition = $this->createComplexWorkflow();
$subject = new \stdClass();
$subject->marking = null;
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore());
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
$workflow->can($subject, 'foobar');
}
@@ -102,7 +102,7 @@ public function testCan()
$definition = $this->createComplexWorkflow();
$subject = new \stdClass();
$subject->marking = null;
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore());
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
$this->assertTrue($workflow->can($subject, 't1'));
$this->assertFalse($workflow->can($subject, 't2'));
@@ -117,7 +117,7 @@ public function testCanWithGuard()
$eventDispatcher->addListener('workflow.workflow_name.guard.t1', function (GuardEvent $event) {
$event->setBlocked(true);
});
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore(), $eventDispatcher, 'workflow_name');
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
$this->assertFalse($workflow->can($subject, 't1'));
}
@@ -131,7 +131,7 @@ public function testApplyWithImpossibleTransition()
$definition = $this->createComplexWorkflow();
$subject = new \stdClass();
$subject->marking = null;
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore());
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
$workflow->apply($subject, 't2');
}
@@ -141,7 +141,7 @@ public function testApply()
$definition = $this->createComplexWorkflow();
$subject = new \stdClass();
$subject->marking = null;
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore());
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
$marking = $workflow->apply($subject, 't1');
@@ -157,7 +157,7 @@ public function testApplyWithEventDispatcher()
$subject = new \stdClass();
$subject->marking = null;
$eventDispatcher = new EventDispatcherMock();
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore(), $eventDispatcher, 'workflow_name');
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
$eventNameExpected = array(
'workflow.guard',
@@ -194,7 +194,7 @@ public function testGetEnabledTransitions()
$eventDispatcher->addListener('workflow.workflow_name.guard.t1', function (GuardEvent $event) {
$event->setBlocked(true);
});
$workflow = new Workflow($definition, new PropertyAccessorMarkingStore(), $eventDispatcher, 'workflow_name');
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
$this->assertEmpty($workflow->getEnabledTransitions($subject));
@@ -16,7 +16,7 @@
use Symfony\Component\Workflow\Event\GuardEvent;
use Symfony\Component\Workflow\Exception\LogicException;
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
use Symfony\Component\Workflow\MarkingStore\PropertyAccessorMarkingStore;
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
/**
* @author Fabien Potencier <fabien@symfony.com>
@@ -33,7 +33,7 @@ class Workflow
public function __construct(Definition $definition, MarkingStoreInterface $markingStore = null, EventDispatcherInterface $dispatcher = null, $name = 'unnamed')
{
$this->definition = $definition;
$this->markingStore = $markingStore ?: new PropertyAccessorMarkingStore();
$this->markingStore = $markingStore ?: new MultipleStateMarkingStore();
$this->dispatcher = $dispatcher;
$this->name = $name;
}

0 comments on commit 08464c9

Please sign in to comment.