Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function visualize(StateMachine $machine)
 {
     $graph = $this->viz->getGraph();
     // create some cities
     foreach ($machine->getStates() as $state) {
         $this->states[$state->getName()] = $this->addNode($graph, $state, $machine->isCurrentState($state->getName()), $state->getType() == StateInterface::TYPE_INITIAL, $state->getType() == StateInterface::TYPE_FINAL);
         if ($this->renderActions) {
             $v1 = $this->states[$state->getName()];
             $v2 = null;
             foreach ($state->getActions() as $action) {
                 $v2 = $this->addAction($graph, $action);
                 $this->addEdge($v1, $v2);
                 $v1 = $v2;
             }
         }
     }
     foreach ($machine->getTransitions() as $index => $transition) {
         $vertex = $this->states[$transition->getInitialState()->getName()];
         $vertexTo = $this->states[$transition->getTransitionTo()->getName()];
         if ($transition->getCondition()) {
             $condition = $this->addCondition($graph, $transition->getCondition(), $index);
             $this->addEdge($vertex, $condition);
             $vertex = $condition;
         }
         $this->addEdge($vertex, $vertexTo);
     }
     return $this->viz->createImageHtml();
 }
Пример #2
0
        $reversePayment = new Transition($committed, $reversed);
        $this->addTransition($authPayment);
        $this->addTransition($commitPayment);
        $this->addTransition($approvePayment);
        $this->addTransition($commitPaymentReview);
        $this->addTransition($reversePayment);
        $this->addTrigger('authorize', array($authPayment));
        $this->addTrigger('commit', array($commitPayment, $commitPaymentReview, $approvePayment));
        $this->addTrigger('approve', array($approvePayment));
        // Set the current state of the object
        $this->setCurrentState($this->payment->state);
    }
}
// Start up the machine
$payment = new Payment();
$stateMachine = new PaymentMachine('test', $payment);
// Run tests
$stateMachine->trigger('authorize');
$stateMachine->trigger('commit');
// Render a GraphViz graph
$viz = new GraphViz(new Graph());
$viz->setExecutable('');
// Path to dot.exe
$viz->setFormat('svg');
$render = new GraphRender($viz);
// Set the executable path and then uncomment this line
// echo $render->visualize($stateMachine);
// Render an ASCII graph
echo "<br/><br/>";
$render = new GraphAscii();
echo nl2br($render->visualize($stateMachine));
Пример #3
0
 public function getOutput(Graph $graph)
 {
     $graphviz = new GraphViz($graph);
     return $graphviz->createScript();
 }
Пример #4
0
 private function getDotScriptForGraph(Graph $graph)
 {
     $graphviz = new GraphViz($graph);
     return $graphviz->createScript();
 }
Пример #5
0
 public function getOutput(Graph $graph)
 {
     $graphviz = new GraphViz($graph);
     $graphviz->setFormat($this->format);
     return $graphviz->createImageData();
 }
 protected function saveGraphInFile(Graph $graph, $projectName)
 {
     $localTargetFile = $this->getLocalTargetFile($projectName);
     $remoteTargetFile = $this->getRemoteTargetFile($projectName);
     $graphviz = new GraphViz($graph);
     $graphviz->setFormat($this->format);
     $tmpDir = sprintf('%s/jarvis/composer_graph_dependencies', $this->getCacheDir());
     $tmpFile = tempnam($tmpDir, 'composer_graph_dependencies');
     if ($tmpFile === false) {
         throw new UnexpectedValueException('Unable to get temporary file name for graphviz script');
     }
     $ret = file_put_contents($tmpFile, $graphviz->createScript(), LOCK_EX);
     if ($ret === false) {
         throw new UnexpectedValueException(sprintf('Unable to write graphviz script to temporary file in %s', $tmpDir));
     }
     $remoteGraphvizScriptFile = sprintf('%s/%s.%s', pathinfo($remoteTargetFile, PATHINFO_DIRNAME), pathinfo($remoteTargetFile, PATHINFO_FILENAME), 'dot');
     $this->getRemoteFilesystem()->copyLocalFileToRemote($tmpFile, $remoteGraphvizScriptFile);
     $commandLine = sprintf('%s -T %s %s -o %s', $this->graphVizExecutable, $this->format, $remoteGraphvizScriptFile, $remoteTargetFile);
     $this->getSshExec()->exec($commandLine);
     $this->getRemoteFilesystem()->copyRemoteFileToLocal($remoteTargetFile, $localTargetFile);
     return $localTargetFile;
 }
Пример #7
0
 public function createVertexExtension($extension)
 {
     if ($extension instanceof ReflectionExtension) {
         $reflection = $class;
         $extension = $reflection->getName();
     } else {
         $reflection = new ReflectionExtension($extension);
     }
     $vertex = $this->graph->createVertex($extension);
     $vertex->setLayoutAttribute('shape', 'record');
     $vertex->setLayoutAttribute('label', GraphViz::raw($this->getLabelRecordExtension($reflection)));
     return $vertex;
 }