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

This commit is contained in:
Woody Gilk 2009-05-20 14:13:02 -05:00
parent c3aaae8491
commit 100f8a7abd
3 changed files with 62 additions and 30 deletions

View file

@ -1,21 +1,41 @@
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Initialize Kohana
*/
Kohana::init(array('charset' => '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', '(<controller>(/<action>(/<id>)))')
'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);

View file

@ -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;

21
system/base.php Normal file
View file

@ -0,0 +1,21 @@
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Kohana translation/internationalization function.
*
* __('Welcome back, :user', array(':user' => $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);
}