-
Notifications
You must be signed in to change notification settings - Fork 1
/
graph.php
37 lines (32 loc) · 1.02 KB
/
graph.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
require_once __DIR__.'/vendor/autoload.php';
use Example\Order\Process\Postpayment;
use Example\Order\Process\Prepayment;
use Metabor\NamedCollection;
use Metabor\Statemachine\Graph\GraphBuilder;
use Fhaculty\Graph\Graph;
use Graphp\GraphViz\GraphViz;
try {
$processes = new NamedCollection();
$processes->add(new Prepayment());
$processes->add(new Postpayment());
if (isset($_GET['process'])) {
$processName = strtolower($_GET['process']);
if ($processes->has($processName)) {
$process = $processes->get($processName);
}
}
if (!isset($process)) {
$processNames = $processes->getNames();
$processName = reset($processNames);
$process = $processes->get($processName);
}
$graph = new Graph();
$builder = new GraphBuilder($graph);
$builder->addStateCollection($process);
$viz = new GraphViz();
$viz->setFormat('svg');
echo file_get_contents($viz->createImageFile($graph));
} catch (Exception $e) {
echo $e->getMessage();
}