This bash script creates README files within a php folder hierarchy and determines all functions, their arguments, and which php files use them.
Useful for finding out which php files use which php functions.
Date Created:Thursday December 25th, 2008 08:18 PM
Date Modified:Thursday December 25th, 2008 08:21 PM
for x in `find ./my-directory -type d`;
do
echo -n ,;
readme=`echo $x/README`;
if [ -s $readme ];
then rm $readme;
fi;
list=`ls $x | grep -v README | grep php`;
for y in `echo $list`; ## LISTS ALL PHP FILES
do
echo -n .;
path=`echo $x/$y`; ## MAKES PATH TO PHP FILE
echo >> $readme;
echo >> $readme;
echo ------------------------------------------------------ >> $readme;
echo $path >> $readme; ## ECHOS PATH OF PHP FILE
echo ------------------------------------------------------ >> $readme;
echo >> $readme;
functions=`cat $path | grep function[[:space:]] | sed 's/{//g' | sed 's/function//g' | sed 's/,\ /,/g' | sed 's/\ )/)/g' | sed 's/(\ /(/g' | sed 's/\s (/(/g' | sed 's/\ =/=/g' | sed 's/=\ /=/g' | grep -v \#`;
for f in `echo $functions`; ## ALL FUNCTIONS
do
fn=`echo $f | grep \( | sed 's/(/ /g' | awk '{print $1}'`; ## FUNCTION NAME
fargs=`echo $f | grep \( | sed 's/(/ /g' | awk '{print $2}' | sed 's/)//g'`; ## FUNCTION ARGS
echo FUNCTION: $fn >> $readme;
echo ARGUMENTS: $fargs >> $readme;
echo DEPENDENTS: >> $readme;
for p in `find ./conf -name "*.php"`;
do
search=`cat $p | grep -s $fn | grep -v function[[:space]]$fn`;
if test `echo $search | awk '{print $1}'`; ## TESTS TO SEE IF A RESULT WAS FOUND
then echo --- $p >> $readme; ## IF YES, LET US KNOW
fi;
done; ## END OF DEPENDENT FILES
echo >> $readme;
done; ## END OF FUNCTIONS
done; ## END OF PHP FILES
done; ## END OF DIRS
echo okay;
Downloads:
Download: dependents.sh 1 KB
Please login or Click Here to register for downloads
Dependent Files by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com
