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 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 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; }