forked from sebastianbergmann/state
-
Notifications
You must be signed in to change notification settings - Fork 2
/
runViz.php
executable file
·93 lines (60 loc) · 2.41 KB
/
runViz.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env php
<?php
if (!file_exists(__DIR__ . '/../vendor/autoload.php')) {
die(
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
'wget https://getcomposer.org/composer.phar' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
}
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/autoload.php';
require __DIR__ . '/GenBase.php';
$base_dir = getcwd();
$defs_arg = str_replace(array('.', ' ', "\n", "\t", "\r"), '', $argv[1]);
$defs_loc = $base_dir.'/'.$defs_arg.'/';
$diagram_loc = $defs_loc.'/diagrams/';
$file_list = \djsharman\libraries\OS_DirFileList::getFileList($defs_loc, array(), true, array('xml'));
function checkDirExists($target_dir) {
$dir_exists = is_dir($target_dir);
if($dir_exists == false) {
$res = mkdir($target_dir, '755', true);
if($res == false) {
die('could not create gen directory');
}
}
}
checkDirExists($diagram_loc);
echo "===========================================\n";
echo "===========================================\n";
foreach($file_list as $file) {
$path_parts = pathinfo($file);
$className = $path_parts['filename'];
echo "Processing $className \n";
$interfaceName = $className.'State';
$abstractClassName = 'Abstract'.$interfaceName;
$parser = new SpecificationParser($file);
$operations = $parser->getOperations();
$queries = $parser->getQueries();
$states = $parser->getStates();
$conf_namespace = $parser->getNamespace();
$namespace = $conf_namespace.$className;
$use = str_replace('\\', '_', '\\'.$namespace);
ob_start();
echo 'digraph '.$use.' {' . PHP_EOL;
foreach ($states as $state => $data) {
foreach ($data['transitions'] as $operation => $to) {
echo '"'.$state.'" -> "'.$to.'" [ color=blue, label = "'.$operation.'"];'. PHP_EOL;
}
}
echo '}' . PHP_EOL;
$output = ob_get_contents();
ob_clean();
$dot_output_filename = $diagram_loc.$use.'.dot';
file_put_contents($dot_output_filename, $output);
$png_output_filename = $diagram_loc.$use.'.png';
shell_exec('/usr/bin/dot -Tpng '.$dot_output_filename.' -o '.$png_output_filename);
echo "===========================================\n";
}
echo "Done\n";
echo "===========================================\n";