From 100f8a7abd35a8db62f3187b96d8fd163eb9374c Mon Sep 17 00:00:00 2001 From: Woody Gilk Date: Wed, 20 May 2009 14:13:02 -0500 Subject: [PATCH] Created new file system/base.php with low-level functions, moved __() to base.php, moved environment setup to bootstrap.php, and updated index.php accordingly --- application/bootstrap.php | 47 +++++++++++++++++++++++++++++++-------- index.php | 24 +++----------------- system/base.php | 21 +++++++++++++++++ 3 files changed, 62 insertions(+), 30 deletions(-) create mode 100644 system/base.php diff --git a/application/bootstrap.php b/application/bootstrap.php index 9c868b3..cb18fad 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -1,21 +1,41 @@ 'utf-8', 'base_url' => '/ko3/')); +//-- Environment setup -------------------------------------------------------- /** - * Enable modules. + * Enable the Kohana auto-loader. + */ +spl_autoload_register(array('Kohana', 'auto_load')); + +/** + * Enable Kohana exception handling, adds stack traces and error source. + */ +set_exception_handler(array('Kohana', 'exception_handler')); + +/** + * Enable Kohana error handling, converts all PHP errors to exceptions. + */ +set_error_handler(array('Kohana', 'error_handler')); + +//-- Kohana configuration ----------------------------------------------------- + +/** + * Initialize Kohana, setting the default options. + */ +Kohana::init(array('charset' => 'utf-8', 'base_url' => '/ko3/index.php/')); + +/** + * Enable modules. Modules are referenced by a relative or absolute path. */ Kohana::modules(array( // 'orm' => MODPATH.'orm', - // 'database' => MODPATH.'database', + 'database' => MODPATH.'database', 'todoist' => MODPATH.'todoist', )); /** - * Log all messages to files + * Attach the file write to logging. Any Kohana_Log object can be attached, + * and multiple writers are supported. */ Kohana::$log->attach(new Kohana_Log_File(APPPATH.'logs')); @@ -24,6 +44,8 @@ Kohana::$log->attach(new Kohana_Log_File(APPPATH.'logs')); */ i18n::$lang = 'en_US'; +//-- Routing and execution ---------------------------------------------------- + /** * Set the routes. */ @@ -40,5 +62,12 @@ Route::set('default', '((/(/)))') 'action' => 'index', 'id' => NULL)); -// Execute the main request -Request::instance($_SERVER['PATH_INFO'])->execute(FALSE); +/** + * Execute the main request using PATH_INFO. If no URI source is specified, + * the URI will be automatically detected. + * + * To return the output of the request instead of displaying it, specify + * TRUE for execute(). + */ +Request::instance($_SERVER['PATH_INFO']) + ->execute(FALSE); diff --git a/index.php b/index.php index 80adcbf..f9622f0 100644 --- a/index.php +++ b/index.php @@ -73,32 +73,14 @@ if (file_exists('install'.EXT)) return include 'install'.EXT; } -// i18n translation function -function __($string, array $values = NULL) -{ - if (i18n::$lang !== i18n::$default_lang) - { - // Get the translation for this string - $string = i18n::get($string); - } - - return empty($values) ? $string : strtr($string, $values); -} - // Define the start time of the application define('KOHANA_START_TIME', microtime(TRUE)); +// Load the base, low-level functions +require SYSPATH.'base'.EXT; + // Load the main Kohana class require SYSPATH.'classes/kohana'.EXT; -// Enable auto-loading of classes -spl_autoload_register(array('Kohana', 'auto_load')); - -// Enable the exception handler -set_exception_handler(array('Kohana', 'exception_handler')); - -// Enable the error-to-exception handler -set_error_handler(array('Kohana', 'error_handler')); - // Bootstrap the application require APPPATH.'bootstrap'.EXT; diff --git a/system/base.php b/system/base.php new file mode 100644 index 0000000..6275104 --- /dev/null +++ b/system/base.php @@ -0,0 +1,21 @@ + $username)); + * + * @param string text to translate + * @param array values to replace in the translated text + * @return string + */ +function __($string, array $values = NULL) +{ + if (i18n::$lang !== i18n::$default_lang) + { + // Get the translation for this string + $string = i18n::get($string); + } + + return empty($values) ? $string : strtr($string, $values); +}