Skip to content

Instantly share code, notes, and snippets.

@jasonrobertfox
Created February 21, 2013 16:30
Show Gist options
  • Save jasonrobertfox/5005954 to your computer and use it in GitHub Desktop.
Save jasonrobertfox/5005954 to your computer and use it in GitHub Desktop.
Use to make a new class using the PSR-0 location standards.
#!/bin/sh
USAGE="Usage: new-class.sh [-u] [-i] <class>"
src='src/'
unit='tests/unit/'
int='tests/integration/'
[[ "${@: -1}" =~ (.*)\/(.*$) ]]
class=${BASH_REMATCH[2]}
path=${BASH_REMATCH[1]}
namespace=`echo $path | sed 's/\//\\\\\\\/g'`
echo "$namespace"
classText=`cat build-deploy/templates/class.template | sed "s/{{namespace}}/${namespace}/g" | sed "s/{{class}}/${class}/g"`
testText=`cat build-deploy/templates/class-test.template | sed "s/{{namespace}}/${namespace}/g" | sed "s/{{class}}/${class}/g"`
echo "$classText"
exit
mkdir -p "$src$path";
classFile="$src$path/$class.php"
echo "Creating: $classFile";
echo "$classText" >> $classFile;
while getopts ":ui" OPTIONS; do
case $OPTIONS in
u )
mkdir -p "$unit$path";
unitTestFile="$unit$path/${class}Test.php"
echo "Creating: $unitTestFile";
echo "$testText" >> $unitTestFile;
;;
i )
mkdir -p "$int$path";
intTestFile="$int$path/${class}Test.php"
echo "Creating: $intTestFile";
echo "$testText" >> $intTestFile;
;;
h ) echo $USAGE;;
\? ) echo $USAGE
exit 1;;
* ) echo $usage
exit 1;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment