/**
* Class autoloader
*
* Include classes automatically when they are instantiated.
* @param string
*/
function __autoload($strClassName)
{
$objCache = FileCache::getInstance('autoload');
// Try to load the class name from the session cache
if (!$GLOBALS['TL_CONFIG']['debugMode'] && isset($objCache->{$strClassName})) {
if (@(include_once TL_ROOT . '/' . $objCache->{$strClassName})) {
return;
// The class could be loaded
} else {
unset($objCache->{$strClassName});
// The class has been removed
}
}
$strLibrary = TL_ROOT . '/system/libraries/' . $strClassName . '.php';
// Check for libraries first
if (file_exists($strLibrary)) {
include_once $strLibrary;
$objCache->{$strClassName} = 'system/libraries/' . $strClassName . '.php';
return;
}
// Then check the modules folder
foreach (scan(TL_ROOT . '/system/modules/') as $strFolder) {
if (substr($strFolder, 0, 1) == '.') {
continue;
}
$strModule = TL_ROOT . '/system/modules/' . $strFolder . '/' . $strClassName . '.php';
if (file_exists($strModule)) {
include_once $strModule;
$objCache->{$strClassName} = 'system/modules/' . $strFolder . '/' . $strClassName . '.php';
return;
}
}
// HOOK: include Swift classes
if (class_exists('Swift', false)) {
Swift::autoload($strClassName);
return;
}
// HOOK: include DOMPDF classes
if (function_exists('DOMPDF_autoload')) {
DOMPDF_autoload($strClassName);
return;
}
trigger_error(sprintf('Could not load class %s', $strClassName), E_USER_ERROR);
}