Updated 3.0:
* Added comments to index.php * Added .gitignore to application/cache and application/log * Started to add missing pieces to Kohana::init() * Changed install.php style slightly
This commit is contained in:
parent
77cb41438d
commit
8d7ab187da
|
@ -0,0 +1,3 @@
|
|||
# Kohana PHP Framework, version 3.0 (dev)
|
||||
|
||||
This is the current development version of [Kohana](http://kohanaphp.com/).
|
1
application/cache/.gitignore
vendored
1
application/cache/.gitignore
vendored
|
@ -0,0 +1 @@
|
|||
[^.]*
|
1
application/log/.gitignore
vendored
1
application/log/.gitignore
vendored
|
@ -0,0 +1 @@
|
|||
[^.]*
|
43
index.php
43
index.php
|
@ -1,32 +1,65 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The directory in which your application specific resources are located.
|
||||
* The application directory must contain the config/kohana.php file.
|
||||
*
|
||||
* @see http://docs.kohanaphp.com/install#application
|
||||
*/
|
||||
$application = 'application';
|
||||
|
||||
/**
|
||||
* The directory in which shared resources are located. Each module must be
|
||||
* contained within its own directory.
|
||||
*
|
||||
* @see http://docs.kohanaphp.com/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://docs.kohanaphp.com/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://docs.kohanaphp.com/install#ext
|
||||
*/
|
||||
define('EXT', '.php');
|
||||
|
||||
define('DOCROOT', str_replace('\\', '/', pathinfo(__FILE__, PATHINFO_DIRNAME)).'/');
|
||||
//
|
||||
// END OF CONFIGURATION, DO NOT EDIT BELOW!
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
// Define the name of the front controller
|
||||
define('FC_FILE', basename(__FILE__));
|
||||
|
||||
// Define the absolute paths for configured directories
|
||||
define('DOCROOT', str_replace('\\', '/', realpath(getcwd())).'/');
|
||||
define('APPPATH', str_replace('\\', '/', realpath($application)).'/');
|
||||
define('MODPATH', str_replace('\\', '/', realpath($modules)).'/');
|
||||
define('SYSPATH', str_replace('\\', '/', realpath($system)).'/');
|
||||
|
||||
// Clean up the configuration vars
|
||||
unset($application, $modules, $system);
|
||||
|
||||
if (file_exists('install'.EXT))
|
||||
{
|
||||
// Installation check
|
||||
// Load the installation check
|
||||
include 'install'.EXT;
|
||||
}
|
||||
elseif (file_exists(APPPATH.'bootstrap'.EXT))
|
||||
{
|
||||
// Custom boostrap
|
||||
// Load the custom bootstrap
|
||||
include APPPATH.'bootstrap'.EXT;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default bootstrap
|
||||
// Load the default bootstrap
|
||||
include SYSPATH.'bootstrap'.EXT;
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
<title>Kohana Installation</title>
|
||||
|
||||
<style type="text/css">
|
||||
body { width: 42em; margin: 0 auto; font-family: sans-serif; }
|
||||
h1 { letter-spacing: -0.05em; }
|
||||
h1 + p { width: 75%; margin: 0 0 2em; color: #666; font-style: italic; font-size:90%; }
|
||||
body { width: 42em; margin: 0 auto; font-family: sans-serif; background: #fff; font-size: 1em; }
|
||||
h1 { letter-spacing: -0.04em; }
|
||||
h1 + p { margin: 0 0 2em; color: #333; font-size: 90%; font-style: italic; }
|
||||
code { font-family: monaco, monospace; }
|
||||
table { border-collapse: collapse; width: 100%; }
|
||||
table th,
|
||||
|
@ -127,7 +127,8 @@
|
|||
<?php if ($failed === TRUE): ?>
|
||||
<p id="results" class="fail">✘ Kohana may not work correctly with your environment.</p>
|
||||
<?php else: ?>
|
||||
<p id="results" class="pass">✔ Your environment passed all requirements.<br />Remove or rename the <code>install<?php echo EXT ?></code> file now.</p>
|
||||
<p id="results" class="pass">✔ Your environment passed all requirements.<br />
|
||||
Remove or rename the <code>install<?php echo EXT ?></code> file now.</p>
|
||||
<?php endif ?>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -28,9 +28,6 @@ else
|
|||
define('SERVER_UTF8', FALSE);
|
||||
}
|
||||
|
||||
// Default output type is UTF-8 text/html
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
|
||||
// Load the main Kohana class
|
||||
require SYSPATH.'classes/kohana'.EXT;
|
||||
|
||||
|
@ -47,12 +44,8 @@ $_SERVER = utf8::clean($_SERVER);
|
|||
/*
|
||||
$route = Route::factory('(:controller(/:method(/:id)))')
|
||||
->defaults(array('controller' => 'welcome', 'method' => 'index'));
|
||||
|
||||
|
||||
echo Kohana::debug($route->matches('uploads/doc/foo.xml'));
|
||||
*/
|
||||
|
||||
$route = Route::factory('(:path/):file(.:format)', array('path' => '.*'));
|
||||
|
||||
$view = View::factory('test');
|
||||
|
||||
echo $view->render();
|
||||
echo Kohana::debug($route->matches('uploads/doc/foo.xml'));
|
||||
|
|
|
@ -16,13 +16,22 @@
|
|||
*/
|
||||
final class Kohana {
|
||||
|
||||
// Command line instance
|
||||
public static $cli_mode = FALSE;
|
||||
|
||||
// Client request method
|
||||
public static $request_method = 'GET';
|
||||
|
||||
// Default charset for all requests
|
||||
public static $charset = 'UTF-8';
|
||||
|
||||
// Has the environment been initialized?
|
||||
private static $init = FALSE;
|
||||
|
||||
// Include paths that are used to find files
|
||||
private static $include_paths = array(APPPATH, SYSPATH);
|
||||
|
||||
// Cache for class methods
|
||||
// Cache for resource location
|
||||
private static $cache = array();
|
||||
|
||||
/**
|
||||
|
@ -39,8 +48,32 @@ final class Kohana {
|
|||
if (self::$init === TRUE)
|
||||
return;
|
||||
|
||||
// Enable auto-loading of classes
|
||||
spl_autoload_register(array(__CLASS__, 'auto_load'));
|
||||
|
||||
if (PHP_SAPI === 'cli')
|
||||
{
|
||||
// The current instance is being run via the command line
|
||||
self::$cli_mode = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($_SERVER['REQUEST_METHOD']))
|
||||
{
|
||||
// Let the server determine the request method
|
||||
self::$request_method = strtoupper($_SERVER['REQUEST_METHOD']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($hooks = self::find_file('hooks'))
|
||||
{
|
||||
foreach ($hooks as $hook)
|
||||
{
|
||||
// Load each hook in the order they appear
|
||||
require $hook;
|
||||
}
|
||||
}
|
||||
|
||||
// The system has been initialized
|
||||
self::$init = TRUE;
|
||||
}
|
||||
|
@ -66,11 +99,12 @@ final class Kohana {
|
|||
// Use the defined extension by default
|
||||
$ext = ($ext === NULL) ? EXT : '.'.$ext;
|
||||
|
||||
// Full (relative) path name
|
||||
// Create a partial path of the filename
|
||||
$file = $dir.'/'.$file.$ext;
|
||||
|
||||
if (isset(self::$cache[__FUNCTION__][$file]))
|
||||
{
|
||||
// The path to this file has already been found
|
||||
return self::$cache[__FUNCTION__][$file];
|
||||
}
|
||||
|
||||
|
@ -78,6 +112,7 @@ final class Kohana {
|
|||
{
|
||||
if (file_exists($path.$file))
|
||||
{
|
||||
// Cache and return the path to this file
|
||||
return self::$cache[__FUNCTION__][$file] = $path.$file;
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +120,20 @@ final class Kohana {
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a file within a totally empty scope and returns the output:
|
||||
*
|
||||
* $foo = Kohana::load_file('foo.php');
|
||||
*
|
||||
* @param string
|
||||
* @return mixed
|
||||
*/
|
||||
public function load_file($file)
|
||||
{
|
||||
// Return the output of the file
|
||||
return include $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides auto-loading support of Kohana classes, as well as transparent
|
||||
* extension of classes that have a _Core suffix.
|
||||
|
@ -93,7 +142,7 @@ final class Kohana {
|
|||
* lowercase and converting underscores to slashes:
|
||||
*
|
||||
* // Loads classes/my/class/name.php
|
||||
* Kohana::auto_load('My_Class_Name')
|
||||
* Kohana::auto_load('My_Class_Name');
|
||||
*
|
||||
* @param string class name
|
||||
* @param string file extensions to use
|
||||
|
@ -101,10 +150,12 @@ final class Kohana {
|
|||
*/
|
||||
public static function auto_load($class)
|
||||
{
|
||||
// Transform the class name into a path
|
||||
$file = str_replace('_', '/', strtolower($class));
|
||||
|
||||
if ($path = self::find_file('classes', $file))
|
||||
{
|
||||
// Load the class file
|
||||
require $path;
|
||||
}
|
||||
else
|
||||
|
@ -114,6 +165,7 @@ final class Kohana {
|
|||
|
||||
if ($path = self::find_file('extensions', $file))
|
||||
{
|
||||
// Load the extension file
|
||||
require $path;
|
||||
}
|
||||
elseif (class_exists($class.'_Core', FALSE))
|
||||
|
@ -131,7 +183,7 @@ final class Kohana {
|
|||
}
|
||||
|
||||
// Transparent class extensions are possible using eval. Not very
|
||||
// clean, but it can be avoided by creating empty extensions.
|
||||
// clean, but it can be avoided by creating empty extension files.
|
||||
eval($extension);
|
||||
}
|
||||
|
||||
|
@ -154,13 +206,13 @@ final class Kohana {
|
|||
if (func_num_args() === 0)
|
||||
return;
|
||||
|
||||
// Get params
|
||||
$params = func_get_args();
|
||||
$output = array();
|
||||
// Get all passed variables
|
||||
$variables = func_get_args();
|
||||
|
||||
foreach ($params as $var)
|
||||
$output = array();
|
||||
foreach ($variables as $var)
|
||||
{
|
||||
$output[] = '<pre>('.gettype($var).') '.htmlspecialchars(print_r($var, TRUE)).'</pre>';
|
||||
$output[] = '<pre>('.gettype($var).') '.htmlspecialchars(print_r($var, TRUE), ENT_QUOTES, self::$charset, TRUE).'</pre>';
|
||||
}
|
||||
|
||||
return implode("\n", $output);
|
||||
|
|
Loading…
Reference in a new issue