Created
August 20, 2012 20:31
-
-
Save ruthlessfish/3407604 to your computer and use it in GitHub Desktop.
Kohana from the command line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#------------------------------------------------------------------------------ | |
# | |
# Kohana | |
# | |
# | |
# Run Kohana controllers from the command line | |
# | |
# Installation: | |
# | |
# * Change DOCROOT below to your desired location | |
# * Save this file to /usr/local/bin/kohana or on your path | |
# | |
# Usage: | |
# | |
# > kohana foo/bar | |
# > kohana -d /path/to/docroot foo/bar | |
# | |
#------------------------------------------------------------------------------ | |
export DOCROOT='/path/to/DOCROOT' | |
#------------------------------------------------------------------------------ | |
function KohanaHelp { | |
echo "Kohana: The Swift PHP Framework | |
Copyright © 2007–2012. The awesome Kohana Team. Kohana is licensed under the BSD License. | |
usage: [-d <DOCROOT>] [<uri>]" | |
exit 1 | |
} | |
function KohanaAbort { | |
echo 'abort: invalid request' | |
exit 0 | |
} | |
#------------------------------------------------------------------------------ | |
# argument processing | |
args=`getopt d: $*` | |
set -- $args | |
for i; do | |
case "$i" in | |
-d ) | |
DOCROOT=$2 | |
shift; shift ;; | |
-- ) | |
shift; break ;; | |
esac | |
done | |
# verify arguments | |
if [ ! $1 ] || [ "$1" == 'help' ]; then | |
KohanaHelp | |
fi | |
#------------------------------------------------------------------------------ | |
# set php and kohana paths | |
PHP=$(which php) | |
URI=$1 | |
# validate paths | |
if [ ! -f $PHP ] || [ ! -d $DOCROOT ]; then | |
KohanaAbort | |
fi | |
# run Kohana CLI | |
$PHP $DOCROOT/index.php --uri=$1 | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment