1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: |
|
7: |
|
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: |
|
21: | class Smarty_Autoloader
|
22: | {
|
23: | |
24: | |
25: | |
26: | |
27: |
|
28: | public static $SMARTY_DIR = null;
|
29: |
|
30: | |
31: | |
32: | |
33: | |
34: |
|
35: | public static $SMARTY_SYSPLUGINS_DIR = null;
|
36: |
|
37: | |
38: | |
39: | |
40: | |
41: |
|
42: | public static $rootClasses = array('smarty' => 'Smarty.class.php', 'smartybc' => 'SmartyBC.class.php',);
|
43: |
|
44: | |
45: | |
46: | |
47: | |
48: |
|
49: | public static function registerBC($prepend = false)
|
50: | {
|
51: | |
52: | |
53: |
|
54: | if (!defined('SMARTY_SPL_AUTOLOAD')) {
|
55: | define('SMARTY_SPL_AUTOLOAD', 0);
|
56: | }
|
57: | if (SMARTY_SPL_AUTOLOAD
|
58: | && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
|
59: | ) {
|
60: | $registeredAutoLoadFunctions = spl_autoload_functions();
|
61: | if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) {
|
62: | spl_autoload_register();
|
63: | }
|
64: | } else {
|
65: | self::register($prepend);
|
66: | }
|
67: | }
|
68: |
|
69: | |
70: | |
71: | |
72: | |
73: |
|
74: | public static function register($prepend = false)
|
75: | {
|
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(PHP_VERSION, '5.3.0', '>=')) {
|
80: | spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
|
81: | } else {
|
82: | spl_autoload_register(array(__CLASS__, 'autoload'));
|
83: | }
|
84: | }
|
85: |
|
86: | |
87: | |
88: | |
89: | |
90: |
|
91: | public static function autoload($class)
|
92: | {
|
93: | if ($class[ 0 ] !== 'S' || strpos($class, 'Smarty') !== 0) {
|
94: | return;
|
95: | }
|
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;
|
106: | }
|
107: | }
|
108: | return;
|
109: | }
|
110: | }
|
111: | |