<?php
class MY_Loader extends CI_Loader {
function MY_Loader()
{
parent::CI_Loader();
}
/**
* Load class
*
* This function loads the requested class.
*
* @access private
* @param string the item that is being loaded
* @param mixed any additional parameters
* @return void
*/
function _ci_load_class($class, $params = NULL)
{
// Get the class name
$class = str_replace(EXT, '', strtolower($class));
// We'll test for both lowercase and capitalized versions of the file name
foreach (array($class, ucfirst($class)) as $class)
{
$fp = $this->_ci_find_class($class);
$ex = $this->_ci_find_class(config_item('subclass_prefix').$class);
// Extension found, but no class found
if ($ex == TRUE AND $fp == FALSE)
{
log_message('error', "Unable to load the requested class: ".$class);
show_error("Unable to load the requested class: ".$class);
}
// Class is already loaded, log a message and stop
if ($fp === TRUE)
{
log_message('debug', $class." class already loaded. Second attempt ignored.");
return;
}
// No class found
if ($fp == FALSE)
{
continue;
}
else
{
include($fp);
}
// For safety checks
$this->_ci_classes[] = $fp;
// Include extension, if one was found
if ($ex == TRUE)
{
include($ex);
return $this->_ci_init_class($class, config_item('subclass_prefix'), $params);
}
else
{
return $this->_ci_init_class($class, '', $params);
}
}// END FOREACH
// If we got this far we were unable to find the requested class
log_message('error', "Unable to load the requested class: ".$class);
show_error("Unable to load the requested class: ".$class);
}
// --------------------------------------------------------------------
/**
* Find class
*
* This function finds the requested class.
*
* @access private
* @param string the item that is being loaded
* @param array paths to search in
* @return void
*/
function _ci_find_class($class, $paths = false)
{
// Default to using the standard paths
if ( ! is_array($paths))
{
$paths = array(APPPATH, BASEPATH);
}
foreach ($paths as $path)
{
$fp = $path.'libraries/'.$class.EXT;
// Safety: Was the class already loaded by a previous call?
if (in_array($fp, $this->_ci_classes))
{
return TRUE;
}
// Does the file exist?
if (file_exists($fp))
{
return $fp;
}
}
// No class was found
return FALSE;
}
// --------------------------------------------------------------------
}
?>