Skip to content

Commit

Permalink
minor #20462 [Workfow] Rename current MarkingStore (lyrixx)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.2-dev branch.

Discussion
----------

[Workfow] Rename current MarkingStore

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | yes (in un-released branch)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

* 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).

---

Note: I did that to ease the on-boarding

Commits
-------

08464c9 [Workfow] Rename current MarkingStore
  • Loading branch information
lyrixx committed Nov 9, 2016
2 parents 61b1334 + 08464c9 commit eb14981
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'workflows' => array(
'my_workflow' => array(
'marking_store' => array(
'type' => 'property_accessor',
'type' => 'multiple_state',
),
'supports' => array(
FrameworkExtensionTest::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ framework:
workflows:
my_workflow:
marking_store:
type: property_accessor
type: multiple_state
supports:
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
places:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Workflow/StateMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
24 changes: 12 additions & 12 deletions src/Symfony/Component/Workflow/Tests/WorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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');
}
Expand All @@ -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'));
Expand All @@ -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'));
}
Expand All @@ -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');
}
Expand All @@ -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');

Expand All @@ -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',
Expand Down Expand Up @@ -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));

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Workflow/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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;
}
Expand Down

0 comments on commit eb14981

Please sign in to comment.