From 894a3f2c9fe111af35dee4f5e8e711259b893fb6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 27 Jun 2017 16:31:17 +0300 Subject: Fix #5164 --- system/core/Loader.php | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'system/core/Loader.php') diff --git a/system/core/Loader.php b/system/core/Loader.php index 5ed6adb48..7be5fd41b 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -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 ( ! isset($property)) + { + $property = strtolower($class); + isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$object_name]; + } + + $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; } -- cgit v1.2.3-24-g4f1b From db89c20721b3b66671db9ff4d3b6c9a6de352533 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 28 Jun 2017 11:18:24 +0300 Subject: Correct fix for #5164 894a3f2c9fe111af35dee4f5e8e711259b893fb6 --- system/core/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Loader.php') diff --git a/system/core/Loader.php b/system/core/Loader.php index 7be5fd41b..cae01ed38 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -1044,7 +1044,7 @@ class CI_Loader { if ( ! isset($property)) { $property = strtolower($class); - isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$object_name]; + isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property]; } $CI =& get_instance(); -- cgit v1.2.3-24-g4f1b From be0280d02a408a8b4aeb6aee10d9dd936f978ce2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 28 Jun 2017 11:49:01 +0300 Subject: #5164 fix for stock libraries --- system/core/Loader.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'system/core/Loader.php') diff --git a/system/core/Loader.php b/system/core/Loader.php index cae01ed38..12922ca64 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -1041,7 +1041,7 @@ class CI_Loader { if (class_exists($class, FALSE)) { $property = $object_name; - if ( ! isset($property)) + if (empty($property)) { $property = strtolower($class); isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property]; @@ -1113,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.'); -- cgit v1.2.3-24-g4f1b From c58b005c5497419dd7ab79fc29ac7e5344c95039 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 28 Jun 2017 11:50:27 +0300 Subject: [ci skip] Remove redundant elses from CI_Loader::_ci_load_stock_library() --- system/core/Loader.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'system/core/Loader.php') diff --git a/system/core/Loader.php b/system/core/Loader.php index 12922ca64..df93d591f 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -1145,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); } } @@ -1166,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); } } -- cgit v1.2.3-24-g4f1b From 9bceb9c7c83082cd3d3aa2c96e5eb8c210890ade Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 6 Jul 2017 15:12:09 +0300 Subject: [ci skip] Merge pull request #5173 from Syafiqq/develop Add array identifier for library loader docblock --- system/core/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Loader.php') diff --git a/system/core/Loader.php b/system/core/Loader.php index df93d591f..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 -- cgit v1.2.3-24-g4f1b