move autoload code into Autoloader.php.

Use Composer autoloader when possible
This commit is contained in:
Uwe Tews
2014-11-13 19:42:01 +01:00
parent 0b21213c55
commit 0b6af0add7
4 changed files with 130 additions and 50 deletions
+14 -49
View File
@@ -2,7 +2,7 @@
/**
* Project: Smarty: the PHP compiling template engine
* File: Smarty.class.php
* SVN: $Id: Smarty.class.php 4897 2014-10-14 22:29:58Z Uwe.Tews@googlemail.com $
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
@@ -70,33 +70,25 @@ if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) {
}
/**
* register the class autoloader
* Try loading the Smmarty_Internal_Data class
*
* If we fail we must load Smarty's autoloader.
* Otherwise we may have a global autoloader like Composer
*/
if (!defined('SMARTY_SPL_AUTOLOAD')) {
define('SMARTY_SPL_AUTOLOAD', 0);
}
if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false) {
$registeredAutoLoadFunctions = spl_autoload_functions();
if (!isset($registeredAutoLoadFunctions['spl_autoload'])) {
spl_autoload_register();
}
} else {
spl_autoload_register('smartyAutoload');
if (!class_exists('Smarty_Internal_Data', true)) {
require 'Autoloader.php';
Smarty_Autoloader::registerBC();
require SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php';
}
/**
* Load always needed external class files
*/
/**
include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php';
include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php';
include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php';
include_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php';
include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php';
include_once SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php';
include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_cacheresource_file.php';
* /
require SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php';
require SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php';
require SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php';
require SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php';
/**
* This is the main Smarty class
@@ -1595,30 +1587,3 @@ class Smarty extends Smarty_Internal_TemplateBase
restore_error_handler();
}
}
/**
* Autoloader
*/
function smartyAutoload($class)
{
$_class = strtolower($class);
static $_classes = array(
'smarty_config_source' => true,
'smarty_config_compiled' => true,
'smarty_security' => true,
'smarty_cacheresource' => true,
'smarty_cacheresource_custom' => true,
'smarty_cacheresource_keyvaluestore' => true,
'smarty_resource' => true,
'smarty_resource_custom' => true,
'smarty_resource_uncompiled' => true,
'smarty_resource_recompiled' => true,
'smartyexception' => true,
'smartycompilerexception' => true,
);
if (!strncmp($_class, 'smarty_internal_', 16) || isset($_classes[$_class])) {
include SMARTY_SYSPLUGINS_DIR . $_class . '.php';
}
}