summaryrefslogtreecommitdiffstats
path: root/system/codeigniter
diff options
context:
space:
mode:
Diffstat (limited to 'system/codeigniter')
-rw-r--r--system/codeigniter/Common.php78
1 files changed, 36 insertions, 42 deletions
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