mirror of
https://github.com/smarty-php/smarty.git
synced 2025-10-17 06:25:19 +02:00
Adds support for PHP8.0, dropping support for PHP7.0 and below. Backwards incompatible changes: - Dropped support for php asp tags in templates (removed from php since php7.0) - Dropped deprecated API calls that where only accessible through SmartyBC - Dropped support for {php} and {include_php} tags and embedded PHP in templates. Embedded PHP will now be passed through as is. - Removed all PHP_VERSION_ID and compare_version checks and conditional code blocks that are now no longer required - Dropped deprecated SMARTY_RESOURCE_CHAR_SET and SMARTY_RESOURCE_DATE_FORMAT constants - Dropped deprecated Smarty::muteExpectedErrors and Smarty::unmuteExpectedErrors API methods - Dropped deprecated $smarty->getVariable() method. Use $smarty->getTemplateVars() instead. - $smarty->registerResource() no longer accepts an array of callback functions See the changelog for more details. Switched CI from Travis to Github CI.
107 lines
2.8 KiB
PHP
107 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* Smarty Autoloader
|
|
*
|
|
* @package Smarty
|
|
*/
|
|
|
|
/**
|
|
* Smarty Autoloader
|
|
*
|
|
* @package Smarty
|
|
* @author Uwe Tews
|
|
* Usage:
|
|
* require_once '...path/Autoloader.php';
|
|
* Smarty_Autoloader::register();
|
|
* or
|
|
* include '...path/bootstrap.php';
|
|
*
|
|
* $smarty = new Smarty();
|
|
*/
|
|
class Smarty_Autoloader
|
|
{
|
|
/**
|
|
* Filepath to Smarty root
|
|
*
|
|
* @var string
|
|
*/
|
|
public static $SMARTY_DIR = null;
|
|
|
|
/**
|
|
* Filepath to Smarty internal plugins
|
|
*
|
|
* @var string
|
|
*/
|
|
public static $SMARTY_SYSPLUGINS_DIR = null;
|
|
|
|
/**
|
|
* Array with Smarty core classes and their filename
|
|
*
|
|
* @var array
|
|
*/
|
|
public static $rootClasses = array('smarty' => 'Smarty.class.php');
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
if (SMARTY_SPL_AUTOLOAD
|
|
&& set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
|
|
) {
|
|
$registeredAutoLoadFunctions = spl_autoload_functions();
|
|
if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) {
|
|
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)
|
|
{
|
|
self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . DIRECTORY_SEPARATOR;
|
|
self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR :
|
|
self::$SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR;
|
|
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
|
|
}
|
|
|
|
/**
|
|
* Handles auto loading of classes.
|
|
*
|
|
* @param string $class A class name.
|
|
*/
|
|
public static function autoload($class)
|
|
{
|
|
if ($class[ 0 ] !== 'S' || strpos($class, 'Smarty') !== 0) {
|
|
return;
|
|
}
|
|
$_class = strtolower($class);
|
|
if (isset(self::$rootClasses[ $_class ])) {
|
|
$file = self::$SMARTY_DIR . self::$rootClasses[ $_class ];
|
|
if (is_file($file)) {
|
|
include $file;
|
|
}
|
|
} else {
|
|
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
|
|
if (is_file($file)) {
|
|
include $file;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
}
|