From d2fc6d4d47732aeb5bd1cf3c1428aac7fff3d5cb Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 13 Jul 2010 18:13:05 +1000 Subject: [PATCH] Upstream Patch: Override path patch --- .../kohana/system/classes/kohana/core.php | 50 ++++++++++++++++--- kh.php | 29 ++++++++++- 2 files changed, 70 insertions(+), 9 deletions(-) diff --git a/includes/kohana/system/classes/kohana/core.php b/includes/kohana/system/classes/kohana/core.php index fbc1e99c..b74d0119 100644 --- a/includes/kohana/system/classes/kohana/core.php +++ b/includes/kohana/system/classes/kohana/core.php @@ -191,6 +191,7 @@ class Kohana_Core { // Kohana is now initialized Kohana::$_init = TRUE; + Kohana::$_paths = Kohana::build_paths(); if (isset($settings['profile'])) { @@ -370,7 +371,7 @@ class Kohana_Core { // Reset internal storage Kohana::$_modules = Kohana::$_files = array(); - Kohana::$_paths = array(APPPATH, SYSPATH); + Kohana::$_paths = Kohana::build_paths(); // Reset file cache status Kohana::$_files_changed = FALSE; @@ -511,14 +512,15 @@ class Kohana_Core { } // Start a new list of include paths, APPPATH first - $paths = array(APPPATH); + $paths = array(); foreach ($modules as $name => $path) { if (is_dir($path)) { // Add the module to include paths - $paths[] = $modules[$name] = realpath($path).DIRECTORY_SEPARATOR; + $modules[$name] = realpath($path).DIRECTORY_SEPARATOR; + $paths[] = $name; } else { @@ -527,11 +529,8 @@ class Kohana_Core { } } - // Finish the include paths by adding SYSPATH - $paths[] = SYSPATH; - // Set the new include paths - Kohana::$_paths = $paths; + Kohana::$_paths = Kohana::build_paths($paths); // Set the current module list Kohana::$_modules = $modules; @@ -550,6 +549,39 @@ class Kohana_Core { return Kohana::$_modules; } + public static function build_paths(array $module_paths=array()) { + // Start a new list of include paths, APPPATH first + $paths = array(); + + if (OVERPATH AND is_dir(OVERPATH.'application')) + $paths[] = OVERPATH.'application'; + + $paths[] = APPPATH; + + // Add our modules + foreach ($module_paths as $path) + { + if (is_dir(MODPATH.$path)) + { + // Add the override path + if (OVERPATH AND is_dir(OVERPATH.'modules'.DIRECTORY_SEPARATOR.$path)) + { + $paths[] = realpath(OVERPATH.'modules'.DIRECTORY_SEPARATOR.$path).DIRECTORY_SEPARATOR; + } + // Add the module to include paths + $paths[] = realpath(MODPATH.$path).DIRECTORY_SEPARATOR; + } + } + + // Finish the include paths by adding SYSPATH + if (OVERPATH AND is_dir(OVERPATH.'system')) + $paths[] = OVERPATH.'system'; + + $paths[] = SYSPATH; + + return $paths; + } + /** * Returns the the currently active include paths, including the * application and system paths. @@ -1355,6 +1387,10 @@ class Kohana_Core { { $file = 'MODPATH'.DIRECTORY_SEPARATOR.substr($file, strlen(MODPATH)); } + elseif (strpos($file, OVERPATH) === 0) + { + $file = 'OVERPATH/'.substr($file, strlen(OVERPATH)); + } elseif (strpos($file, DOCROOT) === 0) { $file = 'DOCROOT'.DIRECTORY_SEPARATOR.substr($file, strlen(DOCROOT)); diff --git a/kh.php b/kh.php index c6b09632..d8cecc50 100644 --- a/kh.php +++ b/kh.php @@ -23,6 +23,12 @@ $modules = 'modules'; */ $system = 'system'; +/** + * This directory in which we can override classes that may not yet be accepted + * upstream. + */ +$override = 'override'; + /** * The default extension of resource files. If you change this, all resources * must be renamed to use the new extension. @@ -68,13 +74,22 @@ if ( ! is_dir($modules) AND is_dir(DOCROOT.$modules)) if ( ! is_dir($system) AND is_dir(DOCROOT.$system)) $system = DOCROOT.$system; +// Make the override relative to the docroot +if ( ! is_dir($override) AND is_dir(DOCROOT.$override)) + $override = DOCROOT.$override; + // 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); +if (is_dir(realpath($override))) + define('OVERPATH', realpath($override).DIRECTORY_SEPARATOR); +else + define('OVERPATH', ''); + // Clean up the configuration vars -unset($application, $modules, $system); +unset($application, $modules, $system, $override); if (file_exists('install'.EXT)) { @@ -88,11 +103,21 @@ require SYSPATH.'base'.EXT; // Load the core Kohana class require SYSPATH.'classes/kohana/core'.EXT; -if (is_file(APPPATH.'classes/kohana'.EXT)) +if (is_file(OVERPATH.'application/classes/kohana'.EXT)) +{ + // Override Application extends the core + require OVERPATH.'application/classes/kohana'.EXT; +} +elseif (is_file(APPPATH.'classes/kohana'.EXT)) { // Application extends the core require APPPATH.'classes/kohana'.EXT; } +elseif (is_file(OVERPATH.'system/classes/kohana'.EXT)) +{ + // Override system extends the core + require APPPATH.'system/classes/kohana'.EXT; +} else { // Load empty core extension