I was just trying something and thought the following may be a nice feature.
Say I want to extend a modules library. When loading a module library it looks for MY_* files but they can only extend the core applications libraries, THEY CANNOT EXTEND A CURRENT MODULE LIBRARY. So I have changed some of the load code so it first checks to see if its meant to extend a module library before it checks if your extending a application library and then a base core library. Looking at the code will explain what I mean if you don’t get me.
function _ci_load_class($class, $params = NULL)
{
// Get the class name
$class = str_replace(EXT, '', $class);
// We'll test for both lowercase and capitalized versions of the file name
foreach (array(ucfirst($class), strtolower($class)) as $class)
{
// {{{ Matchbox
$module = $this->_matchbox->argument(2);
if ($subclass = $this->_matchbox->find('libraries/' . config_item('subclass_prefix') . $class . EXT, $module)) {
$baseclass = $this->_matchbox->find('libraries/'. $class . EXT, $module);
if ( ! file_exists($baseclass))
{
log_message('debug', "Unable to load the requested class: ".$class." in module: ".$module);
$baseclass = APPPATH.'libraries/'.ucfirst($class).EXT;
if ( ! file_exists($baseclass))
{
log_message('debug', "Unable to load the requested application class: ".$class);
$baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT;
if ( ! file_exists($baseclass))
{
log_message('debug', "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_classes))
{
$is_duplicate = TRUE;
log_message('debug', $class." class already loaded. Second attempt ignored.");
return;
}
include($baseclass);
include($subclass);
$this->_ci_classes[] = $subclass;
// {{{ Matchbox
return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $module);
// }}}
}
// Lets search for the requested library file and load it.
$is_duplicate = FALSE;
// {{{ Matchbox
if ($filepath = $this->_matchbox->find('libraries/' . $class . EXT, $module, 2)) {
if (in_array($class, $this->_ci_classes)) {
$is_duplicate = true;
log_message('debug', $class . ' class already loaded. Second attempt ignored.');
return;
}
include($filepath);
$this->_ci_classes[] = $class;
return $this->_ci_init_class($class, '', $params, $module);
}
// }}}
} // END FOREACH
// 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);
}
}
Don’t know if my nested for loops is the best way to achive this?