- add bootstrap file to load and register Smarty_Autoloader. Change composer.json to make it known to composer

This commit is contained in:
uwetews
2016-11-08 17:48:25 +01:00
parent c4746e9080
commit 428a7ad883
6 changed files with 58 additions and 31 deletions

View File

@@ -1,3 +1,17 @@
Smarty: the PHP compiling template engine
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License below for more details.
GNU LESSER GENERAL PUBLIC LICENSE GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007 Version 3, 29 June 2007

View File

@@ -1,4 +1,7 @@
===== 3.1.31-dev ===== (xx.xx.xx) ===== 3.1.31-dev ===== (xx.xx.xx)
08.11.2016
- add bootstrap file to load and register Smarty_Autoloader. Change composer.json to make it known to composer
07.11.2016 07.11.2016
- optimization of lexer speed https://github.com/smarty-php/smarty/issues/311 - optimization of lexer speed https://github.com/smarty-php/smarty/issues/311

View File

@@ -28,11 +28,7 @@
"php": ">=5.2" "php": ">=5.2"
}, },
"autoload": { "autoload": {
"classmap": [ "files": ["libs/bootstrap.php"]
"libs/Smarty.class.php",
"libs/SmartyBC.class.php",
"libs/sysplugins/"
]
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {

View File

@@ -13,9 +13,10 @@
* Usage: * Usage:
* require_once '...path/Autoloader.php'; * require_once '...path/Autoloader.php';
* Smarty_Autoloader::register(); * Smarty_Autoloader::register();
* or
* include '...path/bootstarp.php';
*
* $smarty = new Smarty(); * $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 class Smarty_Autoloader
{ {
@@ -24,14 +25,14 @@ class Smarty_Autoloader
* *
* @var string * @var string
*/ */
public static $SMARTY_DIR = ''; public static $SMARTY_DIR = null;
/** /**
* Filepath to Smarty internal plugins * Filepath to Smarty internal plugins
* *
* @var string * @var string
*/ */
public static $SMARTY_SYSPLUGINS_DIR = ''; public static $SMARTY_SYSPLUGINS_DIR = null;
/** /**
* Array with Smarty core classes and their filename * Array with Smarty core classes and their filename
@@ -89,15 +90,17 @@ class Smarty_Autoloader
*/ */
public static function autoload($class) public static function autoload($class)
{ {
$_class = strtolower($class); if ($class[ 0 ] !== 'S' && strpos($class, 'Smarty') !== 0) {
if (strpos($_class, 'smarty') !== 0) {
return; return;
} }
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; $_class = strtolower($class);
if (isset(self::$rootClasses[ $_class ])) {
$file = self::$SMARTY_DIR . self::$rootClasses[ $_class ];
if (is_file($file)) { if (is_file($file)) {
include $file; include $file;
} else if (isset(self::$rootClasses[ $_class ])) { }
$file = self::$SMARTY_DIR . self::$rootClasses[ $_class ]; } else {
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
if (is_file($file)) { if (is_file($file)) {
include $file; include $file;
} }

View File

@@ -66,23 +66,16 @@ if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) {
} }
/** /**
* Try loading the Smarty_Internal_Data class * Load Smarty_Autoloader
* If we fail we must load Smarty's autoloader.
* Otherwise we may have a global autoloader like Composer
*/ */
if (!class_exists('Smarty_Autoloader', false)) { if (!class_exists('Smarty_Autoloader')) {
if (!class_exists('Smarty_Internal_Data', true)) { include __DIR__ . '/bootstrap.php';
require_once dirname(__FILE__) . '/Autoloader.php';
Smarty_Autoloader::registerBC();
}
} }
/** /**
* Load always needed external class files * Load always needed external class files
*/ */
if (!class_exists('Smarty_Internal_Data', false)) { require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php';
}
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_extension_handler.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_extension_handler.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php';
@@ -90,6 +83,7 @@ require_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_variable.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_variable.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_source.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_source.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_resource_base.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_resource_base.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php';
/** /**
* This is the main Smarty class * This is the main Smarty class
@@ -114,7 +108,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.31-dev/41'; const SMARTY_VERSION = '3.1.31-dev/42';
/** /**
* define variable scopes * define variable scopes

17
libs/bootstrap.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
/*
* This file is part of the Smarty package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
* Load and register Smarty Autoloader
*/
if (!class_exists('Smarty_Autoloader')) {
require __DIR__ . '/Autoloader.php';
}
Smarty_Autoloader::register();