/** * Visits the node, checks contraints and calls verify on each node. * * Returns true if the node was verified. False if it was already * verified. * * @param ezcWorkflowVisitable $visitable * @throws ezcWorkflowInvalidWorkflowException * @return boolean */ public function visit(ezcWorkflowVisitable $visitable) { if ($visitable instanceof ezcWorkflow) { foreach ($visitable->nodes as $node) { if ($node instanceof ezcWorkflowNodeStart && !$node instanceof ezcWorkflowNodeFinally) { $this->numStartNodes++; if ($this->numStartNodes > 1) { throw new ezcWorkflowInvalidWorkflowException('A workflow may have only one start node.'); } } if ($node instanceof ezcWorkflowNodeFinally) { $this->numFinallyNodes++; if ($this->numFinallyNodes > 1) { throw new ezcWorkflowInvalidWorkflowException('A workflow may have only one finally node.'); } } } } if ($visitable instanceof ezcWorkflowNode) { $id = $visitable->getId(); if (isset($this->visited[$id])) { return false; } $this->visited[$id] = true; $visitable->verify(); } return true; }
/** * Visits the node and resets it. * * Returns true if the node was reset. False if it was already * reset. * * @param ezcWorkflowVisitable $visitable * @return boolean */ public function visit(ezcWorkflowVisitable $visitable) { if ($visitable instanceof ezcWorkflowNode) { $id = $visitable->getId(); if (isset($this->visited[$id])) { return false; } $this->visited[$id] = true; $visitable->initState(); } return true; }
/** * Visits the node, adds it to the list of nodes. * * Returns true if the node was added. False if it was already in the list * of nodes. * * @param ezcWorkflowVisitable $visitable * @return boolean */ public function visit(ezcWorkflowVisitable $visitable) { if ($visitable instanceof ezcWorkflowNode) { $id = $visitable->getId(); if ($id !== false) { $this->maxNodeId = max($this->maxNodeId, $id); } if (isset($this->nodes[$id])) { return false; } $this->nodes[$id] = $visitable; } return true; }
/** * Visits the node, adds it to the list of nodes. * * Returns true if the node was added. False if it was already in the list * of nodes. * * @param ezcWorkflowVisitable $visitable * @return boolean */ public function visit(ezcWorkflowVisitable $visitable) { if ($visitable instanceof ezcWorkflow) { $visitor = new ezcWorkflowVisitorMaxNodeIdFinder($visitable); $this->nextId = $visitor->getMaxNodeId() + 1; unset($visitor); if ($visitable->startNode->getId() === false) { $visitable->startNode->setId($this->nextId++); } if ($visitable->endNode->getId() === false) { $visitable->endNode->setId($this->nextId++); } if (count($visitable->finallyNode->getOutNodes()) > 0) { $this->finallyNode = $visitable->finallyNode; if ($visitable->finallyNode->getId() === false) { $visitable->finallyNode->setId($this->nextId++); } } } else { if ($visitable instanceof ezcWorkflowNode) { $id = $visitable->getId(); if ($id === false) { $id = $this->nextId++; $visitable->setId($id); } if (isset($this->nodes[$id])) { return false; } $this->nodes[$id] = $visitable; } } return true; }
/** * Perform the visit. * * @param ezcWorkflowVisitable $visitable */ protected function doVisit(ezcWorkflowVisitable $visitable) { if ($visitable instanceof ezcWorkflow) { foreach ($visitable->nodes as $node) { if ($node instanceof ezcWorkflowNodeStart && !$node instanceof ezcWorkflowNodeFinally) { $this->numStartNodes++; if ($this->numStartNodes > 1) { throw new ezcWorkflowInvalidWorkflowException('A workflow may have only one start node.'); } } if ($node instanceof ezcWorkflowNodeFinally) { $this->numFinallyNodes++; if ($this->numFinallyNodes > 1) { throw new ezcWorkflowInvalidWorkflowException('A workflow may have only one finally node.'); } } } } if ($visitable instanceof ezcWorkflowNode) { $visitable->verify(); } }
/** * Perform the visit. * * @param ezcWorkflowVisitable $visitable */ protected function doVisit(ezcWorkflowVisitable $visitable) { if ($visitable instanceof ezcWorkflow) { $visitable->startNode->setId(++$this->nextId); $this->startNode = $visitable->startNode; $visitable->endNode->setId(++$this->nextId); $this->endNode = $visitable->endNode; if (count($visitable->finallyNode->getOutNodes()) > 0) { $this->finallyNode = $visitable->finallyNode; $visitable->finallyNode->setId(++$this->nextId); } } else { if ($visitable instanceof ezcWorkflowNode) { if ($visitable !== $this->startNode && $visitable !== $this->endNode && $visitable !== $this->finallyNode) { $id = ++$this->nextId; $visitable->setId($id); } else { $id = $visitable->getId(); } $this->nodes[$id] = $visitable; } } }
/** * Perform the visit. * * @param ezcWorkflowVisitable $visitable */ protected function doVisit(ezcWorkflowVisitable $visitable) { if ($visitable instanceof ezcWorkflow) { $this->workflowName = $visitable->name; // The following line of code is not a no-op. It triggers the // ezcWorkflow::__get() method, thus initializing the respective // ezcWorkflowVisitorNodeCollector object. $visitable->nodes; } if ($visitable instanceof ezcWorkflowNode) { $id = $visitable->getId(); if (in_array($id, $this->options['highlightedNodes'])) { $color = $this->options['colorHighlighted']; } else { $color = $this->options['colorNormal']; } if (!isset($this->nodes[$id])) { $this->nodes[$id] = array('label' => (string) $visitable, 'color' => $color); } $outNodes = array(); foreach ($visitable->getOutNodes() as $outNode) { $label = ''; if ($visitable instanceof ezcWorkflowNodeConditionalBranch) { $condition = $visitable->getCondition($outNode); if ($condition !== false) { $label = ' [label="' . $condition . '"]'; } } $outNodes[] = array($outNode->getId(), $label); } $this->edges[$id] = $outNodes; } }
/** * Perform the visit. * * @param ezcWorkflowVisitable $visitable */ protected function doVisit(ezcWorkflowVisitable $visitable) { if ($visitable instanceof ezcWorkflowNode) { $visitable->initState(); } }