Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
/**
3
 * Smarty Autoloader
4
 *
5
 * @package Smarty
6
 */
7
 
8
 
9
if (!defined('SMARTY_HELPER_FUNCTIONS_LOADED')) {
10
	include __DIR__ . '/functions.php';
11
}
12
 
13
/**
14
 * Smarty Autoloader
15
 *
16
 * @package Smarty
17
 * @author  Uwe Tews
18
 *             Usage:
19
 *                  require_once '...path/Autoloader.php';
20
 *                  Smarty_Autoloader::register();
21
 *             or
22
 *                  include '...path/bootstrap.php';
23
 *
24
 *                  $smarty = new Smarty();
25
 */
26
class Smarty_Autoloader
27
{
28
    /**
29
     * Filepath to Smarty root
30
     *
31
     * @var string
32
     */
33
    public static $SMARTY_DIR = null;
34
 
35
    /**
36
     * Filepath to Smarty internal plugins
37
     *
38
     * @var string
39
     */
40
    public static $SMARTY_SYSPLUGINS_DIR = null;
41
 
42
    /**
43
     * Array with Smarty core classes and their filename
44
     *
45
     * @var array
46
     */
47
    public static $rootClasses = array('smarty' => 'Smarty.class.php');
48
 
49
    /**
50
     * Registers Smarty_Autoloader backward compatible to older installations.
51
     *
52
     * @param bool $prepend Whether to prepend the autoloader or not.
53
     */
54
    public static function registerBC($prepend = false)
55
    {
56
        /**
57
         * register the class autoloader
58
         */
59
        if (!defined('SMARTY_SPL_AUTOLOAD')) {
60
            define('SMARTY_SPL_AUTOLOAD', 0);
61
        }
62
        if (SMARTY_SPL_AUTOLOAD
63
            && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
64
        ) {
65
            $registeredAutoLoadFunctions = spl_autoload_functions();
66
            if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) {
67
                spl_autoload_register();
68
            }
69
        } else {
70
            self::register($prepend);
71
        }
72
    }
73
 
74
    /**
75
     * Registers Smarty_Autoloader as an SPL autoloader.
76
     *
77
     * @param bool $prepend Whether to prepend the autoloader or not.
78
     */
79
    public static function register($prepend = false)
80
    {
81
        self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : __DIR__ . DIRECTORY_SEPARATOR;
82
        self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR :
83
            self::$SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR;
84
        spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
85
    }
86
 
87
    /**
88
     * Handles auto loading of classes.
89
     *
90
     * @param string $class A class name.
91
     */
92
    public static function autoload($class)
93
    {
94
        if ($class[ 0 ] !== 'S' || strpos($class, 'Smarty') !== 0) {
95
            return;
96
        }
97
        $_class = smarty_strtolower_ascii($class);
98
        if (isset(self::$rootClasses[ $_class ])) {
99
            $file = self::$SMARTY_DIR . self::$rootClasses[ $_class ];
100
            if (is_file($file)) {
101
                include $file;
102
            }
103
        } else {
104
            $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
105
            if (is_file($file)) {
106
                include $file;
107
            }
108
        }
109
        return;
110
    }
111
}