Swift::autoload PHP Method

autoload() public static method

Internal autoloader for spl_autoload_register().
public static autoload ( string $class )
$class string
    public static function autoload($class)
    {
        // Don't interfere with other autoloaders
        if (0 !== strpos($class, 'Swift_')) {
            return;
        }
        $path = dirname(__FILE__) . '/' . str_replace('_', '/', $class) . '.php';
        if (!file_exists($path)) {
            return;
        }
        require $path;
        if (self::$inits && !self::$initialized) {
            self::$initialized = true;
            foreach (self::$inits as $init) {
                call_user_func($init);
            }
        }
    }

Usage Example

Ejemplo n.º 1
0
/**
 * 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);
}
All Usage Examples Of Swift::autoload