Skip to content

Instantly share code, notes, and snippets.

@simshaun
Last active December 9, 2016 19:11
Show Gist options
  • Save simshaun/60c4826b5ae88328b05043857b8107ef to your computer and use it in GitHub Desktop.
Save simshaun/60c4826b5ae88328b05043857b8107ef to your computer and use it in GitHub Desktop.
Symfony Workflow integration with multiple $tos
framework:
workflows:
pull_request:
type: 'state_machine'
supports:
- AppBundle\Entity\PullRequest
places:
- init
- foo
- bar
transitions:
submit:
from: init
to: [foo, bar]
<?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
/** @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