2014-11-13 19:42:01 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Smarty Autoloader
|
|
|
|
*
|
2018-06-12 09:58:15 +02:00
|
|
|
* @package Smarty
|
2014-11-13 19:42:01 +01:00
|
|
|
*/
|
|
|
|
|
2022-09-22 14:32:55 -07:00
|
|
|
|
|
|
|
if (!defined('SMARTY_HELPER_FUNCTIONS_LOADED')) {
|
2022-09-27 13:03:34 +03:00
|
|
|
include __DIR__ . '/functions.php';
|
2022-09-22 14:32:55 -07:00
|
|
|
}
|
|
|
|
|
2014-11-13 19:42:01 +01:00
|
|
|
/**
|
|
|
|
* Smarty Autoloader
|
|
|
|
*
|
2018-06-12 09:58:15 +02:00
|
|
|
* @package Smarty
|
|
|
|
* @author Uwe Tews
|
2014-11-13 19:42:01 +01:00
|
|
|
* Usage:
|
2016-11-08 17:48:25 +01:00
|
|
|
* require_once '...path/Autoloader.php';
|
|
|
|
* Smarty_Autoloader::register();
|
|
|
|
* or
|
2017-05-27 14:37:35 +02:00
|
|
|
* include '...path/bootstrap.php';
|
2016-11-08 17:48:25 +01:00
|
|
|
*
|
|
|
|
* $smarty = new Smarty();
|
2014-11-13 19:42:01 +01:00
|
|
|
*/
|
|
|
|
class Smarty_Autoloader
|
|
|
|
{
|
2018-06-12 09:58:15 +02:00
|
|
|
/**
|
2014-11-13 19:42:01 +01:00
|
|
|
* Filepath to Smarty root
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-11-08 17:48:25 +01:00
|
|
|
public static $SMARTY_DIR = null;
|
2015-06-27 23:59:12 +02:00
|
|
|
|
2014-11-13 19:42:01 +01:00
|
|
|
/**
|
|
|
|
* Filepath to Smarty internal plugins
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-11-08 17:48:25 +01:00
|
|
|
public static $SMARTY_SYSPLUGINS_DIR = null;
|
2015-06-27 23:59:12 +02:00
|
|
|
|
2014-11-13 19:42:01 +01:00
|
|
|
/**
|
|
|
|
* Array with Smarty core classes and their filename
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2021-10-13 12:15:17 +02:00
|
|
|
public static $rootClasses = array('smarty' => 'Smarty.class.php');
|
2014-11-13 19:42:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers Smarty_Autoloader backward compatible to older installations.
|
|
|
|
*
|
|
|
|
* @param bool $prepend Whether to prepend the autoloader or not.
|
|
|
|
*/
|
|
|
|
public static function registerBC($prepend = false)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* register the class autoloader
|
|
|
|
*/
|
|
|
|
if (!defined('SMARTY_SPL_AUTOLOAD')) {
|
|
|
|
define('SMARTY_SPL_AUTOLOAD', 0);
|
|
|
|
}
|
2018-08-31 16:45:09 +02:00
|
|
|
if (SMARTY_SPL_AUTOLOAD
|
2018-06-12 09:58:15 +02:00
|
|
|
&& set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
|
2015-08-06 00:59:06 +02:00
|
|
|
) {
|
2014-11-13 19:42:01 +01:00
|
|
|
$registeredAutoLoadFunctions = spl_autoload_functions();
|
2016-02-09 01:27:15 +01:00
|
|
|
if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) {
|
2014-11-13 19:42:01 +01:00
|
|
|
spl_autoload_register();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
self::register($prepend);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers Smarty_Autoloader as an SPL autoloader.
|
|
|
|
*
|
|
|
|
* @param bool $prepend Whether to prepend the autoloader or not.
|
|
|
|
*/
|
|
|
|
public static function register($prepend = false)
|
|
|
|
{
|
2022-09-27 13:03:34 +03:00
|
|
|
self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : __DIR__ . DIRECTORY_SEPARATOR;
|
2015-10-24 05:20:09 +02:00
|
|
|
self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR :
|
|
|
|
self::$SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR;
|
2021-10-13 12:15:17 +02:00
|
|
|
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
|
2014-11-13 19:42:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-06-28 08:33:18 +02:00
|
|
|
* Handles auto loading of classes.
|
2014-11-13 19:42:01 +01:00
|
|
|
*
|
|
|
|
* @param string $class A class name.
|
|
|
|
*/
|
|
|
|
public static function autoload($class)
|
|
|
|
{
|
2018-10-14 04:18:45 +02:00
|
|
|
if ($class[ 0 ] !== 'S' || strpos($class, 'Smarty') !== 0) {
|
2015-01-02 09:12:27 +01:00
|
|
|
return;
|
2014-11-13 19:42:01 +01:00
|
|
|
}
|
2022-09-22 14:32:55 -07:00
|
|
|
$_class = smarty_strtolower_ascii($class);
|
2016-11-08 17:48:25 +01:00
|
|
|
if (isset(self::$rootClasses[ $_class ])) {
|
2016-03-09 01:44:10 +01:00
|
|
|
$file = self::$SMARTY_DIR . self::$rootClasses[ $_class ];
|
2016-03-02 18:17:22 +01:00
|
|
|
if (is_file($file)) {
|
|
|
|
include $file;
|
|
|
|
}
|
2016-11-08 17:48:25 +01:00
|
|
|
} else {
|
|
|
|
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
|
|
|
|
if (is_file($file)) {
|
|
|
|
include $file;
|
|
|
|
}
|
2014-12-31 14:32:47 +01:00
|
|
|
}
|
|
|
|
return;
|
2014-11-13 19:42:01 +01:00
|
|
|
}
|
|
|
|
}
|