public static function auto_load($class)
{
if (class_exists($class, FALSE))
return TRUE;
if (($suffix = strrpos($class, '_')) > 0)
{
// Find the class suffix
$suffix = substr($class, $suffix + 1);
}
else
{
// No suffix
$suffix = FALSE;
}
if ($suffix === 'Core')
{
$type = 'libraries';
$file = substr($class, 0, -5);
}
elseif ($suffix === 'Controller')
{
$type = 'controllers';
// Lowercase filename
$file = strtolower(substr($class, 0, -11));
}
elseif ($suffix === 'Model')
{
$type = 'models';
// Lowercase filename
$file = strtolower(substr($class, 0, -6));
}
elseif ($suffix === 'Driver')
{
$type = 'libraries/drivers';
$file = str_replace('_', '/', substr($class, 0, -7));
}
else
{
// This could be either a library or a helper, but libraries must
// always be capitalized, so we check if the first character is
// uppercase. If it is, we are loading a library, not a helper.
$type = ($class[0] < 'a') ? 'libraries' : 'helpers';
$file = $class;
}
if ($filename = self::find_file($type, $file))
{
// Load the class
require $filename;
}
elseif ($type == 'controllers' && $filename = self::find_file($type, Router::$segments[0].'/'.$file))
{
// Load the class from a controllers subfolder
require $filename;
}
else
{
// The class could not be found
return FALSE;
}
if ($filename = self::find_file($type, self::$configuration['core']['extension_prefix'].$class))
{
// Load the class extension
require $filename;
}
elseif ($suffix !== 'Core' AND class_exists($class.'_Core', FALSE))
{
// Class extension to be evaluated
$extension = 'class '.$class.' extends '.$class.'_Core { }';
// Start class analysis
$core = new ReflectionClass($class.'_Core');
if ($core->isAbstract())
{
// Make the extension abstract
$extension = 'abstract '.$extension;
}
// Transparent class extensions are handled using eval. This is
// a disgusting hack, but it gets the job done.
eval($extension);
}
return TRUE;
}