summaryrefslogtreecommitdiffstats
path: root/system/core/Loader.php
diff options
context:
space:
mode:
authorDaniel Hunsaker <danhunsaker@gmail.com>2013-02-22 21:49:33 +0100
committerDaniel Hunsaker <danhunsaker@gmail.com>2013-02-22 21:49:33 +0100
commit44a6d1da2be916fe0f23a3ea4d5fcb391d7f65dd (patch)
tree31549ebf6ea5ea98e4347eb640d1caa685316f3e /system/core/Loader.php
parent353f9834adf3f44c6c7a0f924089bb2b43360404 (diff)
parenteb291c1d1e1116a4420fa30e587adeea0451eeb7 (diff)
Merge branch 'develop' of github.com:EllisLab/CodeIgniter into feature/exit-status
Diffstat (limited to 'system/core/Loader.php')
-rw-r--r--system/core/Loader.php158
1 files changed, 67 insertions, 91 deletions
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 1ad07f1fa..6e5b58ba7 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -97,13 +97,6 @@ class CI_Loader {
protected $_ci_classes = array();
/**
- * List of loaded files
- *
- * @var array
- */
- protected $_ci_loaded_files = array();
-
- /**
* List of loaded models
*
* @var array
@@ -277,7 +270,7 @@ class CI_Loader {
continue;
}
- if ($db_conn !== FALSE && ! class_exists('CI_DB'))
+ if ($db_conn !== FALSE && ! class_exists('CI_DB', FALSE))
{
if ($db_conn === TRUE)
{
@@ -287,7 +280,7 @@ class CI_Loader {
$CI->load->database($db_conn, FALSE, TRUE);
}
- if ( ! class_exists('CI_Model'))
+ if ( ! class_exists('CI_Model', FALSE))
{
load_class('Model', 'core');
}
@@ -943,7 +936,6 @@ class CI_Loader {
// Was the path included with the class name?
// We look for a slash to determine this
- $subdir = '';
if (($last_slash = strrpos($class, '/')) !== FALSE)
{
// Extract the path
@@ -952,108 +944,92 @@ class CI_Loader {
// Get the filename from the path
$class = substr($class, $last_slash);
}
+ else
+ {
+ $subdir = '';
+ }
+
+ $class = ucfirst($class);
+ $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php';
- // We'll test for both lowercase and capitalized versions of the file name
- foreach (array(ucfirst($class), strtolower($class)) as $class)
+ // Is this a class extension request?
+ if (file_exists($subclass))
{
- $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php';
+ $baseclass = BASEPATH.'libraries/'.$class.'.php';
- // Is this a class extension request?
- if (file_exists($subclass))
+ if ( ! file_exists($baseclass))
{
- $baseclass = BASEPATH.'libraries/'.ucfirst($class).'.php';
-
- if ( ! file_exists($baseclass))
- {
- log_message('error', 'Unable to load the requested class: '.$class);
- show_error('Unable to load the requested class: '.$class);
- }
+ log_message('error', 'Unable to load the requested class: '.$class);
+ show_error('Unable to load the requested class: '.$class);
+ }
- // Safety: Was the class already loaded by a previous call?
- if (in_array($subclass, $this->_ci_loaded_files))
+ // Safety: Was the class already loaded by a previous call?
+ if (class_exists(config_item('subclass_prefix').$class, FALSE))
+ {
+ // Before we deem this to be a duplicate request, let's see
+ // if a custom object name is being supplied. If so, we'll
+ // return a new instance of the object
+ if ($object_name !== NULL)
{
- // Before we deem this to be a duplicate request, let's see
- // if a custom object name is being supplied. If so, we'll
- // return a new instance of the object
- if ($object_name !== NULL)
+ $CI =& get_instance();
+ if ( ! isset($CI->$object_name))
{
- $CI =& get_instance();
- if ( ! isset($CI->$object_name))
- {
- return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
- }
+ return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
}
-
- $is_duplicate = TRUE;
- log_message('debug', $class.' class already loaded. Second attempt ignored.');
- return;
}
- include_once($baseclass);
- include_once($subclass);
- $this->_ci_loaded_files[] = $subclass;
-
- return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
+ log_message('debug', $class.' class already loaded. Second attempt ignored.');
+ return;
}
- // Lets search for the requested library file and load it.
- $is_duplicate = FALSE;
- foreach ($this->_ci_library_paths as $path)
- {
- $filepath = $path.'libraries/'.$subdir.$class.'.php';
+ include_once($baseclass);
+ include_once($subclass);
- // Does the file exist? No? Bummer...
- if ( ! file_exists($filepath))
- {
- continue;
- }
+ return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
+ }
+
+ // Let's search for the requested library file and load it.
+ foreach ($this->_ci_library_paths as $path)
+ {
+ $filepath = $path.'libraries/'.$subdir.$class.'.php';
- // Safety: Was the class already loaded by a previous call?
- if (in_array($filepath, $this->_ci_loaded_files))
+ // Safety: Was the class already loaded by a previous call?
+ if (class_exists($class, FALSE))
+ {
+ // Before we deem this to be a duplicate request, let's see
+ // if a custom object name is being supplied. If so, we'll
+ // return a new instance of the object
+ if ($object_name !== NULL)
{
- // Before we deem this to be a duplicate request, let's see
- // if a custom object name is being supplied. If so, we'll
- // return a new instance of the object
- if ($object_name !== NULL)
+ $CI =& get_instance();
+ if ( ! isset($CI->$object_name))
{
- $CI =& get_instance();
- if ( ! isset($CI->$object_name))
- {
- return $this->_ci_init_class($class, '', $params, $object_name);
- }
+ return $this->_ci_init_class($class, '', $params, $object_name);
}
-
- $is_duplicate = TRUE;
- log_message('debug', $class.' class already loaded. Second attempt ignored.');
- return;
}
- include_once($filepath);
- $this->_ci_loaded_files[] = $filepath;
- return $this->_ci_init_class($class, '', $params, $object_name);
+ log_message('debug', $class.' class already loaded. Second attempt ignored.');
+ return;
+ }
+ // Does the file exist? No? Bummer...
+ elseif ( ! file_exists($filepath))
+ {
+ continue;
}
- } // END FOREACH
+
+ include_once($filepath);
+ return $this->_ci_init_class($class, '', $params, $object_name);
+ }
// One last attempt. Maybe the library is in a subdirectory, but it wasn't specified?
if ($subdir === '')
{
- $path = strtolower($class).'/'.$class;
- return $this->_ci_load_class($path, $params, $object_name);
- }
- elseif (ucfirst($subdir) != $subdir)
- {
- // Lowercase subdir failed - retry capitalized
- $path = ucfirst($subdir).$class;
- return $this->_ci_load_class($path, $params, $object_name);
+ return $this->_ci_load_class($class.'/'.$class, $params, $object_name);
}
// If we got this far we were unable to find the requested class.
- // We do not issue errors if the load call failed due to a duplicate request
- if ($is_duplicate === FALSE)
- {
- log_message('error', 'Unable to load the requested class: '.$class);
- show_error('Unable to load the requested class: '.$class);
- }
+ log_message('error', 'Unable to load the requested class: '.$class);
+ show_error('Unable to load the requested class: '.$class);
}
// --------------------------------------------------------------------
@@ -1089,12 +1065,12 @@ class CI_Loader {
// We test for both uppercase and lowercase, for servers that
// are case-sensitive with regard to file names. Check for environment
// first, global next
- if (defined('ENVIRONMENT') && file_exists($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'))
+ if (file_exists($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'))
{
include($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php');
break;
}
- elseif (defined('ENVIRONMENT') && file_exists($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'))
+ elseif (file_exists($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'))
{
include($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php');
break;
@@ -1115,11 +1091,11 @@ class CI_Loader {
if ($prefix === '')
{
- if (class_exists('CI_'.$class))
+ if (class_exists('CI_'.$class, FALSE))
{
$name = 'CI_'.$class;
}
- elseif (class_exists(config_item('subclass_prefix').$class))
+ elseif (class_exists(config_item('subclass_prefix').$class, FALSE))
{
$name = config_item('subclass_prefix').$class;
}
@@ -1134,7 +1110,7 @@ class CI_Loader {
}
// Is the class name valid?
- if ( ! class_exists($name))
+ if ( ! class_exists($name, FALSE))
{
log_message('error', 'Non-existent class: '.$name);
show_error('Non-existent class: '.$name);
@@ -1180,7 +1156,7 @@ class CI_Loader {
*/
protected function _ci_autoloader()
{
- if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'))
+ if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php');
}