Last active
December 9, 2016 19:11
-
-
Save simshaun/60c4826b5ae88328b05043857b8107ef to your computer and use it in GitHub Desktop.
Symfony Workflow integration with multiple $tos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
framework: | |
workflows: | |
pull_request: | |
type: 'state_machine' | |
supports: | |
- AppBundle\Entity\PullRequest | |
places: | |
- init | |
- foo | |
- bar | |
transitions: | |
submit: | |
from: init | |
to: [foo, bar] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__.'/vendor/autoload.php'; | |
use Symfony\Component\Workflow\DefinitionBuilder; | |
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore; | |
use Symfony\Component\Workflow\Transition; | |
use Symfony\Component\Workflow\Workflow; | |
$builder = new DefinitionBuilder(); | |
$builder->addPlaces(['init', 'foo', 'bar']); | |
$builder->addTransition(new Transition('submit', 'init', ['foo', 'bar'])); | |
$definition = $builder->build(); | |
$workflow = new Workflow($definition, new MultipleStateMarkingStore()); | |
$subject = new \stdClass(); | |
$subject->marking = null; | |
$workflow->apply($subject, 'submit'); | |
assert($subject->marking === ['foo' => 1, 'bar' => 1]); | |
// Works |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @var Workflow $stateMachine */ | |
$stateMachine = $this->container->get('state_machine.pull_request'); | |
$pr = new PullRequest(); | |
$pr->marking = ['start']; | |
$stateMachine->apply($pr, 'submit'); | |
// Result: | |
InvalidDefinitionException in StateMachineValidator.php line 40: | |
A transition from a place/state must have an unique name. Multiple transitions named "submit" from place/state "init" where found on StateMachine "pull_request" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment