14 * require_once '...path/Autoloader.php';
15 * Smarty_Autoloader::register();
17 * include '...path/bootstarp.php';
19 * $smarty = new Smarty();
21 class Smarty_Autoloader
24 * Filepath to Smarty root
28 public static $SMARTY_DIR = null;
31 * Filepath to Smarty internal plugins
35 public static $SMARTY_SYSPLUGINS_DIR = null;
38 * Array with Smarty core classes and their filename
42 public static $rootClasses = array('smarty' => 'Smarty.class.php', 'smartybc' => 'SmartyBC.class.php',);
45 * Registers Smarty_Autoloader backward compatible to older installations.
47 * @param bool $prepend Whether to prepend the autoloader or not.
49 public static function registerBC($prepend = false)
52 * register the class autoloader
54 if (!defined('SMARTY_SPL_AUTOLOAD')) {
55 define('SMARTY_SPL_AUTOLOAD', 0);
57 if (SMARTY_SPL_AUTOLOAD &&
58 set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
60 $registeredAutoLoadFunctions = spl_autoload_functions();
61 if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) {
62 spl_autoload_register();
65 self::register($prepend);
70 * Registers Smarty_Autoloader as an SPL autoloader.
72 * @param bool $prepend Whether to prepend the autoloader or not.
74 public static function register($prepend = false)
76 self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . DIRECTORY_SEPARATOR;
77 self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR :
78 self::$SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR;
79 if (version_compare(phpversion(), '5.3.0', '>=')) {
80 spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
82 spl_autoload_register(array(__CLASS__, 'autoload'));
87 * Handles auto loading of classes.
89 * @param string $class A class name.
91 public static function autoload($class)
93 if ($class[ 0 ] !== 'S' && strpos($class, 'Smarty') !== 0) {
96 $_class = strtolower($class);
97 if (isset(self::$rootClasses[ $_class ])) {
98 $file = self::$SMARTY_DIR . self::$rootClasses[ $_class ];
103 $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
104 if (is_file($file)) {