2
2
/**
3
3
* Smarty Autoloader
4
4
*
5
- * @package Smarty
5
+ * @package Smarty
6
6
*/
7
7
8
8
/**
9
9
* Smarty Autoloader
10
10
*
11
- * @package Smarty
12
- * @author Uwe Tews
11
+ * @package Smarty
12
+ * @author Uwe Tews
13
13
* 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();
19
20
*/
20
21
class Smarty_Autoloader
21
22
{
@@ -24,14 +25,14 @@ class Smarty_Autoloader
24
25
*
25
26
* @var string
26
27
*/
27
- public static $ SMARTY_DIR = '' ;
28
+ public static $ SMARTY_DIR = null ;
28
29
29
30
/**
30
31
* Filepath to Smarty internal plugins
31
32
*
32
33
* @var string
33
34
*/
34
- public static $ SMARTY_SYSPLUGINS_DIR = '' ;
35
+ public static $ SMARTY_SYSPLUGINS_DIR = null ;
35
36
36
37
/**
37
38
* Array with Smarty core classes and their filename
@@ -53,11 +54,11 @@ public static function registerBC($prepend = false)
53
54
if (!defined ('SMARTY_SPL_AUTOLOAD ' )) {
54
55
define ('SMARTY_SPL_AUTOLOAD ' , 0 );
55
56
}
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
58
59
) {
59
60
$ registeredAutoLoadFunctions = spl_autoload_functions ();
60
- if (!isset ($ registeredAutoLoadFunctions ['spl_autoload ' ])) {
61
+ if (!isset ($ registeredAutoLoadFunctions [ 'spl_autoload ' ])) {
61
62
spl_autoload_register ();
62
63
}
63
64
} else {
@@ -75,7 +76,7 @@ public static function register($prepend = false)
75
76
self ::$ SMARTY_DIR = defined ('SMARTY_DIR ' ) ? SMARTY_DIR : dirname (__FILE__ ) . DIRECTORY_SEPARATOR ;
76
77
self ::$ SMARTY_SYSPLUGINS_DIR = defined ('SMARTY_SYSPLUGINS_DIR ' ) ? SMARTY_SYSPLUGINS_DIR :
77
78
self ::$ SMARTY_DIR . 'sysplugins ' . DIRECTORY_SEPARATOR ;
78
- if (version_compare (phpversion () , '5.3.0 ' , '>= ' )) {
79
+ if (version_compare (PHP_VERSION , '5.3.0 ' , '>= ' )) {
79
80
spl_autoload_register (array (__CLASS__ , 'autoload ' ), true , $ prepend );
80
81
} else {
81
82
spl_autoload_register (array (__CLASS__ , 'autoload ' ));
@@ -89,35 +90,20 @@ public static function register($prepend = false)
89
90
*/
90
91
public static function autoload ($ class )
91
92
{
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 ) {
102
94
return ;
103
95
}
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 ;
113
106
}
114
- }
115
- if (0 !== strpos ($ _class , 'smarty ' )) {
116
- return ;
117
- }
118
- if (is_file ($ file )) {
119
- require $ file ;
120
- return ;
121
107
}
122
108
return ;
123
109
}
0 commit comments