22/**
33 * Smarty Autoloader
44 *
5- * @package Smarty
5+ * @package Smarty
66 */
77
88/**
99 * Smarty Autoloader
1010 *
11- * @package Smarty
12- * @author Uwe Tews
11+ * @package Smarty
12+ * @author Uwe Tews
1313 * Usage:
14- * require_once '...path/Autoloader.php';
15- * Smarty_Autoloader::register();
16- * $smarty = new Smarty();
17- * Note: This autoloader is not needed if you use Composer.
18- * Composer will automatically add the classes of the Smarty package to it common autoloader.
14+ * require_once '...path/Autoloader.php';
15+ * Smarty_Autoloader::register();
16+ * or
17+ * include '...path/bootstrap.php';
18+ *
19+ * $smarty = new Smarty();
1920 */
2021class Smarty_Autoloader
2122{
@@ -24,14 +25,14 @@ class Smarty_Autoloader
2425 *
2526 * @var string
2627 */
27- public static $ SMARTY_DIR = '' ;
28+ public static $ SMARTY_DIR = null ;
2829
2930 /**
3031 * Filepath to Smarty internal plugins
3132 *
3233 * @var string
3334 */
34- public static $ SMARTY_SYSPLUGINS_DIR = '' ;
35+ public static $ SMARTY_SYSPLUGINS_DIR = null ;
3536
3637 /**
3738 * Array with Smarty core classes and their filename
@@ -53,11 +54,11 @@ public static function registerBC($prepend = false)
5354 if (!defined ('SMARTY_SPL_AUTOLOAD ' )) {
5455 define ('SMARTY_SPL_AUTOLOAD ' , 0 );
5556 }
56- if (SMARTY_SPL_AUTOLOAD &&
57- set_include_path (get_include_path () . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR ) !== false
57+ if (SMARTY_SPL_AUTOLOAD
58+ && set_include_path (get_include_path () . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR ) !== false
5859 ) {
5960 $ registeredAutoLoadFunctions = spl_autoload_functions ();
60- if (!isset ($ registeredAutoLoadFunctions ['spl_autoload ' ])) {
61+ if (!isset ($ registeredAutoLoadFunctions [ 'spl_autoload ' ])) {
6162 spl_autoload_register ();
6263 }
6364 } else {
@@ -75,7 +76,7 @@ public static function register($prepend = false)
7576 self ::$ SMARTY_DIR = defined ('SMARTY_DIR ' ) ? SMARTY_DIR : dirname (__FILE__ ) . DIRECTORY_SEPARATOR ;
7677 self ::$ SMARTY_SYSPLUGINS_DIR = defined ('SMARTY_SYSPLUGINS_DIR ' ) ? SMARTY_SYSPLUGINS_DIR :
7778 self ::$ SMARTY_DIR . 'sysplugins ' . DIRECTORY_SEPARATOR ;
78- if (version_compare (phpversion () , '5.3.0 ' , '>= ' )) {
79+ if (version_compare (PHP_VERSION , '5.3.0 ' , '>= ' )) {
7980 spl_autoload_register (array (__CLASS__ , 'autoload ' ), true , $ prepend );
8081 } else {
8182 spl_autoload_register (array (__CLASS__ , 'autoload ' ));
@@ -89,35 +90,20 @@ public static function register($prepend = false)
8990 */
9091 public static function autoload ($ class )
9192 {
92- $ _class = strtolower ($ class );
93- $ file = self ::$ SMARTY_SYSPLUGINS_DIR . $ _class . '.php ' ;
94- if (strpos ($ _class , 'smarty_internal_ ' ) === 0 ) {
95- if (strpos ($ _class , 'smarty_internal_compile_ ' ) === 0 ) {
96- if (is_file ($ file )) {
97- require $ file ;
98- }
99- return ;
100- }
101- @include $ file ;
93+ if ($ class [ 0 ] !== 'S ' || strpos ($ class , 'Smarty ' ) !== 0 ) {
10294 return ;
10395 }
104- if (preg_match ('/^(smarty_(((template_(source|config|cache|compiled|resource_base))|((cached|compiled)?resource)|(variable|security)))|(smarty(bc)?)$)/ ' ,
105- $ _class , $ match )) {
106- if (!empty ($ match [3 ])) {
107- @include $ file ;
108- return ;
109- } elseif (!empty ($ match [9 ]) && isset (self ::$ rootClasses [$ _class ])) {
110- $ file = self ::$ rootClasses [$ _class ];
111- require $ file ;
112- return ;
96+ $ _class = strtolower ($ class );
97+ if (isset (self ::$ rootClasses [ $ _class ])) {
98+ $ file = self ::$ SMARTY_DIR . self ::$ rootClasses [ $ _class ];
99+ if (is_file ($ file )) {
100+ include $ file ;
101+ }
102+ } else {
103+ $ file = self ::$ SMARTY_SYSPLUGINS_DIR . $ _class . '.php ' ;
104+ if (is_file ($ file )) {
105+ include $ file ;
113106 }
114- }
115- if (0 !== strpos ($ _class , 'smarty ' )) {
116- return ;
117- }
118- if (is_file ($ file )) {
119- require $ file ;
120- return ;
121107 }
122108 return ;
123109 }
0 commit comments