Guest User

Untitled

a guest
Jun 17th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <?php
  2.  
  3. use pdepend\reflection\Autoloader;
  4. use pdepend\reflection\ReflectionSession;
  5. use pdepend\reflection\resolvers\PearNamingResolver;
  6.  
  7. if ( !isset( $argv[1] ) )
  8. {
  9. die( 'Missing dir.' );
  10. }
  11.  
  12. include_once '/home/dotxp/dev/PHP/staticReflection/src/main/php/pdepend/reflection/Autoloader.php';
  13.  
  14. spl_autoload_register( array( new Autoloader(), 'autoload' ) );
  15.  
  16. $classes = array();
  17. $intClasses = array();
  18. $inheritance = array();
  19. $implemented = array();
  20.  
  21. $session = ReflectionSession::createDefaultSession(
  22. new PearNamingResolver( array( $argv[1] ) )
  23. );
  24.  
  25. $query = $session->createDirectoryQuery();
  26. foreach ( $query->find( $argv[1] ) as $class )
  27. {
  28. if ( strpos( $class->getFileName(), 'tests/' ) !== false )
  29. {
  30. continue;
  31. }
  32.  
  33. $fullName = fqn( $class );
  34.  
  35. $classes[$fullName] = true;
  36. $intClasses[$fullName] = true;
  37.  
  38. $parent = $class->getParentClass();
  39.  
  40. if ( $parent !== false )
  41. {
  42. $classes[fqn( $parent )] = true;
  43. $inheritance[fqn( $class )] = fqn( $parent );
  44. }
  45. }
  46.  
  47. function fqn( $class )
  48. {
  49. return $class->getNamespaceName() . '\\' . $class->getName();
  50. }
  51.  
  52. echo "\n\n";
  53. echo "digraph ClassDiagram {\n";
  54. echo " rankdir=BT\n\n";
  55.  
  56. classNode( 'External', false );
  57.  
  58. foreach ( $classes as $className => $dummy )
  59. {
  60. if ( isset( $intClasses[$className] ) )
  61. {
  62. classNode( $className, true );
  63. }
  64. }
  65.  
  66. function classNode( $className, $isInternal )
  67. {
  68. echo sprintf(
  69. " %s [shape=box,color=black,fontcolor=%s,label=\"%s\"]\n",
  70. stripslashes( $className ),
  71. ( $isInternal ? 'black' : '"#c0c0c0"' ),
  72. addslashes( $className )
  73. );
  74. }
  75.  
  76. echo "\n";
  77.  
  78. foreach ( $inheritance as $from => $to )
  79. {
  80. echo sprintf(
  81. " %s -> %s\n",
  82. stripslashes( $from ),
  83. ( isset( $intClasses[$to] ) ? stripslashes( $to ) : "External" )
  84. );
  85. }
  86.  
  87. echo "}\n";
Add Comment
Please, Sign In to add comment