public function testAddTransition() { $places = range('a', 'b'); $transition = new Transition('name', $places[0], $places[1]); $definition = new Definition($places, array($transition)); $this->assertCount(1, $definition->getTransitions()); $this->assertSame($transition, $definition->getTransitions()['name']); }
public function provideSimpleWorkflowDefinition() { $definition = new Definition(); $definition->addPlaces(range('a', 'c')); $definition->addTransition(new Transition('t1', 'a', 'b')); $definition->addTransition(new Transition('t2', 'b', 'c')); return $definition; }
public function validate(Definition $definition, $name) { if (!$this->singlePlace) { return; } foreach ($definition->getTransitions() as $transition) { if (1 < count($transition->getTos())) { throw new InvalidDefinitionException(sprintf('The marking store of workflow "%s" can not store many places. But the transition "%s" has too many output (%d). Only one is accepted.', $name, $transition->getName(), count($transition->getTos()))); } } }
/** * @internal */ protected function findEdges(Definition $definition) { $edges = array(); foreach ($definition->getTransitions() as $transition) { foreach ($transition->getFroms() as $from) { foreach ($transition->getTos() as $to) { $edges[$from][] = array('name' => $transition->getName(), 'to' => $to); } } } return $edges; }
public function __construct(Definition $definition, MarkingStoreInterface $markingStore, EventDispatcherInterface $dispatcher = null, $name = 'unnamed') { $this->definition = $definition; $this->markingStore = $markingStore; $this->dispatcher = $dispatcher; $this->name = $name; // If the marking can contain only one place, we should control the definition if ($markingStore instanceof UniqueTransitionOutputInterface) { foreach ($definition->getTransitions() as $transition) { if (1 < count($transition->getTos())) { throw new LogicException(sprintf('The marking store (%s) of workflow "%s" can not store many places. But the transition "%s" has too many output (%d). Only one is accepted.', get_class($markingStore), $this->name, $transition->getName(), count($transition->getTos()))); } } } }
public function validate(Definition $definition, $name) { $transitionFromNames = array(); foreach ($definition->getTransitions() as $transition) { // Make sure that each transition has exactly one TO if (1 !== count($transition->getTos())) { throw new InvalidDefinitionException(sprintf('A transition in StateMachine can only have one output. But the transition "%s" in StateMachine "%s" has %d outputs.', $transition->getName(), $name, count($transition->getTos()))); } // Make sure that each transition has exactly one FROM $froms = $transition->getFroms(); if (1 !== count($froms)) { throw new InvalidDefinitionException(sprintf('A transition in StateMachine can only have one input. But the transition "%s" in StateMachine "%s" has %d inputs.', $transition->getName(), $name, count($transition->getTos()))); } // Enforcing uniqueness of the names of transitions starting at each node $from = reset($froms); if (isset($transitionFromNames[$from][$transition->getName()])) { throw new InvalidDefinitionException(sprintf('A transition from a place/state must have an unique name. Multiple transitions named "%s" from place/state "%s" where found on StateMachine "%s". ', $transition->getName(), $from, $name)); } $transitionFromNames[$from][$transition->getName()] = true; } }
private function createComplexWorkflow() { $definition = new Definition(); $definition->addPlaces(range('a', 'g')); $definition->addTransition(new Transition('t1', 'a', array('b', 'c'))); $definition->addTransition(new Transition('t2', array('b', 'c'), 'd')); $definition->addTransition(new Transition('t3', 'd', 'e')); $definition->addTransition(new Transition('t4', 'd', 'f')); $definition->addTransition(new Transition('t5', 'e', 'g')); $definition->addTransition(new Transition('t6', 'f', 'g')); return $definition; // The graph looks like: // // +---+ +----+ +---+ +----+ +----+ +----+ +----+ +----+ +---+ // | a | --> | t1 | --> | c | --> | t2 | --> | d | --> | t4 | --> | f | --> | t6 | --> | g | // +---+ +----+ +---+ +----+ +----+ +----+ +----+ +----+ +---+ // | ^ | ^ // | | | | // v | v | // +----+ | +----+ +----+ +----+ | // | b | ----------------+ | t3 | --> | e | --> | t5 | -----------------+ // +----+ +----+ +----+ +----+ }
private function findEdges(Definition $definition) { $dotEdges = array(); foreach ($definition->getTransitions() as $transition) { foreach ($transition->getFroms() as $from) { $dotEdges[] = array('from' => $from, 'to' => $transition->getName(), 'direction' => 'from'); } foreach ($transition->getTos() as $to) { $dotEdges[] = array('from' => $transition->getName(), 'to' => $to, 'direction' => 'to'); } } return $dotEdges; }