- some speed optimizations on loading internal plugins

This commit is contained in:
Uwe.Tews
2009-08-30 18:10:01 +00:00
parent 770ef89611
commit 45ba48f2b6
4 changed files with 36 additions and 21 deletions

View File

@@ -1,3 +1,7 @@
08/30/2009
- some speed optimizations on loading internal plugins
08/29/2009 08/29/2009
- implemented caching of registered Resources - implemented caching of registered Resources
- new property 'auto_literal'. if true(default) '{ ' and ' }' interpreted as literal, not as Smarty delimiter - new property 'auto_literal'. if true(default) '{ ' and ' }' interpreted as literal, not as Smarty delimiter

View File

@@ -39,13 +39,20 @@ if (!defined('DS')) {
/** /**
* set SMARTY_DIR to absolute path to Smarty library files. * set SMARTY_DIR to absolute path to Smarty library files.
* if not defined, include_path will be used. Sets SMARTY_DIR only if user * Sets SMARTY_DIR only if user application has not already defined it.
* application has not already defined it.
*/ */
if (!defined('SMARTY_DIR')) { if (!defined('SMARTY_DIR')) {
define('SMARTY_DIR', dirname(__FILE__) . DS); define('SMARTY_DIR', dirname(__FILE__) . DS);
} }
/**
* set SMARTY_SYSPLUGINS_DIR to absolute path to Smarty internal plugins.
* Sets SMARTY_SYSPLUGINS_DIR only if user application has not already defined it.
*/
if (!defined('SMARTY_SYSPLUGINS_DIR')) {
define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DS);
}
/** /**
* define variable scopes * define variable scopes
*/ */
@@ -64,7 +71,7 @@ define('SMARTY_CACHING_LIVETIME_SAVED', 2);
/** /**
* load required base class for creation of the smarty object * load required base class for creation of the smarty object
*/ */
require_once(dirname(__FILE__) . DS . 'sysplugins' . DS . 'internal.templatebase.php'); require_once(SMARTY_SYSPLUGINS_DIR . 'internal.templatebase.php');
/** /**
* This is the main Smarty class * This is the main Smarty class
@@ -139,8 +146,6 @@ class Smarty extends Smarty_Internal_TemplateBase {
public $parent = null; public $parent = null;
// global template functions // global template functions
public $template_functions = null; public $template_functions = null;
// system plugins directory
private $sysplugins_dir = null;
// resource type used if none given // resource type used if none given
public $default_resource_type = 'file'; public $default_resource_type = 'file';
// charset of template // charset of template
@@ -208,15 +213,14 @@ class Smarty extends Smarty_Internal_TemplateBase {
// set default dirs // set default dirs
$this->template_dir = array('.' . DS . 'templates' . DS); $this->template_dir = array('.' . DS . 'templates' . DS);
$this->compile_dir = '.' . DS . 'templates_c' . DS; $this->compile_dir = '.' . DS . 'templates_c' . DS;
$this->plugins_dir = array(dirname(__FILE__) . DS . 'plugins' . DS); $this->plugins_dir = array(SMARTY_DIR . 'plugins' . DS);
$this->cache_dir = '.' . DS . 'cache' . DS; $this->cache_dir = '.' . DS . 'cache' . DS;
$this->config_dir = '.' . DS . 'configs' . DS; $this->config_dir = '.' . DS . 'configs' . DS;
$this->sysplugins_dir = dirname(__FILE__) . DS . 'sysplugins' . DS;
$this->debug_tpl = SMARTY_DIR . 'debug.tpl'; $this->debug_tpl = SMARTY_DIR . 'debug.tpl';
// load basic plugins // load basic plugins
require_once(dirname(__FILE__) . DS . 'sysplugins' . DS . 'internal.template.php'); require_once(SMARTY_SYSPLUGINS_DIR . 'internal.template.php');
require_once(dirname(__FILE__) . DS . 'sysplugins' . DS . 'internal.plugin_handler.php'); require_once(SMARTY_SYSPLUGINS_DIR . 'internal.plugin_handler.php');
require_once(dirname(__FILE__) . DS . 'sysplugins' . DS . 'internal.run_filter.php'); require_once(SMARTY_SYSPLUGINS_DIR . 'internal.run_filter.php');
// $this->loadPlugin($this->template_class); // $this->loadPlugin($this->template_class);
// $this->loadPlugin('Smarty_Internal_Plugin_Handler'); // $this->loadPlugin('Smarty_Internal_Plugin_Handler');
// $this->loadPlugin('Smarty_Internal_Run_Filter'); // $this->loadPlugin('Smarty_Internal_Run_Filter');
@@ -450,8 +454,8 @@ class Smarty extends Smarty_Internal_TemplateBase {
$_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}{$this->php_ext}"; $_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}{$this->php_ext}";
// if type is "internal", get plugin from sysplugins // if type is "internal", get plugin from sysplugins
if ($_name_parts[1] == 'internal') { if ($_name_parts[1] == 'internal') {
if (file_exists($this->sysplugins_dir . $_plugin_filename)) { if (file_exists(SMARTY_SYSPLUGINS_DIR . $_plugin_filename)) {
require_once($this->sysplugins_dir . $_plugin_filename); require_once(SMARTY_SYSPLUGINS_DIR . $_plugin_filename);
return true; return true;
} else { } else {
return false; return false;
@@ -496,10 +500,10 @@ class Smarty extends Smarty_Internal_TemplateBase {
{ {
if (!is_callable($name)) { if (!is_callable($name)) {
$_plugin_filename = strtolower('method.' . $name . $this->php_ext); $_plugin_filename = strtolower('method.' . $name . $this->php_ext);
if (!file_exists($this->sysplugins_dir . $_plugin_filename)) { if (!file_exists(SMARTY_SYSPLUGINS_DIR . $_plugin_filename)) {
throw new Exception("Sysplugin file " . $_plugin_filename . " does not exist"); throw new Exception("Sysplugin file " . $_plugin_filename . " does not exist");
} }
require_once($this->sysplugins_dir . $_plugin_filename); require_once(SMARTY_SYSPLUGINS_DIR . $_plugin_filename);
if (!is_callable($name)) { if (!is_callable($name)) {
throw new Exception ("Sysplugin file " . $_plugin_filename . " does not define function " . $name); throw new Exception ("Sysplugin file " . $_plugin_filename . " does not define function " . $name);
} }

View File

@@ -62,7 +62,8 @@ class Smarty_Internal_CacheResource_File {
{ {
if (!$template->isEvaluated()) { if (!$template->isEvaluated()) {
if (!is_object($this->smarty->write_file_object)) { if (!is_object($this->smarty->write_file_object)) {
$this->smarty->loadPlugin("Smarty_Internal_Write_File"); require_once(SMARTY_SYSPLUGINS_DIR . 'internal.write_file.php');
//$this->smarty->loadPlugin("Smarty_Internal_Write_File");
$this->smarty->write_file_object = new Smarty_Internal_Write_File; $this->smarty->write_file_object = new Smarty_Internal_Write_File;
} }
return $this->smarty->write_file_object->writeFile($template->getCachedFilepath(), $template->rendered_content); return $this->smarty->write_file_object->writeFile($template->getCachedFilepath(), $template->rendered_content);

View File

@@ -302,13 +302,16 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
// compile template // compile template
if (!is_object($this->compiler_object)) { if (!is_object($this->compiler_object)) {
// load compiler // load compiler
$this->smarty->loadPlugin('Smarty_Internal_CompileBase'); require_once(SMARTY_SYSPLUGINS_DIR . 'internal.compilebase.php');
$this->smarty->loadPlugin('Smarty_Internal_TemplateCompilerBase'); require_once(SMARTY_SYSPLUGINS_DIR . 'internal.templatecompilerbase.php');
//$this->smarty->loadPlugin('Smarty_Internal_CompileBase');
//$this->smarty->loadPlugin('Smarty_Internal_TemplateCompilerBase');
$this->smarty->loadPlugin($this->resource_objects[$this->resource_type]->compiler_class); $this->smarty->loadPlugin($this->resource_objects[$this->resource_type]->compiler_class);
$this->compiler_object = new $this->resource_objects[$this->resource_type]->compiler_class($this->resource_objects[$this->resource_type]->template_lexer_class, $this->resource_objects[$this->resource_type]->template_parser_class, $this->smarty); $this->compiler_object = new $this->resource_objects[$this->resource_type]->compiler_class($this->resource_objects[$this->resource_type]->template_lexer_class, $this->resource_objects[$this->resource_type]->template_parser_class, $this->smarty);
} }
if (!is_object($this->smarty->write_file_object)) { if (!is_object($this->smarty->write_file_object)) {
$this->smarty->loadPlugin("Smarty_Internal_Write_File"); require_once(SMARTY_SYSPLUGINS_DIR . 'internal.write_file.php');
//$this->smarty->loadPlugin("Smarty_Internal_Write_File");
$this->smarty->write_file_object = new Smarty_Internal_Write_File; $this->smarty->write_file_object = new Smarty_Internal_Write_File;
} }
// call compiler // call compiler
@@ -455,7 +458,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
// PHP template // PHP template
$_start_time = $this->_get_time(); $_start_time = $this->_get_time();
// Smarty variables as objects extract as objects // Smarty variables as objects extract as objects
$this->smarty->loadPlugin('Smarty_Internal_PHPVariableObjects'); require_once(SMARTY_SYSPLUGINS_DIR . 'internal.phpvariableobjects.php');
//$this->smarty->loadPlugin('Smarty_Internal_PHPVariableObjects');
$_ptr = $this; $_ptr = $this;
do { do {
foreach ($_ptr->tpl_vars as $_smarty_var => $_var_object) { foreach ($_ptr->tpl_vars as $_smarty_var => $_var_object) {
@@ -563,7 +567,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
if (!isset($this->resource_objects[$resource_type])) { if (!isset($this->resource_objects[$resource_type])) {
// try registered resource // try registered resource
if (isset($this->smarty->_plugins['resource'][$resource_type])) { if (isset($this->smarty->_plugins['resource'][$resource_type])) {
$this->smarty->loadPlugin('Smarty_Internal_Resource_Registered'); require_once(SMARTY_SYSPLUGINS_DIR . 'internal.resource_registered.php');
//$this->smarty->loadPlugin('Smarty_Internal_Resource_Registered');
$resource_handler = $this->resource_objects[$resource_type] = new Smarty_Internal_Resource_Registered($this->smarty); $resource_handler = $this->resource_objects[$resource_type] = new Smarty_Internal_Resource_Registered($this->smarty);
} else { } else {
// try sysplugins dir // try sysplugins dir
@@ -583,7 +588,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
if ($this->smarty->security) { if ($this->smarty->security) {
$this->smarty->security_handler->isTrustedStream($resource_type); $this->smarty->security_handler->isTrustedStream($resource_type);
} }
$this->smarty->loadPlugin('Smarty_Internal_Resource_Stream'); require_once(SMARTY_SYSPLUGINS_DIR . 'internal.resource_stream.php');
//$this->smarty->loadPlugin('Smarty_Internal_Resource_Stream');
$resource_handler = $this->resource_objects[$resource_type] = new Smarty_Internal_Resource_Stream($this->smarty); $resource_handler = $this->resource_objects[$resource_type] = new Smarty_Internal_Resource_Stream($this->smarty);
$resource_name = str_replace(':', '://', $template_resource); $resource_name = str_replace(':', '://', $template_resource);
} else { } else {