Menu

[r14]: / trunk / src / PHPCallGraphCli.php  Maximize  Restore  History

Download this file

195 lines (174 with data), 6.6 kB

  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
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Console front-end to use PHPCallGraph from the command line
*
* PHP version 5
*
* This file is part of PHPCallGraph.
*
* PHPCallGraph is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* PHPCallGraph is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package PHPCallGraph
* @author Falko Menge <fakko at users dot sourceforge dot net>
* @copyright 2007 Falko Menge
* @license http://www.gnu.org/licenses/gpl.txt GNU General Public License
*/
// include PHPCallGraph library
require_once 'PHPCallGraph.php';
/**
* console front-end to use PHPCallGraph from the command line
*
* This class requires eZ Components autoloader to be configured
* because it uses ezcConsoleTools
*/
class PHPCallGraphCli {
/**
* @return PHPCallGraphCli
*/
public function __construct() {
}
/**
* starts the command line interface for PHPCallGraph
* @return void
*/
public function run() {
$input = new ezcConsoleInput();
$formatOption = $input->registerOption(
new ezcConsoleOption(
'f',
'format',
ezcConsoleInput::TYPE_STRING
)
);
$formatOption->shorthelp = "set output format; can be 'txt', 'cga' or one of the formats supported by dot";
$outputfileOption = $input->registerOption(
new ezcConsoleOption(
'o',
'outputfile',
ezcConsoleInput::TYPE_STRING
)
);
$outputfileOption->shorthelp = 'output file';
$recursiveOption = $input->registerOption(
new ezcConsoleOption(
'r',
'recursive',
ezcConsoleInput::TYPE_NONE
)
);
$recursiveOption->shorthelp = 'analyze directories recursive';
$dotcommandOption = $input->registerOption(
new ezcConsoleOption(
'd',
'dotcommand',
ezcConsoleInput::TYPE_STRING
)
);
$dotcommandOption->shorthelp = 'set dot command';
$noexternalcallsOption = $input->registerOption(
new ezcConsoleOption(
'n',
'noexternalcalls',
ezcConsoleInput::TYPE_NONE
)
);
$noexternalcallsOption->shorthelp = 'do not show calls to methods or functions which are external to a class';
$phpfunctionsOption = $input->registerOption(
new ezcConsoleOption(
'p',
'phpfunctions',
ezcConsoleInput::TYPE_NONE
)
);
$phpfunctionsOption->shorthelp = 'show calls to internal PHP functions';
$verboseOption = $input->registerOption(
new ezcConsoleOption(
'v',
'verbose',
ezcConsoleInput::TYPE_NONE
)
);
$verboseOption->shorthelp = 'verbose mode for text output format';
$helpOption = $input->registerOption(
new ezcConsoleOption(
'h',
'help'
)
);
$helpOption->isHelpOption = true; // if parameter is set, all options marked as mandatory may be skipped
$helpOption->shorthelp = 'display help';
$input->argumentDefinition = new ezcConsoleArguments();
$input->argumentDefinition[0] = new ezcConsoleArgument(
'sources',
ezcConsoleInput::TYPE_STRING,
'files and/or directories to analyze',
'',
true,
true
);
try {
$input->process();
} catch (ezcConsoleOptionException $e) {
die($e->getMessage() . "\nTry option -h to get a list of available options.\n");
} catch (ezcConsoleArgumentMandatoryViolationException $e) {
die($e->getMessage() . "\nTry option -h to get a list of available options.\n");
}
if ($helpOption->value === true) {
echo $input->getHelpText(
"\nPHPCallGraph v" . PHPCallGraph::VERSION . "\n\n"
. "A tool to generate static call graphs for PHP source code.\n"
. "The graphs can be leveraged to gain a better understanding of\n"
. "large software systems or even to debunk design flaws in them."
);
} else {
// configure output driver according to format option
switch ($formatOption->value) {
case 'cga':
require_once 'drivers/CgaStaticTraceDriver.php';
$driver = new CgaStaticTraceDriver();
break;
case false:
case 'txt':
require_once 'drivers/TextDriver.php';
$driver = new TextDriver($verboseOption->value);
break;
default:
require_once 'drivers/GraphVizDriver.php';
$driver = new GraphVizDriver();
$driver->setOutputFormat($formatOption->value);
if ($dotcommandOption->value !== false) {
$driver->setDotCommand($dotcommandOption->value);
}
}
// configure generator
$phpcg = new PHPCallGraph($driver);
if ($noexternalcallsOption->value !== false) {
$phpcg->setShowExternalCalls(false);
}
if ($phpfunctionsOption->value !== false) {
$phpcg->setShowInternalFunctions(true);
}
// start generation
$phpcg->parse($input->getArguments(), $recursiveOption->value);
// output result
if ($outputfileOption->value === false) {
echo $phpcg;
} else {
$phpcg->save($outputfileOption->value);
}
}
}
}
?>