Skip to content

Instantly share code, notes, and snippets.

@lukemorton
Created April 12, 2011 18:21
Show Gist options
  • Select an option

  • Save lukemorton/916077 to your computer and use it in GitHub Desktop.

Select an option

Save lukemorton/916077 to your computer and use it in GitHub Desktop.
Create a new Kohana app easily
<?php
/**
* The directory in which your application specific resources are located.
* The application directory must contain the bootstrap.php file.
*
* @see http://kohanaframework.org/guide/about.install#application
*/
$application = '../application';
/**
* The directory in which your modules are located.
*
* @see http://kohanaframework.org/guide/about.install#modules
*/
$modules = '../modules';
/**
* The directory in which the Kohana resources are located. The system
* directory must contain the classes/kohana.php file.
*
* @see http://kohanaframework.org/guide/about.install#system
*/
$system = '../system';
/**
* The default extension of resource files. If you change this, all resources
* must be renamed to use the new extension.
*
* @see http://kohanaframework.org/guide/about.install#ext
*/
define('EXT', '.php');
/**
* Set the PHP error reporting level. If you set this in php.ini, you remove this.
* @see http://php.net/error_reporting
*
* When developing your application, it is highly recommended to enable notices
* and strict warnings. Enable them by using: E_ALL | E_STRICT
*
* In a production environment, it is safe to ignore notices and strict warnings.
* Disable them by using: E_ALL ^ E_NOTICE
*
* When using a legacy application with PHP >= 5.3, it is recommended to disable
* deprecated notices. Disable with: E_ALL & ~E_DEPRECATED
*/
error_reporting(E_ALL | E_STRICT);
/**
* End of standard configuration! Changing any of the code below should only be
* attempted by those with a working knowledge of Kohana internals.
*
* @see http://kohanaframework.org/guide/using.configuration
*/
// Set the full path to the docroot
define('DOCROOT', realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR);
// Make the application relative to the docroot, for symlink'd index.php
if ( ! is_dir($application) AND is_dir(DOCROOT.$application))
$application = DOCROOT.$application;
// Make the modules relative to the docroot, for symlink'd index.php
if ( ! is_dir($modules) AND is_dir(DOCROOT.$modules))
$modules = DOCROOT.$modules;
// Make the system relative to the docroot, for symlink'd index.php
if ( ! is_dir($system) AND is_dir(DOCROOT.$system))
$system = DOCROOT.$system;
// Define the absolute paths for configured directories
define('APPPATH', realpath($application).DIRECTORY_SEPARATOR);
define('MODPATH', realpath($modules).DIRECTORY_SEPARATOR);
define('SYSPATH', realpath($system).DIRECTORY_SEPARATOR);
// Clean up the configuration vars
unset($application, $modules, $system);
if (file_exists('install'.EXT))
{
// Load the installation check
return include 'install'.EXT;
}
/**
* Define the start time of the application, used for profiling.
*/
if ( ! defined('KOHANA_START_TIME'))
{
define('KOHANA_START_TIME', microtime(TRUE));
}
/**
* Define the memory usage at the start of the application, used for profiling.
*/
if ( ! defined('KOHANA_START_MEMORY'))
{
define('KOHANA_START_MEMORY', memory_get_usage());
}
// Bootstrap the application
require APPPATH.'bootstrap'.EXT;
/**
* Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO'].
* If no source is specified, the URI will be automatically detected.
*/
echo Request::factory()
->execute()
->send_headers()
->body();
#!/bin/bash
#
# Kohana Application Installer
# ============================
#
# This is a small bash script for installing the core files for a Kohana
# application. Will install at the path specified a basic application
# structure, then initialises a git repository for your convenience. The
# core Kohana system files are added as a submodule and you are given
# the option to install Kostache because you just should!
#
#
# Author
# ------
# Luke Morton <[email protected]>
#
#
# Requirements
# ------------
# * git
#
#
# Usage
# -----
# ./koapp /var/www/my-new-app
#
# Default
DEFAULT_APP_PATH="$HOME/koapp"
if [ -n "$1" ];
then
# Use first arg as application path
APP_NAME="$1"
else
# Request application name
echo "Please provide a path in which to install your new Kohana application: "
read CUSTOM_APP_PATH
# Set app path
if [ -n "$CUSTOM_APP_PATH" ];
then
APP_NAME="$CUSTOM_APP_PATH"
else
APP_NAME="$DEFAULT_APP_PATH"
fi
fi
# Use app name
echo "Using $APP_NAME as application path..."
if [ ! -d "$APP_NAME" ];
then
# Create folder in application path
echo "Creating application path..."
mkdir -p $APP_NAME
fi
# Go go go...
cd $APP_NAME
# Create application folders with correct perms
echo "Creating application folders..."
mkdir -p {application,modules,public}
mkdir -p application/{config,classes,cache,logs}
echo "Ensuring 777 permissions on application/log and application/cache..."
chmod 0777 application/{cache,logs}
if [ -d ".git" ];
then
# Already a git repo
echo "Application path is already a git repo..."
else
# Init repo
echo "Initialising application folder as git repo..."
git init > /dev/null
fi
if [ ! -f "application/bootstrap.php" ];
then
# Grab bootstrap and index
echo "Getting bootstrap.php..."
wget https://github.com/kohana/kohana/raw/3.1/master/application/bootstrap.php --output-document=application/bootstrap.php --no-check-certificate > /dev/null 2>&1
fi
if [ ! -f "public/index.php" ];
then
echo "Getting index.php..."
wget https://gist.github.com/raw/916077/d8a65e6400a5f12b0db7c1fd45d584f3d7c391bd/index.php --output-document=public/index.php --no-check-certificate > /dev/null 2>&1
fi
if [ ! -d "system" ];
then
# Get system files
echo "Cloning Kohana Core into system..."
git submodule add https://github.com/kohana/core.git system > /dev/null 2>&1
fi
install_module()
{
MODULE_NAME=$1
MODULE_LOCATION=$2
if [ ! -d "modules/$MODULE_NAME" ];
then
echo "Would you like to install $MODULE_NAME (y/n)?"
read INSTALL
if [ "$INSTALL" == "y" ];
then
echo "Installing $MODULE_NAME..."
echo "Cloning $MODULE_NAME from $MODULE_LOCATION into modules/$MODULE_NAME..."
git submodule add "$MODULE_LOCATION" "modules/$MODULE_NAME" > /dev/null 2>&1
fi
fi
}
install_kostache()
{
install_module "kostache" "https://github.com/zombor/KOstache.git"
if [ "$INSTALL" == "y" ];
then
mkdir application/templates
fi
}
install_orm()
{
install_module "orm" "https://github.com/kohana/orm.git"
if [ "$INSTALL" == "y" ];
then
echo "[!!] You will need the database module in order to use ORM"
install_db
fi
}
install_db()
{
install_module "database" "https://github.com/kohana/database.git"
if [ "$INSTALL" == "y" ];
then
cp modules/database/config/database.php application/config/database.php
fi
}
install_kostache
install_orm
install_db
# Ensure submodules initialised
echo "Initialising submodules..."
git submodule update --init > /dev/null
# Add changes
git add . > /dev/null
echo "Please provide a commit message or leave blank to use default: "
read COMMIT
if [ ! -n "$COMMIT" ];
then
COMMIT="Kohana Application Installer run for $APP_NAME"
fi
echo "Commiting original sin...."
git commit -m "$COMMIT" > /dev/null
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment