'Graph PHP entities', 'aliases' => array('hier'), 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL, 'core' => array('7+'), 'drupal dependencies' => array(), '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; } /** * Helper to enumerate GraphViz format filters on the current system. * * @return array * An array of format names. */ 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; } /** * Validation callback for classgraph. */ function drush_classgrapher_classgraph_validate() { if (!@include_once 'Image/GraphViz.php') { drush_set_error('classgrapher', 'PEAR Image_Graphviz not found.'); } } /** * Command callback for classgraph. */ function drush_classgrapher_classgraph($base) { $logger = new ClassGrapherLogger(); $imager = drush_get_option('cgimager'); if (!isset($imager) || $imager === FALSE) { $debug = 'dot'; } $debug = drush_get_option('cgdebug'); if (!isset($debug) || $debug === FALSE) { $this->debugLevel = WATCHDOG_INFO; } else { $this->debugLevel = (int) $debug; } $info = libraries_load('grammar_parser'); $graph = new ClassGrapherGraph($base, $logger); echo $graph->build($imager); }