Created
February 2, 2012 17:51
-
-
Save phpfour/1724837 to your computer and use it in GitHub Desktop.
Kohana Bootstrap (comment less, clean version)
This file contains 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
<?php defined('SYSPATH') or die('No direct script access.'); | |
class Bootstrap | |
{ | |
public static function run() | |
{ | |
self::loadKohanaCore(); | |
self::loadKohanaExtension(); | |
self::setDefaultTimezone(); | |
self::setDefaultLocale(); | |
self::enableKohanaAutoloader(); | |
self::enableKohanaUnserializer(); | |
self::setDefaultLanguage(); | |
self::setKohanaEnvironment(); | |
self::initKohana(); | |
self::initLogWriter(); | |
self::initConfigReader(); | |
self::initModules(); | |
self::initRoutes(); | |
} | |
public static function loadKohanaCore() | |
{ | |
require SYSPATH . 'classes/kohana/core' . EXT; | |
} | |
public static function loadKohanaExtension() | |
{ | |
if (is_file(APPPATH . 'classes/kohana' . EXT)) { | |
require APPPATH . 'classes/kohana' . EXT; | |
} else { | |
require SYSPATH . 'classes/kohana' . EXT; | |
} | |
} | |
public static function setDefaultTimezone($timezone = 'America/Chicago') | |
{ | |
date_default_timezone_set($timezone); | |
} | |
public static function setDefaultLocale() | |
{ | |
setlocale(LC_ALL, 'en_US.utf-8'); | |
} | |
public static function enableKohanaAutoloader() | |
{ | |
spl_autoload_register(array ('Kohana', 'auto_load')); | |
} | |
public static function enableKohanaUnserializer() | |
{ | |
ini_set('unserialize_callback_func', 'spl_autoload_call'); | |
} | |
public static function setDefaultLanguage($lang = 'en-us') | |
{ | |
I18n::lang($lang); | |
} | |
public static function setKohanaEnvironment() | |
{ | |
if (isset($_SERVER['KOHANA_ENV'])) { | |
Kohana::$environment = constant('Kohana::' . strtoupper($_SERVER['KOHANA_ENV'])); | |
} | |
} | |
public static function initKohana() | |
{ | |
Kohana::init(array( | |
'base_url' => '/', | |
)); | |
} | |
public static function initLogWriter() | |
{ | |
Kohana::$log->attach(new Log_File(APPPATH . 'logs')); | |
} | |
public static function initConfigReader() | |
{ | |
Kohana::$config->attach(new Config_File); | |
} | |
public static function initModules() | |
{ | |
Kohana::modules(array ( | |
'auth' => MODPATH . 'auth', // Basic authentication | |
'cache' => MODPATH . 'cache', // Caching with multiple backends | |
'codebench' => MODPATH . 'codebench', // Benchmarking tool | |
'database' => MODPATH . 'database', // Database access | |
'image' => MODPATH . 'image', // Image manipulation | |
'orm' => MODPATH . 'orm', // Object Relationship Mapping | |
'unittest' => MODPATH . 'unittest', // Unit testing | |
'userguide' => MODPATH . 'userguide', // User guide and API documentation | |
)); | |
} | |
public static function initRoutes() | |
{ | |
Route::set('default', '(<controller>(/<action>(/<id>)))')->defaults(array( | |
'controller' => 'welcome', | |
'action' => 'index', | |
)); | |
} | |
} | |
Bootstrap::run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment