summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-rw-r--r--system/application/config/config.php43
-rw-r--r--system/codeigniter/Common.php78
-rw-r--r--system/libraries/Benchmark.php1
-rw-r--r--system/libraries/Loader.php50
4 files changed, 83 insertions, 89 deletions
diff --git a/system/application/config/config.php b/system/application/config/config.php
index bf15525cb..b0d2bf500 100644
--- a/system/application/config/config.php
+++ b/system/application/config/config.php
@@ -83,6 +83,21 @@ $config['enable_hooks'] = TRUE;
/*
|--------------------------------------------------------------------------
+| Class Extension Prefix
+|--------------------------------------------------------------------------
+|
+| This item allows you to set the filename/classname prefix when extending
+| native libraries. For more information please see the user guide:
+|
+| http://www.codeigniter.com/user_guide/general/core_classes.html
+| http://www.codeigniter.com/user_guide/general/creating_libraries.html
+|
+*/
+$config['subclass_prefix'] = 'MY_';
+
+
+/*
+|--------------------------------------------------------------------------
| Allowed URL Characters
|--------------------------------------------------------------------------
|
@@ -129,20 +144,7 @@ $config['function_trigger'] = 'm';
/*
|--------------------------------------------------------------------------
-| Master Time Reference
-|--------------------------------------------------------------------------
-|
-| Options are "local" or "gmt". This pref tells the system whether to use
-| your server's local time as the master "now" reference, or convert it to
-| GMT. See the "date helper" page of the user guide for information
-| regarding date handling.
-|
-*/
-$config['time_reference'] = 'local';
-
-/*
-|--------------------------------------------------------------------------
-| Error Logging Threshold
+| Error Logging
|--------------------------------------------------------------------------
|
| You can enable error logging by setting a threshold over zero. The
@@ -267,5 +269,18 @@ $config['global_xss_filtering'] = FALSE;
*/
$config['compress_output'] = FALSE;
+/*
+|--------------------------------------------------------------------------
+| Master Time Reference
+|--------------------------------------------------------------------------
+|
+| Options are "local" or "gmt". This pref tells the system whether to use
+| your server's local time as the master "now" reference, or convert it to
+| GMT. See the "date helper" page of the user guide for information
+| regarding date handling.
+|
+*/
+$config['time_reference'] = 'local';
+
?> \ No newline at end of file
diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php
index 07b468fef..a82d486e6 100644
--- a/system/codeigniter/Common.php
+++ b/system/codeigniter/Common.php
@@ -50,57 +50,27 @@ function &load_class($class, $instantiate = TRUE)
{
return $objects[$class];
}
-
- // This is a special case. It's a class in the Base5.php file
- // which we don't need to load. We only instantiate it.
- if ($class == 'Instance')
- {
- $objects[$class] =& new $class();
- return $objects[$class];
- }
-
+
// If the requested class does not exist in the application/libraries
- // folder we'll load the native class from the system/libraries folder.
-
- $is_subclass = FALSE;
- if ( ! file_exists(APPPATH.'libraries/'.$class.EXT))
+ // folder we'll load the native class from the system/libraries folder.
+ if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT))
{
- require(BASEPATH.'libraries/'.$class.EXT);
+ require(BASEPATH.'libraries/'.$class.EXT);
+ require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT);
+ $is_subclass = TRUE;
}
else
{
- // A core class can either be extended or replaced by putting an
- // identically named file in the application/libraries folder. 
- // We need to determine, however, if the class being requested is
- // a sub-class of an existing library or an independent instance
- // since each needs to be handled slightly different. 
- // To do this we'll open the requested class and read the top portion
- // of it. If the class extends a base class we will load the base first.
- // If it doesn't extend the base we'll only load the requested class.
-
- // Note: I'm not thrilled with this approach since it requires us to
- // read the top part of the file (I set a character limit of 5000 bytes,
- // which correlates to roughly the first 100 lines of code), but
- // I can't think of a better way to allow classes to be extended or
- // replaced on-the-fly with nothing required for the user to do
- // except write the declaration.  Fortunately PHP is ridiculously fast
- // at file reading operations so I'm not able to discern a performance
- // hit based on my benchmarks, assuming only a small number of core
- // files are being extended, which will usually be the case.
-
- $fp = fopen(APPPATH.'libraries/'.$class.EXT, "rb");
-
- if (preg_match("/MY_".$class."\s+extends\s+CI_".$class."/i", fread($fp, '6000')))
+ if (file_exists(APPPATH.'libraries/'.$class.EXT))
{
- require(BASEPATH.'libraries/'.$class.EXT);
- require(APPPATH.'libraries/'.$class.EXT);
- $is_subclass = TRUE;
+ require(APPPATH.'libraries/'.$class.EXT);
+ $is_subclass = FALSE;
}
else
{
- require(APPPATH.'libraries/'.$class.EXT);
+ require(BASEPATH.'libraries/'.$class.EXT);
+ $is_subclass = FALSE;
}
- fclose($fp);
}
if ($instantiate == FALSE)
@@ -111,7 +81,7 @@ function &load_class($class, $instantiate = TRUE)
if ($is_subclass == TRUE)
{
- $name = 'MY_'.$class;
+ $name = config_item('subclass_prefix').$class;
$objects[$class] =& new $name();
return $objects[$class];
}
@@ -151,6 +121,30 @@ function &get_config()
return $main_conf[0];
}
+/**
+* Gets a config item
+*
+* @access public
+* @return mixed
+*/
+function &config_item($item)
+{
+ static $config_item = array();
+
+ if ( ! isset($config_item[$item]))
+ {
+ $config =& get_config();
+
+ if ( ! isset($config[$item]))
+ {
+ return FALSE;
+ }
+ $config_item[$item] = $config[$item];
+ }
+
+ return $config_item[$item];
+}
+
/**
* Error Handler
diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php
index c20a54269..d4262792c 100644
--- a/system/libraries/Benchmark.php
+++ b/system/libraries/Benchmark.php
@@ -31,7 +31,6 @@ class CI_Benchmark {
var $marker = array();
-
// --------------------------------------------------------------------
/**
diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php
index 3b1a7f2cd..b313c6d5a 100644
--- a/system/libraries/Loader.php
+++ b/system/libraries/Loader.php
@@ -655,51 +655,37 @@ class CI_Loader {
function _ci_load_class($class, $params = NULL)
{
// Prep the class name
- $class = strtolower(str_replace(EXT, '', $class));
-
- // Is this a class extension request?
- if (substr($class, 0, 3) == 'my_')
- {
- $class = preg_replace("/my_(.+)/", "\\1", $class);
+ $class = ucfirst(strtolower(str_replace(EXT, '', $class)));
- // Load the requested library from the main system/libraries folder
- if (file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT))
- {
- include_once(BASEPATH.'libraries/'.ucfirst($class).EXT);
- }
-
- // Now look for a matching library
- foreach (array(ucfirst($class), $class) as $filename)
+ // Is this a class extension request?
+ if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT))
+ {
+ if ( ! file_exists(BASEPATH.'libraries/'.$class.EXT))
{
- if (file_exists(APPPATH.'libraries/'.$filename.EXT))
- {
- include_once(APPPATH.'libraries/'.$filename.EXT);
- }
+ log_message('error', "Unable to load the requested class: ".$class);
+ show_error("Unable to load the requested class: ".$class);
}
-
- return $this->_ci_init_class($filename, 'MY_', $params);
+
+ include_once(BASEPATH.'libraries/'.ucfirst($class).EXT);
+ include_once(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT);
+
+ return $this->_ci_init_class($filename, config_item('subclass_prefix'), $params);
}
// Lets search for the requested library file and load it.
- // For backward compatibility we'll test for filenames that are
- // both uppercase and lower.
- foreach (array(ucfirst($class), $class) as $filename)
+ for ($i = 1; $i < 3; $i++)
{
- for ($i = 1; $i < 3; $i++)
+ $path = ($i % 2) ? APPPATH : BASEPATH;
+ if (file_exists($path.'libraries/'.$filename.EXT))
{
- $path = ($i % 2) ? APPPATH : BASEPATH;
-
- if (file_exists($path.'libraries/'.$filename.EXT))
- {
- include_once($path.'libraries/'.$filename.EXT);
- return $this->_ci_init_class($filename, '', $params);
- }
+ include_once($path.'libraries/'.$filename.EXT);
+ return $this->_ci_init_class($filename, '', $params);
}
}
// If we got this far we were unable to find the requested class
log_message('error', "Unable to load the requested class: ".$class);
- show_error("Unable to load the class: ".$class);
+ show_error("Unable to load the requested class: ".$class);
}
// --------------------------------------------------------------------