mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 19:34:27 +02:00
- some speed optimizations on loading internal plugins
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
08/30/2009
|
||||
- some speed optimizations on loading internal plugins
|
||||
|
||||
|
||||
08/29/2009
|
||||
- implemented caching of registered Resources
|
||||
- new property 'auto_literal'. if true(default) '{ ' and ' }' interpreted as literal, not as Smarty delimiter
|
||||
|
@@ -39,13 +39,20 @@ if (!defined('DS')) {
|
||||
|
||||
/**
|
||||
* set SMARTY_DIR to absolute path to Smarty library files.
|
||||
* if not defined, include_path will be used. Sets SMARTY_DIR only if user
|
||||
* application has not already defined it.
|
||||
* Sets SMARTY_DIR only if user application has not already defined it.
|
||||
*/
|
||||
if (!defined('SMARTY_DIR')) {
|
||||
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
|
||||
*/
|
||||
@@ -64,7 +71,7 @@ define('SMARTY_CACHING_LIVETIME_SAVED', 2);
|
||||
/**
|
||||
* 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
|
||||
@@ -139,8 +146,6 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
public $parent = null;
|
||||
// global template functions
|
||||
public $template_functions = null;
|
||||
// system plugins directory
|
||||
private $sysplugins_dir = null;
|
||||
// resource type used if none given
|
||||
public $default_resource_type = 'file';
|
||||
// charset of template
|
||||
@@ -208,15 +213,14 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
// set default dirs
|
||||
$this->template_dir = array('.' . DS . 'templates' . 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->config_dir = '.' . DS . 'configs' . DS;
|
||||
$this->sysplugins_dir = dirname(__FILE__) . DS . 'sysplugins' . DS;
|
||||
$this->debug_tpl = SMARTY_DIR . 'debug.tpl';
|
||||
// load basic plugins
|
||||
require_once(dirname(__FILE__) . DS . 'sysplugins' . DS . 'internal.template.php');
|
||||
require_once(dirname(__FILE__) . DS . 'sysplugins' . DS . 'internal.plugin_handler.php');
|
||||
require_once(dirname(__FILE__) . DS . 'sysplugins' . DS . 'internal.run_filter.php');
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.template.php');
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.plugin_handler.php');
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.run_filter.php');
|
||||
// $this->loadPlugin($this->template_class);
|
||||
// $this->loadPlugin('Smarty_Internal_Plugin_Handler');
|
||||
// $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}";
|
||||
// if type is "internal", get plugin from sysplugins
|
||||
if ($_name_parts[1] == 'internal') {
|
||||
if (file_exists($this->sysplugins_dir . $_plugin_filename)) {
|
||||
require_once($this->sysplugins_dir . $_plugin_filename);
|
||||
if (file_exists(SMARTY_SYSPLUGINS_DIR . $_plugin_filename)) {
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . $_plugin_filename);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -496,10 +500,10 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
{
|
||||
if (!is_callable($name)) {
|
||||
$_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");
|
||||
}
|
||||
require_once($this->sysplugins_dir . $_plugin_filename);
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . $_plugin_filename);
|
||||
if (!is_callable($name)) {
|
||||
throw new Exception ("Sysplugin file " . $_plugin_filename . " does not define function " . $name);
|
||||
}
|
||||
|
@@ -62,7 +62,8 @@ class Smarty_Internal_CacheResource_File {
|
||||
{
|
||||
if (!$template->isEvaluated()) {
|
||||
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;
|
||||
}
|
||||
return $this->smarty->write_file_object->writeFile($template->getCachedFilepath(), $template->rendered_content);
|
||||
|
@@ -302,13 +302,16 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
// compile template
|
||||
if (!is_object($this->compiler_object)) {
|
||||
// load compiler
|
||||
$this->smarty->loadPlugin('Smarty_Internal_CompileBase');
|
||||
$this->smarty->loadPlugin('Smarty_Internal_TemplateCompilerBase');
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.compilebase.php');
|
||||
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->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)) {
|
||||
$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;
|
||||
}
|
||||
// call compiler
|
||||
@@ -455,7 +458,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
// PHP template
|
||||
$_start_time = $this->_get_time();
|
||||
// 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;
|
||||
do {
|
||||
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])) {
|
||||
// try registered resource
|
||||
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);
|
||||
} else {
|
||||
// try sysplugins dir
|
||||
@@ -583,7 +588,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
if ($this->smarty->security) {
|
||||
$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_name = str_replace(':', '://', $template_resource);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user