Create a gist now

Instantly share code, notes, and snippets.

@qcmnagai /workflow.php Secret
Last active Dec 8, 2016

What would you like to do?
Pull Reuest Workflow Sample
require './vendor/autoload.php';
use Symfony\Component\Workflow\DefinitionBuilder;
use Symfony\Component\Workflow\Transition;
use Symfony\Component\Workflow\StateMachine;
class PullRequest {
private $marking = 'ready';
public function getMarking()
return $this->marking;
public function setMarking($marking)
$this->marking = $marking;
$builder = new DefinitionBuilder();
$builder->addPlaces(['ready', 'wip', 'in-review', 'merged']);
$builder->addTransition(new Transition('start-work', 'ready', 'wip'));
$builder->addTransition(new Transition('request-review', 'wip', 'in-review'));
$builder->addTransition(new Transition('feedback', 'in-review', 'wip'));
$builder->addTransition(new Transition('merge', 'in-review', 'merged'));
$definition = $builder->build();
$workflow = new StateMachine($definition);
$pr = new PullRequest();
$workflow->can($pr, 'hoge'); // Thow Symfony\Component\Workflow\Exception\LogicException
$workflow->can($pr, 'merge'); // False
$workflow->apply($pr, 'merge'); // Thow Symfony\Component\Workflow\Exception\LogicException
$workflow->can($pr, 'start-work'); // True
$workflow->apply($pr, 'start-work');
$workflow->can($pr, 'request-review'); // True
$workflow->getEnabledTransitions($pr); // ['feedback', 'merge']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment