Skip to content

Instantly share code, notes, and snippets.

@ruthlessfish
Created August 20, 2012 20:31
Show Gist options
  • Save ruthlessfish/3407604 to your computer and use it in GitHub Desktop.
Save ruthlessfish/3407604 to your computer and use it in GitHub Desktop.
Kohana from the command line
#!/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