@@ -182,7 +182,7 @@ public function is_loaded($class)
182182 * Loads and instantiates libraries.
183183 * Designed to be called from application controllers.
184184 *
185- * @param string $library Library name
185+ * @param mixed $library Library name
186186 * @param array $params Optional parameters to pass to the library class constructor
187187 * @param string $object_name An optional object name to assign to
188188 * @return object
@@ -1037,6 +1037,26 @@ protected function _ci_load_library($class, $params = NULL, $object_name = NULL)
10371037 return $ this ->_ci_load_stock_library ($ class , $ subdir , $ params , $ object_name );
10381038 }
10391039
1040+ // Safety: Was the class already loaded by a previous call?
1041+ if (class_exists ($ class , FALSE ))
1042+ {
1043+ $ property = $ object_name ;
1044+ if (empty ($ property ))
1045+ {
1046+ $ property = strtolower ($ class );
1047+ isset ($ this ->_ci_varmap [$ property ]) && $ property = $ this ->_ci_varmap [$ property ];
1048+ }
1049+
1050+ $ CI =& get_instance ();
1051+ if (isset ($ CI ->$ property ))
1052+ {
1053+ log_message ('debug ' , $ class .' class already loaded. Second attempt ignored. ' );
1054+ return ;
1055+ }
1056+
1057+ return $ this ->_ci_init_library ($ class , '' , $ params , $ object_name );
1058+ }
1059+
10401060 // Let's search for the requested library file and load it.
10411061 foreach ($ this ->_ci_library_paths as $ path )
10421062 {
@@ -1047,27 +1067,8 @@ protected function _ci_load_library($class, $params = NULL, $object_name = NULL)
10471067 }
10481068
10491069 $ filepath = $ path .'libraries/ ' .$ subdir .$ class .'.php ' ;
1050-
1051- // Safety: Was the class already loaded by a previous call?
1052- if (class_exists ($ class , FALSE ))
1053- {
1054- // Before we deem this to be a duplicate request, let's see
1055- // if a custom object name is being supplied. If so, we'll
1056- // return a new instance of the object
1057- if ($ object_name !== NULL )
1058- {
1059- $ CI =& get_instance ();
1060- if ( ! isset ($ CI ->$ object_name ))
1061- {
1062- return $ this ->_ci_init_library ($ class , '' , $ params , $ object_name );
1063- }
1064- }
1065-
1066- log_message ('debug ' , $ class .' class already loaded. Second attempt ignored. ' );
1067- return ;
1068- }
10691070 // Does the file exist? No? Bummer...
1070- elseif ( ! file_exists ($ filepath ))
1071+ if ( ! file_exists ($ filepath ))
10711072 {
10721073 continue ;
10731074 }
@@ -1112,16 +1113,17 @@ protected function _ci_load_stock_library($library_name, $file_path, $params, $o
11121113 $ prefix = config_item ('subclass_prefix ' );
11131114 }
11141115
1115- // Before we deem this to be a duplicate request, let's see
1116- // if a custom object name is being supplied. If so, we'll
1117- // return a new instance of the object
1118- if ($ object_name !== NULL )
1116+ $ property = $ object_name ;
1117+ if (empty ($ property ))
11191118 {
1120- $ CI =& get_instance ();
1121- if ( ! isset ($ CI ->$ object_name ))
1122- {
1123- return $ this ->_ci_init_library ($ library_name , $ prefix , $ params , $ object_name );
1124- }
1119+ $ property = strtolower ($ library_name );
1120+ isset ($ this ->_ci_varmap [$ property ]) && $ property = $ this ->_ci_varmap [$ property ];
1121+ }
1122+
1123+ $ CI =& get_instance ();
1124+ if ( ! isset ($ CI ->$ property ))
1125+ {
1126+ return $ this ->_ci_init_library ($ library_name , $ prefix , $ params , $ object_name );
11251127 }
11261128
11271129 log_message ('debug ' , $ library_name .' class already loaded. Second attempt ignored. ' );
@@ -1143,10 +1145,8 @@ protected function _ci_load_stock_library($library_name, $file_path, $params, $o
11431145 {
11441146 return $ this ->_ci_init_library ($ library_name , $ prefix , $ params , $ object_name );
11451147 }
1146- else
1147- {
1148- log_message ('debug ' , $ path .' exists, but does not declare ' .$ prefix .$ library_name );
1149- }
1148+
1149+ log_message ('debug ' , $ path .' exists, but does not declare ' .$ prefix .$ library_name );
11501150 }
11511151 }
11521152
@@ -1164,10 +1164,8 @@ protected function _ci_load_stock_library($library_name, $file_path, $params, $o
11641164 $ prefix = config_item ('subclass_prefix ' );
11651165 break ;
11661166 }
1167- else
1168- {
1169- log_message ('debug ' , $ path .' exists, but does not declare ' .$ subclass );
1170- }
1167+
1168+ log_message ('debug ' , $ path .' exists, but does not declare ' .$ subclass );
11711169 }
11721170 }
11731171
0 commit comments