<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>Class dependency graph generation</title>
    <link>http://westhoffswelt.de/blog/class_dependency_graph_generation.html</link>
    <description>Generate a graphical representation of any given php class structure including the class hirachy and every interface it implements just by calling this single utility script.
</description>
    <language>en</language>
    <copyright>CC by-nc-sa</copyright>
    <managingEditor>Jakob Westhoff</managingEditor>
    <managingEditor>Jakob Westhoff &lt;jakob@westhoffswelt.de&gt;</managingEditor>
    <pubDate>Thu, 16 Nov 2006 19:33:00 +0000</pubDate>
    <lastBuildDate>Thu, 16 Nov 2006 19:33:00 +0000</lastBuildDate>
    <generator>eZ Components Feed dev (http://ezcomponents.org/docs/tutorials/Feed)</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <item>
      <title>Piccolino81 at Wed, 20 Jul 2011 14:06:26 +0200</title>
      <link>http://westhoffswelt.de/blog/class_dependency_graph_generation.html#comment_2</link>
      <description>On my iMac (Mac OS X 10.6.8) I had to change the 'sed' commands a little...&#13;
&#13;
...good luck :-)&#13;
&#13;
&#13;
#==============================================================================&#13;
#!/bin/bash&#13;
#&#13;
# Usage: script.sh &lt;name&gt; &lt;classprefix&gt; &lt;directory&gt;&#13;
#&#13;
# Mandatory graph configuration&#13;
#&#13;
GRAPHTYPE=svg&#13;
GRAPH=$1.svg&#13;
CLASSES=$3&#13;
CLASS_PREFIX=$2&#13;
TMPFILE=classgraph.dot&#13;
&#13;
#&#13;
# Optional graph configuration&#13;
#&#13;
CLASS_FONTSIZE=14&#13;
CLASS_FONTCOLOR=dodgerblue4&#13;
CLASS_BORDERCOLOR=dodgerblue1&#13;
CLASS_SHAPE=ellipse&#13;
CLASS_FONTNAME=Times-Roman&#13;
&#13;
INTERFACE_FONTSIZE=14&#13;
INTERFACE_FONTCOLOR=darkorange3&#13;
INTERFACE_BORDERCOLOR=darkorange1&#13;
INTERFACE_SHAPE=box&#13;
INTERFACE_FONTNAME=Times-Roman&#13;
&#13;
CLASS_INHERITANCE_COLOR=steelblue4&#13;
INTERFACE_INHERITANCE_COLOR=firebrick3&#13;
IMPLEMENTS_COLOR=tan2&#13;
&#13;
RANK_DISTANCE=1.0&#13;
&#13;
&#13;
#&#13;
# Graph generation&#13;
#&#13;
rm $TMPFILE 2&gt;/dev/null&#13;
&#13;
# Check for svg output and correct some font bugs&#13;
if [ "$GRAPHTYPE" = "svg" ]; then&#13;
	ORIG_CLASS_FONTSIZE=$CLASS_FONTSIZE&#13;
	ORIG_INTERFACE_FONTSIZE=$INTERFACE_FONTSIZE&#13;
	let CLASS_FONTSIZE=$CLASS_FONTSIZE+10&#13;
	let INTERFACE_FONTSIZE=$INTERFACE_FONTSIZE+10&#13;
fi&#13;
&#13;
# Start the graph&#13;
echo "digraph class_structure {" &gt;&gt;$TMPFILE&#13;
&#13;
# Set the rank distance&#13;
echo "ranksep=$RANK_DISTANCE" &gt;&gt;$TMPFILE&#13;
&#13;
# Set standard node look and feel&#13;
echo "node [fontsize=\"$CLASS_FONTSIZE\"]" &gt;&gt;$TMPFILE&#13;
&#13;
# Create a configured node for every class&#13;
echo "Creating node for every class."&#13;
for i in `find $CLASSES -iname "*.php"`; do grep "class $CLASS_PREFIX" "$i" | sed -e "s@^.*class \\($CLASS_PREFIX[a-zA-Z0-9_]*\\).*\$@\\1 [fontsize=\"$CLASS_FONTSIZE\", fontcolor=\"$CLASS_FONTCOLOR\", color=\"$CLASS_BORDERCOLOR\", shape=\"$CLASS_SHAPE\", fontname=\"$CLASS_FONTNAME\"]@" &gt;&gt;$TMPFILE; done&#13;
&#13;
# Create a configured node for the "Exception" class&#13;
echo "Exception [fontsize="$CLASS_FONTSIZE", fontcolor=\"$CLASS_FONTCOLOR\", color=\"$CLASS_BORDERCOLOR\", shape=\"$CLASS_SHAPE\", fontname=\"$CLASS_FONTNAME\"]" &gt;&gt;$TMPFILE&#13;
&#13;
# Create a configured node for every interface&#13;
echo "Creating node for every interface."&#13;
for i in `find $CLASSES -iname "*.php"`; do grep "interface $CLASS_PREFIX" "$i" | sed -e "s@^.*interface \\($CLASS_PREFIX[a-zA-Z0-9_]*\\).*\$@\1 [fontsize="$INTERFACE_FONTSIZE", fontcolor=\"$INTERFACE_FONTCOLOR\", color=\"$INTERFACE_BORDERCOLOR\", shape=\"$INTERFACE_SHAPE\", fontname=\"$INTERFACE_FONTNAME\"]@" &gt;&gt;$TMPFILE; done&#13;
&#13;
# Create edges for class inheritance&#13;
echo "Creating class inheritance edges."&#13;
for i in `find $CLASSES -iname "*.php"`; &#13;
do &#13;
	grep "class $CLASS_PREFIX" "$i" |&#13;
	grep "extends" |&#13;
###	sed -e "s@^.*class \\($CLASS_PREFIX[a-zA-Z0-9_]*\\).*extends \\([a-zA-Z0-9_]\\+\\).*\$@\\2-&gt;\\1 [dir=back, color=\"$CLASS_INHERITANCE_COLOR\"]@" &gt;&gt;$TMPFILE; 	&#13;
	sed -e "s/class \($CLASS_PREFIX[a-zA-Z0-9_]*\).*extends \($CLASS_PREFIX[a-zA-Z0-9_]*\)/\2 -&gt; \1 [dir=back, color=\"$CLASS_INHERITANCE_COLOR\"]/" &gt;&gt;$TMPFILE; &#13;
done&#13;
&#13;
# Create edges for interface inheritance&#13;
echo "Creating interface inheritance edges."&#13;
for i in `find $CLASSES -iname "*.php"`; &#13;
do &#13;
	grep "interface $CLASS_PREFIX" "$i" | &#13;
	grep "extends" | &#13;
###	sed -e "s@^.*interface \\($CLASS_PREFIX[a-zA-Z0-9_]*\\).*extends \\([a-zA-Z0-9_]\\+\\).*\$@\\2-&gt;\\1 [dir=back, color=\"$INTERFACE_INHERITANCE_COLOR\"]@" &gt;&gt;$TMPFILE; &#13;
	sed -e "s/interface \($CLASS_PREFIX[a-zA-Z0-9_]*\).*extends \($CLASS_PREFIX[a-zA-Z0-9_]*\).*/\2 -&gt; \1 [dir=back, color=\"$INTERFACE_INHERITANCE_COLOR\"]/" &gt;&gt;$TMPFILE;&#13;
done&#13;
&#13;
# Create edges for interface implementation&#13;
echo "Creating interface implementation edges."&#13;
for i in `find $CLASSES -iname "*.php"`; do &#13;
	grep "class $CLASS_PREFIX" "$i" | &#13;
	grep "implements" |&#13;
###	sed -e "s@^.*class \\($CLASS_PREFIX[a-zA-Z0-9_]*\\).*implements \\([a-zA-Z0-9_, ]\\+\\).*\$@{\\2}-&gt;\\1 [dir=back, color=\"$IMPLEMENTS_COLOR\"]@"|sed -e 's@ @@g'|sed -e 's@,@ @g' &gt;&gt;$TMPFILE; &#13;
	sed -e "s/class \($CLASS_PREFIX[a-zA-Z0-9_]*\).*implements \($CLASS_PREFIX[a-zA-Z0-9_]*\).*/{\2} -&gt; \1 [dir=back, color=\"$IMPLEMENTS_COLOR\"]/" &gt;&gt;$TMPFILE;&#13;
done&#13;
&#13;
# Close the graph&#13;
echo "}" &gt;&gt;$TMPFILE&#13;
&#13;
# Backup dot file&#13;
cp $TMPFILE $TMPFILE."tmp"&#13;
&#13;
echo "Generating graph."&#13;
dot $TMPFILE -T$GRAPHTYPE -o $GRAPH&#13;
&#13;
# Has the graph been successfully generated?&#13;
if [ $? -ne 0 ]; then&#13;
	exit $?&#13;
fi&#13;
&#13;
# Correct the fonts if svg output driver is used&#13;
if [ "$GRAPHTYPE" = "svg" ]; then&#13;
	mv $GRAPH $TMPFILE&#13;
	cat $TMPFILE|sed -e "s@font-size:$CLASS_FONTSIZE.00pt@font-size:$ORIG_CLASS_FONTSIZE.00pt@"|sed -e "s@font-size:$INTERFACE_FONTSIZE.00pt@font-size:$ORIG_INTERFACE_FONTSIZE.00pt@" &gt;$GRAPH&#13;
fi&#13;
&#13;
echo "Deleting temporary files."&#13;
rm $TMPFILE&#13;
&#13;
echo "All done."</description>
      <author>Piccolino81</author>
      <pubDate>Wed, 20 Jul 2011 12:06:26 +0000</pubDate>
    </item>
    <item>
      <title>Andrew Cobby at Thu, 17 Feb 2011 23:38:37 +0100</title>
      <link>http://westhoffswelt.de/blog/class_dependency_graph_generation.html#comment_1</link>
      <description>My graphs only have Exception class and nothing else.&#13;
&#13;
Does it work with PHP 5.3 (and Namespaces)?</description>
      <author>Andrew Cobby</author>
      <pubDate>Thu, 17 Feb 2011 22:38:37 +0000</pubDate>
    </item>
    <item>
      <title>Westhoffswelt - Welcome to the real world at Fri, 30 Jan 2009 01:47:01 +0100</title>
      <link>http://westhoffswelt.de/blog/class_dependency_graph_generation.html#trackback_1</link>
      <description>Just a little update to the class dependency generation script to fix some
incompatabilities. Now everything should work flawlessly</description>
      <author>Westhoffswelt - Welcome to the real world</author>
      <pubDate>Fri, 30 Jan 2009 00:47:01 +0000</pubDate>
    </item>
  </channel>
</rss>

