123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- use \OSInet\Class_Grapher\Logger;
- use \OSInet\Class_Grapher\Graph;
- function classgrapher_drush_command() {
- $items = array();
- $items['classgraph'] = array(
- 'description' => 'Graph PHP entities',
- 'aliases' => array('hier'),
- 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
-
- 'core' => array('7'),
- 'drupal dependencies' => array('libraries'),
- 'arguments' => array(
- 'base' => 'The base directory below which to parse source files.',
- ),
- 'options' => array(
- 'cgdebug' => array(
- 'description' => 'Debug level: 0 to 7. Default to 6.',
- ),
- 'cgimager' => array(
- 'description' => 'Imager to use. Default to "dot". Use "dump" for a debug dump without GraphViz generation. Alternate imagers like circo, (s)fdp or twopi are converted to dot.',
- 'example-value' => 'dump,dot,neato',
- ),
- 'cgformat' => array(
- 'description' => 'Image format. Default to "svg". Not available with the dump imager.',
- 'example-value' => implode(',', _drush_classgrapher_get_formats()),
- ),
- ),
- );
- return $items;
- }
- function _drush_classgrapher_get_formats() {
- $dotCommand = 'dot -Tinvalid';
- $descriptorSpec = array(
- 0 => array('pipe', 'r'),
- 1 => array('pipe', 'w'),
- 2 => array('pipe', 'w'),
- );
- $process = proc_open($dotCommand, $descriptorSpec, $pipes, NULL, NULL);
- if (!is_resource($process)) {
- drush_set_error('classgrapher', 'GraphViz not found.');
- }
- fclose($pipes[0]);
- fclose($pipes[1]);
- $stderr = stream_get_contents($pipes[2]);
- proc_close($process);
- $sts = preg_match('/(.+):( .* )*/', $stderr, $matches);
- if (!$sts || count($matches) != 3) {
- drush_set_error('classgrapher', 'GraphViz did not return a usable formats list.');
- }
- $formats = explode(' ', trim($matches[2]));
- return $formats;
- }
- function drush_classgrapher_classgraph_validate() {
-
-
- if (function_exists('libraries_load')) {
- $info = libraries_load('grammar_parser');
- }
- else {
- drush_set_error('classgrapher', 'Libraries 7.x-2.x needed.');
- }
-
- $path = explode(':', ini_get('include_path'));
- $path[] = realpath(__DIR__ . '/../..');
- ini_set('include_path', implode(':', $path));
-
- include 'misc/psr0.php';
- spl_autoload_register('psr0_autoload');
-
-
-
-
- if (!@include_once 'Image/GraphViz.php') {
- drush_set_error('classgrapher', 'PEAR Image_Graphviz not found.');
- }
- }
- function drush_classgrapher_classgraph($base) {
- $optionDefaults = array(
- 'imager' => 'dot',
- 'debug' => WATCHDOG_INFO,
- 'format' => 'svg',
- );
- foreach ($optionDefaults as $name => $default) {
- $$name = drush_get_option("cg$name", $default);
- }
- $graph = new Graph($base, new Logger($debug));
- echo $graph->build($imager, $format);
- }
|