Talk:Class tree

class-tree.php:

<?php

$lines = shell_exec("egrep -r '^class ' . | egrep -v extlib"); $lines = explode("\n", $lines); $lines = array_map('trim', $lines);

$classes = array; $filenames = array;

foreach ($lines as $line) { $line = preg_replace('!\s*//.*$!', '', $line); $line = preg_replace('!\s*implements.*$!', '', $line); $line = preg_replace('!\s*{.*$!', '', $line); if (!$line) { continue; }	if (preg_match('/^([^:]+):class\s+(\w+)(?:\s+extends\s+(\w+))?\s*$/', $line, $matches)) { @list($all, $filename, $classname, $parent) = $matches; if (isset($parent)) { $classes[$classname] = $parent; } else { $classes[$classname] = 'object'; }		$filenames[$classname] = $filename; } else { print "bad line: $line\n"; } }

function dumpTree($tree, $start='object', $level=0) {	if ($level > 0) { $heading = str_repeat('*', $level). ' ';		print "{$heading}{$start}\n"; }	foreach ($tree as $class => $parent) { if ($parent == $start) { dumpTree($tree, $class, $level+1); }	} }

ksort($classes); dumpTree($classes);