class_grapher_demo.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * This code uses several external classes:
  4. *
  5. * - PSR0-compliant
  6. * - OSInet Class_Grapher package.
  7. * - PEAR
  8. * - Image_GraphViz
  9. * - Miscellaneous
  10. * - grammar_parser package 7.x -
  11. * - http://drupal.org/project/grammar_parser
  12. * - does not depend on Drupal, but can be used within Drupal/Drush either
  13. * as a module or a Libraries-compatible PHP library.
  14. *
  15. * It also depends on
  16. * - GraphViz - http://www.graphviz.org/
  17. * - PHP 5.3
  18. */
  19. // To use, adjust the grammar parser path to your deployment.
  20. $gpPath = '../../d7/sites/all/libraries/grammar_parser/engine';
  21. use \OSInet\Class_Grapher\Logger;
  22. use \OSInet\Class_Grapher\Graph;
  23. // Image_GraphViz throws notices, so keep it quiet.
  24. error_reporting(E_WARNING);
  25. // Include the OSInet PSR0 autoloader.
  26. require __DIR__ .'/../../misc/psr0.php';
  27. // Load Image_GraphViz: PEAR, not PSR0.
  28. require 'Image/GraphViz.php';
  29. // Load grammar_parser. Not autoloadable.
  30. $gpFiles = array('parser', 'editor', 'list', 'object', 'reader', 'writer');
  31. foreach ($gpFiles as $file) {
  32. require "$gpPath/$file.inc";
  33. }
  34. // Initialize PSR0 autoloader for remaining classes.
  35. spl_autoload_register('psr0_autoload', TRUE);
  36. // Suggestion: look at Drupal 8 core/lib/Drupal/Core/Database directory
  37. $base = $argv;
  38. // Ignore script itself.
  39. array_shift($base);
  40. $logger = new Logger(LOG_DEBUG);
  41. $imager = 'dot';
  42. $format = 'svg';
  43. $graph = new Graph($base, $logger);
  44. echo $graph->build($imager, $format);