Example #1
0
 public function getOutput(Graph $graph)
 {
     $graphviz = new GraphViz($graph);
     $graphviz->setFormat($this->format);
     return $graphviz->createImageData();
 }
Example #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));
 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;
 }