Dependent Files

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`;
    echo -,;
    readme=`echo $x/README`;
    if [ -s $readme ];
    then rm $readme;
    list=`ls $x | grep -v README | grep php`;
    for y in `echo $list`; ## LISTS ALL PHP FILES
        echo -.;
        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 
            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"`;
                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
            done## END OF DEPENDENT FILES
            echo >> $readme;
        done## END OF FUNCTIONS
    done## END OF PHP FILES
done## END OF DIRS
echo okay;

Download: 1 KB

Please login or Click Here to register for downloads
Creative Commons License
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
Permissions beyond the scope of this license may be available at