diff options
author | emkael <emkael@tlen.pl> | 2016-12-27 14:47:01 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-12-27 14:47:01 +0100 |
commit | 7085a0c2f7104a56a7e946c43ba0b5736be5f4e7 (patch) | |
tree | 5518c72e3486f41c559be30e514be1917bf5724f /lib/smarty3/Autoloader.php | |
parent | 1a3d783d8957a6adbe49b1765b326805477e7856 (diff) |
* smarty bundled
Diffstat (limited to 'lib/smarty3/Autoloader.php')
-rw-r--r-- | lib/smarty3/Autoloader.php | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/lib/smarty3/Autoloader.php b/lib/smarty3/Autoloader.php new file mode 100644 index 0000000..e888553 --- /dev/null +++ b/lib/smarty3/Autoloader.php @@ -0,0 +1,107 @@ +<?php +/** + * Smarty Autoloader + * + * @package Smarty + */ + +/** + * Smarty Autoloader + * + * @package Smarty + * @author Uwe Tews + * Usage: + * require_once '...path/Autoloader.php'; + * Smarty_Autoloader::register(); + * $smarty = new Smarty(); + * Note: This autoloader is not needed if you use Composer. + * Composer will automatically add the classes of the Smarty package to it common autoloader. + */ +class Smarty_Autoloader +{ + /** + * Filepath to Smarty root + * + * @var string + */ + public static $SMARTY_DIR = ''; + + /** + * Filepath to Smarty internal plugins + * + * @var string + */ + public static $SMARTY_SYSPLUGINS_DIR = ''; + + /** + * Array with Smarty core classes and their filename + * + * @var array + */ + public static $rootClasses = array('smarty' => 'Smarty.class.php', 'smartybc' => 'SmartyBC.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; + if (version_compare(phpversion(), '5.3.0', '>=')) { + spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend); + } else { + spl_autoload_register(array(__CLASS__, 'autoload')); + } + } + + /** + * Handles auto loading of classes. + * + * @param string $class A class name. + */ + public static function autoload($class) + { + $_class = strtolower($class); + if (strpos($_class, 'smarty') !== 0) { + return; + } + $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; + if (is_file($file)) { + include $file; + } else if (isset(self::$rootClasses[ $_class ])) { + $file = self::$SMARTY_DIR . self::$rootClasses[ $_class ]; + if (is_file($file)) { + include $file; + } + } + return; + } +} |