summaryrefslogtreecommitdiffstats
path: root/system/core/Loader.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2017-09-25 18:44:51 +0200
committerAndrey Andreev <narf@devilix.net>2017-09-25 18:44:51 +0200
commite76217041ddcae80f11b50b44a7d409b6722ad40 (patch)
tree6f7dd444bfc5b4206a6e07169ad3c05b9b63fa4d /system/core/Loader.php
parent9c07c3697bab0bf43e10daf59068497dd3a0a9fd (diff)
parentcf728703b5852591c160cbd9566a0e508dd5759a (diff)
Merge branch '3.1-stable'
Diffstat (limited to 'system/core/Loader.php')
-rw-r--r--system/core/Loader.php76
1 files changed, 37 insertions, 39 deletions
diff --git a/system/core/Loader.php b/system/core/Loader.php
index acfc739dd..085c5b51d 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -182,7 +182,7 @@ class CI_Loader {
* Loads and instantiates libraries.
* Designed to be called from application controllers.
*
- * @param string $library Library name
+ * @param mixed $library Library name
* @param array $params Optional parameters to pass to the library class constructor
* @param string $object_name An optional object name to assign to
* @return object
@@ -590,7 +590,7 @@ class CI_Loader {
{
$filename = basename($helper);
$filepath = ($filename === $helper) ? '' : substr($helper, 0, strlen($helper) - strlen($filename));
- $filename = strtolower(preg_replace('#(_helper)?(.php)?$#i', '', $filename)).'_helper';
+ $filename = strtolower(preg_replace('#(_helper)?(\.php)?$#i', '', $filename)).'_helper';
$helper = $filepath.$filename;
if (isset($this->_ci_helpers[$helper]))
@@ -1037,6 +1037,26 @@ class CI_Loader {
return $this->_ci_load_stock_library($class, $subdir, $params, $object_name);
}
+ // Safety: Was the class already loaded by a previous call?
+ if (class_exists($class, FALSE))
+ {
+ $property = $object_name;
+ if (empty($property))
+ {
+ $property = strtolower($class);
+ isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property];
+ }
+
+ $CI =& get_instance();
+ if (isset($CI->$property))
+ {
+ log_message('debug', $class.' class already loaded. Second attempt ignored.');
+ return;
+ }
+
+ return $this->_ci_init_library($class, '', $params, $object_name);
+ }
+
// Let's search for the requested library file and load it.
foreach ($this->_ci_library_paths as $path)
{
@@ -1047,27 +1067,8 @@ class CI_Loader {
}
$filepath = $path.'libraries/'.$subdir.$class.'.php';
-
- // 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)
- {
- $CI =& get_instance();
- if ( ! isset($CI->$object_name))
- {
- return $this->_ci_init_library($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))
+ if ( ! file_exists($filepath))
{
continue;
}
@@ -1112,16 +1113,17 @@ class CI_Loader {
$prefix = config_item('subclass_prefix');
}
- // 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)
+ $property = $object_name;
+ if (empty($property))
{
- $CI =& get_instance();
- if ( ! isset($CI->$object_name))
- {
- return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
- }
+ $property = strtolower($library_name);
+ isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property];
+ }
+
+ $CI =& get_instance();
+ if ( ! isset($CI->$property))
+ {
+ return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
}
log_message('debug', $library_name.' class already loaded. Second attempt ignored.');
@@ -1143,10 +1145,8 @@ class CI_Loader {
{
return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
}
- else
- {
- log_message('debug', $path.' exists, but does not declare '.$prefix.$library_name);
- }
+
+ log_message('debug', $path.' exists, but does not declare '.$prefix.$library_name);
}
}
@@ -1164,10 +1164,8 @@ class CI_Loader {
$prefix = config_item('subclass_prefix');
break;
}
- else
- {
- log_message('debug', $path.' exists, but does not declare '.$subclass);
- }
+
+ log_message('debug', $path.' exists, but does not declare '.$subclass);
}
}