Use require_once

This commit is contained in:
Uwe Tews
2015-01-07 16:45:33 +01:00
parent b3f8ddefd2
commit 740a583c7c
5 changed files with 45 additions and 31 deletions

View File

@@ -11,7 +11,7 @@
* @package Smarty * @package Smarty
* @author Uwe Tews * @author Uwe Tews
* Usage: * Usage:
* include '...path/Autoloader.php'; * require_once '...path/Autoloader.php';
* Smarty_Autoloader::register(); * Smarty_Autoloader::register();
* $smarty = new Smarty(); * $smarty = new Smarty();
* Note: This autoloader is not needed if you use Composer. * Note: This autoloader is not needed if you use Composer.
@@ -47,24 +47,38 @@ class Smarty_Autoloader
); );
private static $syspluginsClasses = array( private static $syspluginsClasses = array(
'smarty_config_source' => true, 'smarty_config_source' => true,
'smarty_security' => true, 'smarty_security' => true,
'smarty_cacheresource' => true, 'smarty_cacheresource' => true,
'smarty_compiledresource' => true, 'smarty_compiledresource' => true,
'smarty_cacheresource_custom' => true, 'smarty_cacheresource_custom' => true,
'smarty_cacheresource_keyvaluestore' => true, 'smarty_cacheresource_keyvaluestore' => true,
'smarty_resource' => true, 'smarty_resource' => true,
'smarty_resource_custom' => true, 'smarty_resource_custom' => true,
'smarty_resource_uncompiled' => true, 'smarty_resource_uncompiled' => true,
'smarty_resource_recompiled' => true, 'smarty_resource_recompiled' => true,
'smarty_template_source' => true, 'smarty_template_source' => true,
'smarty_template_compiled' => true, 'smarty_template_compiled' => true,
'smarty_template_cached' => true, 'smarty_template_cached' => true,
'smarty_data' => true, 'smarty_data' => true,
'smarty_variable' => true, 'smarty_variable' => true,
'smarty_undefined_variable' => true, 'smarty_undefined_variable' => true,
'smartyexception' => true, 'smartyexception' => true,
'smartycompilerexception' => true, 'smartycompilerexception' => true,
'smarty_internal_data' => true,
'smarty_internal_template' => true,
'smarty_internal_templatebase' => true,
'smarty_internal_resource_file' => true,
'smarty_internal_resource_extends' => true,
'smarty_internal_resource_eval' => true,
'smarty_internal_resource_string' => true,
'smarty_internal_resource_registered' => true,
'smarty_internal_extension_codeframe' => true,
'smarty_internal_extension_config' => true,
'smarty_internal_filter_handler' => true,
'smarty_internal_function_call_handler' => true,
'smarty_internal_cacheresource_file' => true,
'smarty_internal_write_file' => true,
); );
/** /**
@@ -121,12 +135,12 @@ class Smarty_Autoloader
if (isset(self::$syspluginsClasses[$_class])) { if (isset(self::$syspluginsClasses[$_class])) {
$_class = (self::$syspluginsClasses[$_class] === true) ? $_class : self::$syspluginsClasses[$_class]; $_class = (self::$syspluginsClasses[$_class] === true) ? $_class : self::$syspluginsClasses[$_class];
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
require $file; require_once $file;
return; return;
} elseif (0 !== strpos($_class, 'smarty_internal_')) { } elseif (0 !== strpos($_class, 'smarty_internal_')) {
if (isset(self::$rootClasses[$class])) { if (isset(self::$rootClasses[$class])) {
$file = self::$SMARTY_DIR . self::$rootClasses[$class]; $file = self::$SMARTY_DIR . self::$rootClasses[$class];
require $file; require_once $file;
return; return;
} }
self::$unknown[$class] = true; self::$unknown[$class] = true;
@@ -134,7 +148,7 @@ class Smarty_Autoloader
} }
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
if (is_file($file)) { if (is_file($file)) {
require $file; require_once $file;
return; return;
} }
self::$unknown[$class] = true; self::$unknown[$class] = true;

View File

@@ -33,7 +33,7 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
$format = Smarty::$_DATE_FORMAT; $format = Smarty::$_DATE_FORMAT;
} }
/** /**
* Include the {@link shared.make_timestamp.php} plugin * require_once the {@link shared.make_timestamp.php} plugin
*/ */
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') { if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') {

View File

@@ -141,7 +141,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
if (!empty($compiler->template->required_plugins['compiled'])) { if (!empty($compiler->template->required_plugins['compiled'])) {
foreach ($compiler->template->required_plugins['compiled'] as $tmp) { foreach ($compiler->template->required_plugins['compiled'] as $tmp) {
foreach ($tmp as $data) { foreach ($tmp as $data) {
$output .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n"; $output .= "if (!is_callable('{$data['function']}')) require_once '{$data['file']}';\n";
} }
} }
} }
@@ -149,7 +149,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "echo '/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php "; $output .= "echo '/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
foreach ($compiler->template->required_plugins['nocache'] as $tmp) { foreach ($compiler->template->required_plugins['nocache'] as $tmp) {
foreach ($tmp as $data) { foreach ($tmp as $data) {
$output .= "if (!is_callable(\'{$data['function']}\')) include \'{$data['file']}\';\n"; $output .= "if (!is_callable(\'{$data['function']}\')) require_once \'{$data['file']}\';\n";
} }
} }
$output .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';\n"; $output .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';\n";
@@ -185,7 +185,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
if (!empty($compiler->template->required_plugins['compiled'])) { if (!empty($compiler->template->required_plugins['compiled'])) {
foreach ($compiler->template->required_plugins['compiled'] as $tmp) { foreach ($compiler->template->required_plugins['compiled'] as $tmp) {
foreach ($tmp as $data) { foreach ($tmp as $data) {
$output .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n"; $output .= "if (!is_callable('{$data['function']}')) require_once '{$data['file']}';\n";
} }
} }
} }

View File

@@ -46,9 +46,9 @@ class Smarty_Internal_Extension_CodeFrame
foreach ($tmp as $data) { foreach ($tmp as $data) {
$file = addslashes($data['file']); $file = addslashes($data['file']);
if (is_Array($data['function'])) { if (is_Array($data['function'])) {
$output .= "if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) include '{$file}';\n"; $output .= "if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n";
} else { } else {
$output .= "if (!is_callable('{$data['function']}')) include '{$file}';\n"; $output .= "if (!is_callable('{$data['function']}')) require_once '{$file}';\n";
} }
} }
} }
@@ -60,9 +60,9 @@ class Smarty_Internal_Extension_CodeFrame
foreach ($tmp as $data) { foreach ($tmp as $data) {
$file = addslashes($data['file']); $file = addslashes($data['file']);
if (is_Array($data['function'])) { if (is_Array($data['function'])) {
$output .= addslashes("if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) include '{$file}';\n"); $output .= addslashes("if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n");
} else { } else {
$output .= addslashes("if (!is_callable('{$data['function']}')) include '{$file}';\n"); $output .= addslashes("if (!is_callable('{$data['function']}')) require_once '{$file}';\n");
} }
} }
} }

View File

@@ -701,7 +701,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->template->required_plugins['compiled'][$tag][$plugin_type]['file'] = $script; $this->template->required_plugins['compiled'][$tag][$plugin_type]['file'] = $script;
$this->template->required_plugins['compiled'][$tag][$plugin_type]['function'] = $callback; $this->template->required_plugins['compiled'][$tag][$plugin_type]['function'] = $callback;
} }
include_once $script; require_once $script;
} else { } else {
$this->trigger_template_error("Default plugin handler: Returned script file \"{$script}\" for \"{$tag}\" not found"); $this->trigger_template_error("Default plugin handler: Returned script file \"{$script}\" for \"{$tag}\" not found");
} }