mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- optimization of resource processing
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
===== 3.1.30-dev ===== (xx.xx.xx)
|
||||
10.03.2014
|
||||
- optimization of resource processing
|
||||
|
||||
09.03.2014
|
||||
- improvement rework of 'scope' attribute handling see see NEW_FEATURES.txt https://github.com/smarty-php/smarty/issues/194
|
||||
https://github.com/smarty-php/smarty/issues/186 https://github.com/smarty-php/smarty/issues/179
|
||||
|
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.30-dev/53';
|
||||
const SMARTY_VERSION = '3.1.30-dev/54';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
|
@@ -71,12 +71,9 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File
|
||||
throw new SmartyException("PHP templates are disabled");
|
||||
}
|
||||
if (!$source->exists) {
|
||||
if (isset($_template->parent) && $_template->parent->_objType == 2) {
|
||||
$parent_resource = " in '{$_template->parent->template_resource}'";
|
||||
} else {
|
||||
$parent_resource = '';
|
||||
}
|
||||
throw new SmartyException("Unable to load template {$source->type} '{$source->name}'{$parent_resource}");
|
||||
$parentIsTpl = isset($this->parent) && $this->parent->_objType == 2;
|
||||
throw new SmartyException("Unable to load template {$source->type} '{$source->name}'" .
|
||||
($parentIsTpl ? " in '{$this->parent->template_resource}'" : ''));
|
||||
}
|
||||
|
||||
// prepare variables
|
||||
@@ -100,8 +97,11 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File
|
||||
*/
|
||||
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
|
||||
{
|
||||
$compiled->filepath = false;
|
||||
$compiled->timestamp = false;
|
||||
$compiled->exists = false;
|
||||
$compiled->filepath = $_template->source->filepath;
|
||||
$compiled->timestamp = $_template->source->timestamp;
|
||||
$compiled->exists = $_template->source->exists;
|
||||
$compiled->file_dependency[ $_template->source->uid ] =
|
||||
array($compiled->filepath, $this->template->source->getTimeStamp(),
|
||||
$this->template->source->type,);
|
||||
}
|
||||
}
|
||||
|
@@ -82,16 +82,11 @@ class Smarty_Internal_Runtime_UpdateCache
|
||||
*/
|
||||
public function updateCache(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $no_output_filter)
|
||||
{
|
||||
if ($_template->source->handler->uncompiled) {
|
||||
ob_start();
|
||||
$_template->source->render($_template);
|
||||
} else {
|
||||
ob_start();
|
||||
if (!isset($_template->compiled)) {
|
||||
$_template->loadCompiled();
|
||||
}
|
||||
$_template->compiled->render($_template);
|
||||
ob_start();
|
||||
if (!isset($_template->compiled)) {
|
||||
$_template->loadCompiled();
|
||||
}
|
||||
$_template->compiled->render($_template);
|
||||
if ($_template->smarty->debugging) {
|
||||
$_template->smarty->_debug->start_cache($_template);
|
||||
}
|
||||
|
@@ -14,9 +14,8 @@
|
||||
* @package Smarty
|
||||
* @subpackage Template
|
||||
*
|
||||
* @property Smarty_Template_Source|Smarty_Template_Config $source
|
||||
* @property Smarty_Template_Compiled $compiled
|
||||
* @property Smarty_Template_Cached $cached
|
||||
* @property Smarty_Template_Compiled $compiled
|
||||
* @property Smarty_Template_Cached $cached
|
||||
*
|
||||
* The following methods will be dynamically loaded by the extension handler when they are called.
|
||||
* They are located in a corresponding Smarty_Internal_Method_xxxx class
|
||||
@@ -107,7 +106,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
public function __construct($template_resource, Smarty $smarty, Smarty_Internal_Data $_parent = null,
|
||||
$_cache_id = null, $_compile_id = null, $_caching = null, $_cache_lifetime = null)
|
||||
{
|
||||
$this->smarty = &$smarty;
|
||||
$this->smarty = $smarty;
|
||||
// Smarty parameter
|
||||
$this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id;
|
||||
$this->compile_id = $_compile_id === null ? $this->smarty->compile_id : $_compile_id;
|
||||
@@ -140,12 +139,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
}
|
||||
// checks if template exists
|
||||
if (!$this->source->exists) {
|
||||
if ($parentIsTpl) {
|
||||
$parent_resource = " in '{$this->parent->template_resource}'";
|
||||
} else {
|
||||
$parent_resource = '';
|
||||
}
|
||||
throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}");
|
||||
throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'" .
|
||||
($parentIsTpl ? " in '{$this->parent->template_resource}'" : ''));
|
||||
}
|
||||
// disable caching for evaluated code
|
||||
if ($this->source->handler->recompiled) {
|
||||
@@ -158,14 +153,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
if (!isset($this->cached) || $this->cached->cache_id !== $this->cache_id ||
|
||||
$this->cached->compile_id !== $this->compile_id
|
||||
) {
|
||||
$this->loadCached();
|
||||
$this->loadCached(true);
|
||||
}
|
||||
$this->cached->render($this, $no_output_filter);
|
||||
} elseif ($this->source->handler->uncompiled) {
|
||||
$this->source->render($this);
|
||||
} else {
|
||||
if (!isset($this->compiled) || $this->compiled->compile_id !== $this->compile_id) {
|
||||
$this->loadCompiled();
|
||||
$this->loadCompiled(true);
|
||||
}
|
||||
$this->compiled->render($this);
|
||||
}
|
||||
@@ -242,22 +235,20 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
{
|
||||
$tpl = clone $this;
|
||||
$tpl->parent = $this;
|
||||
$_templateId = $this->smarty->_getTemplateId($template, $cache_id, $compile_id, $caching);
|
||||
$smarty = &$this->smarty;
|
||||
$_templateId = $smarty->_getTemplateId($template, $cache_id, $compile_id, $caching);
|
||||
// recursive call ?
|
||||
if ($tpl->_getTemplateId() != $_templateId) {
|
||||
// already in template cache?
|
||||
if (isset($this->smarty->_cache[ 'tplObjects' ][ $_templateId ])) {
|
||||
if (isset($smarty->_cache[ 'tplObjects' ][ $_templateId ])) {
|
||||
// copy data from cached object
|
||||
$cachedTpl = &$this->smarty->_cache[ 'tplObjects' ][ $_templateId ];
|
||||
$cachedTpl = &$smarty->_cache[ 'tplObjects' ][ $_templateId ];
|
||||
$tpl->templateId = $cachedTpl->templateId;
|
||||
$tpl->template_resource = $cachedTpl->template_resource;
|
||||
$tpl->cache_id = $cachedTpl->cache_id;
|
||||
$tpl->compile_id = $cachedTpl->compile_id;
|
||||
$tpl->source = $cachedTpl->source;
|
||||
// if $caching mode changed the compiled resource is invalid
|
||||
if ((bool) $tpl->caching !== (bool) $caching) {
|
||||
unset($tpl->compiled);
|
||||
} elseif (isset($cachedTpl->compiled)) {
|
||||
if (isset($cachedTpl->compiled)) {
|
||||
$tpl->compiled = $cachedTpl->compiled;
|
||||
} else {
|
||||
unset($tpl->compiled);
|
||||
@@ -275,11 +266,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
if (isset($uid)) {
|
||||
// for inline templates we can get all resource information from file dependency
|
||||
list($filepath, $timestamp, $type) = $tpl->compiled->file_dependency[ $uid ];
|
||||
$tpl->source =
|
||||
new Smarty_Template_Source(isset($tpl->smarty->_cache[ 'resource_handlers' ][ $type ]) ?
|
||||
$tpl->smarty->_cache[ 'resource_handlers' ][ $type ] :
|
||||
Smarty_Resource::load($tpl->smarty, $type), $tpl->smarty,
|
||||
$filepath, $type, $filepath);
|
||||
$tpl->source = new Smarty_Template_Source($smarty, $filepath, $type, $filepath);
|
||||
$tpl->source->filepath = $filepath;
|
||||
$tpl->source->timestamp = $timestamp;
|
||||
$tpl->source->exists = true;
|
||||
@@ -300,13 +287,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
$tpl->cache_lifetime = $cache_lifetime;
|
||||
// set template scope
|
||||
$tpl->scope = $scope;
|
||||
if (!isset($tpl->smarty->_cache[ 'tplObjects' ][ $tpl->templateId ]) && !$tpl->source->handler->recompiled) {
|
||||
if (!isset($smarty->_cache[ 'tplObjects' ][ $tpl->templateId ]) && !$tpl->source->handler->recompiled) {
|
||||
// check if template object should be cached
|
||||
if ($forceTplCache || (isset($tpl->smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ]) &&
|
||||
$tpl->smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ] > 1) ||
|
||||
($tpl->_isParentTemplate() && isset($tpl->smarty->_cache[ 'tplObjects' ][ $tpl->parent->templateId ]))
|
||||
if ($forceTplCache || (isset($smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ]) &&
|
||||
$smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ] > 1) ||
|
||||
($tpl->_isParentTemplate() && isset($smarty->_cache[ 'tplObjects' ][ $tpl->parent->templateId ]))
|
||||
) {
|
||||
$tpl->smarty->_cache[ 'tplObjects' ][ $tpl->templateId ] = $tpl;
|
||||
$smarty->_cache[ 'tplObjects' ][ $tpl->templateId ] = $tpl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,18 +303,24 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
$tpl->tpl_vars[ $_key ] = new Smarty_Variable($_val, $this->isRenderingCache);
|
||||
}
|
||||
}
|
||||
if ($tpl->caching == 9999 && $tpl->compiled->has_nocache_code) {
|
||||
$this->cached->hashes[ $tpl->compiled->nocache_hash ] = true;
|
||||
if ($tpl->caching == 9999) {
|
||||
if (!isset($tpl->compiled)) {
|
||||
$this->loadCompiled(true);
|
||||
}
|
||||
if ($tpl->compiled->has_nocache_code) {
|
||||
$this->cached->hashes[ $tpl->compiled->nocache_hash ] = true;
|
||||
}
|
||||
}
|
||||
$tpl->_cache = array();
|
||||
if (isset($uid)) {
|
||||
if ($this->smarty->debugging) {
|
||||
$this->smarty->_debug->start_template($tpl);
|
||||
$this->smarty->_debug->start_render($tpl);
|
||||
if ($smarty->debugging) {
|
||||
$smarty->_debug->start_template($tpl);
|
||||
$smarty->_debug->start_render($tpl);
|
||||
}
|
||||
$tpl->compiled->getRenderedTemplateCode($tpl, $content_func);
|
||||
if ($this->smarty->debugging) {
|
||||
$this->smarty->_debug->end_template($tpl);
|
||||
$this->smarty->_debug->end_render($tpl);
|
||||
if ($smarty->debugging) {
|
||||
$smarty->_debug->end_template($tpl);
|
||||
$smarty->_debug->end_render($tpl);
|
||||
}
|
||||
} else {
|
||||
if (isset($tpl->compiled)) {
|
||||
@@ -511,10 +504,11 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* Load compiled object
|
||||
*
|
||||
* @param bool $force force new compiled object
|
||||
*/
|
||||
public function loadCompiled()
|
||||
public function loadCompiled($force = false)
|
||||
{
|
||||
if (!isset($this->compiled)) {
|
||||
if ($force || !isset($this->compiled)) {
|
||||
$this->compiled = Smarty_Template_Compiled::load($this);
|
||||
}
|
||||
}
|
||||
@@ -522,10 +516,11 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* Load cached object
|
||||
*
|
||||
* @param bool $force force new cached object
|
||||
*/
|
||||
public function loadCached()
|
||||
public function loadCached($force = false)
|
||||
{
|
||||
if (!isset($this->cached)) {
|
||||
if ($force || !isset($this->cached)) {
|
||||
$this->cached = Smarty_Template_Cached::load($this);
|
||||
}
|
||||
}
|
||||
@@ -537,12 +532,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
*/
|
||||
public function loadCompiler()
|
||||
{
|
||||
if (!class_exists($this->source->handler->compiler_class)) {
|
||||
$this->smarty->loadPlugin($this->source->handler->compiler_class);
|
||||
if (!class_exists($this->source->compiler_class)) {
|
||||
$this->smarty->loadPlugin($this->source->compiler_class);
|
||||
}
|
||||
$this->compiler = new $this->source->handler->compiler_class($this->source->handler->template_lexer_class,
|
||||
$this->source->handler->template_parser_class,
|
||||
$this->smarty);
|
||||
$this->compiler =
|
||||
new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class,
|
||||
$this->smarty);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -49,27 +49,6 @@ abstract class Smarty_Resource
|
||||
*/
|
||||
public $hasCompiledHandler = false;
|
||||
|
||||
/**
|
||||
* Name of the Class to compile this resource's contents with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
|
||||
|
||||
/**
|
||||
* Name of the Class to tokenize this resource's contents with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $template_lexer_class = 'Smarty_Internal_Templatelexer';
|
||||
|
||||
/**
|
||||
* Name of the Class to parse this resource's contents with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $template_parser_class = 'Smarty_Internal_Templateparser';
|
||||
|
||||
/**
|
||||
* Load template's source into current template object
|
||||
*
|
||||
|
@@ -44,36 +44,14 @@ abstract class Smarty_Resource_Uncompiled extends Smarty_Resource
|
||||
* populate compiled object with compiled filepath
|
||||
*
|
||||
* @param Smarty_Template_Compiled $compiled compiled object
|
||||
* @param Smarty_Internal_Template $_template template object (is ignored)
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*/
|
||||
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
|
||||
{
|
||||
$compiled->filepath = false;
|
||||
$compiled->timestamp = false;
|
||||
$compiled->exists = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* render compiled template code
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function render($_template)
|
||||
{
|
||||
$level = ob_get_level();
|
||||
ob_start();
|
||||
try {
|
||||
$this->renderUncompiled($_template->source, $_template);
|
||||
return ob_get_clean();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
while (ob_get_level() > $level) {
|
||||
ob_end_clean();
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
$compiled->filepath = $_template->source->filepath;
|
||||
$compiled->timestamp = $_template->source->timestamp;
|
||||
$compiled->exists = $_template->source->exists;
|
||||
$compiled->file_dependency[ $_template->source->uid ] =
|
||||
array($compiled->filepath, $compiled->timestamp, $_template->source->type,);
|
||||
}
|
||||
}
|
||||
|
@@ -72,6 +72,13 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
|
||||
*/
|
||||
public $hashes = array();
|
||||
|
||||
/**
|
||||
* Flag if this is a cache resource
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $isCache = true;
|
||||
|
||||
/**
|
||||
* create Cached Object container
|
||||
*
|
||||
|
@@ -96,46 +96,46 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $_template)
|
||||
{
|
||||
$_smarty_tpl = $_template;
|
||||
if ($_template->source->handler->recompiled || !$_template->compiled->exists ||
|
||||
$_template->smarty->force_compile || ($_template->smarty->compile_check &&
|
||||
$_template->source->getTimeStamp() >
|
||||
$_template->compiled->getTimeStamp())
|
||||
) {
|
||||
$this->compileTemplateSource($_template);
|
||||
$compileCheck = $_template->smarty->compile_check;
|
||||
$_template->smarty->compile_check = false;
|
||||
if ($_template->source->handler->recompiled) {
|
||||
$level = ob_get_level();
|
||||
ob_start();
|
||||
try {
|
||||
eval("?>" . $this->content);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
while (ob_get_level() > $level) {
|
||||
ob_end_clean();
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
ob_get_clean();
|
||||
$this->content = null;
|
||||
} else {
|
||||
$this->loadCompiledTemplate($_template);
|
||||
}
|
||||
$_template->smarty->compile_check = $compileCheck;
|
||||
} else {
|
||||
$_template->mustCompile = true;
|
||||
@include($_template->compiled->filepath);
|
||||
if ($_template->mustCompile) {
|
||||
if (!$_template->source->handler->uncompiled) {
|
||||
$_smarty_tpl = $_template;
|
||||
if ($_template->source->handler->recompiled || !$this->exists || $_template->smarty->force_compile ||
|
||||
($_template->smarty->compile_check && $_template->source->getTimeStamp() > $this->getTimeStamp())
|
||||
) {
|
||||
$this->compileTemplateSource($_template);
|
||||
$compileCheck = $_template->smarty->compile_check;
|
||||
$_template->smarty->compile_check = false;
|
||||
$this->loadCompiledTemplate($_template);
|
||||
if ($_template->source->handler->recompiled) {
|
||||
$level = ob_get_level();
|
||||
ob_start();
|
||||
try {
|
||||
eval("?>" . $this->content);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
while (ob_get_level() > $level) {
|
||||
ob_end_clean();
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
ob_get_clean();
|
||||
$this->content = null;
|
||||
} else {
|
||||
$this->loadCompiledTemplate($_template);
|
||||
}
|
||||
$_template->smarty->compile_check = $compileCheck;
|
||||
} else {
|
||||
$_template->mustCompile = true;
|
||||
@include($this->filepath);
|
||||
if ($_template->mustCompile) {
|
||||
$this->compileTemplateSource($_template);
|
||||
$compileCheck = $_template->smarty->compile_check;
|
||||
$_template->smarty->compile_check = false;
|
||||
$this->loadCompiledTemplate($_template);
|
||||
$_template->smarty->compile_check = $compileCheck;
|
||||
}
|
||||
}
|
||||
$_template->_subTemplateRegister();
|
||||
$this->processed = true;
|
||||
}
|
||||
$_template->_subTemplateRegister();
|
||||
$this->processed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,15 +147,15 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
private function loadCompiledTemplate(Smarty_Internal_Template $_template)
|
||||
{
|
||||
if (function_exists('opcache_invalidate')) {
|
||||
opcache_invalidate($_template->compiled->filepath, true);
|
||||
opcache_invalidate($this->filepath, true);
|
||||
} elseif (function_exists('apc_compile_file')) {
|
||||
apc_compile_file($_template->compiled->filepath);
|
||||
apc_compile_file($this->filepath);
|
||||
}
|
||||
$_smarty_tpl = $_template;
|
||||
if (defined('HHVM_VERSION')) {
|
||||
eval("?>" . file_get_contents($_template->compiled->filepath));
|
||||
eval("?>" . file_get_contents($this->filepath));
|
||||
} else {
|
||||
include($_template->compiled->filepath);
|
||||
include($this->filepath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +179,11 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
$_template->cached->file_dependency =
|
||||
array_merge($_template->cached->file_dependency, $this->file_dependency);
|
||||
}
|
||||
$this->getRenderedTemplateCode($_template);
|
||||
if ($_template->source->handler->uncompiled) {
|
||||
$_template->source->handler->renderUncompiled($_template->source, $_template);
|
||||
} else {
|
||||
$this->getRenderedTemplateCode($_template);
|
||||
}
|
||||
if ($_template->caching && $this->has_nocache_code) {
|
||||
$_template->cached->hashes[ $this->nocache_hash ] = true;
|
||||
}
|
||||
@@ -207,8 +211,8 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
$this->unifunc = null;
|
||||
// compile locking
|
||||
if (!$_template->source->handler->recompiled) {
|
||||
if ($saved_timestamp = $_template->compiled->getTimeStamp()) {
|
||||
touch($_template->compiled->filepath);
|
||||
if ($saved_timestamp = $this->getTimeStamp()) {
|
||||
touch($this->filepath);
|
||||
}
|
||||
}
|
||||
// call compiler
|
||||
@@ -219,7 +223,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
catch (Exception $e) {
|
||||
// restore old timestamp in case of error
|
||||
if (!$_template->source->handler->recompiled && $saved_timestamp) {
|
||||
touch($_template->compiled->filepath, $saved_timestamp);
|
||||
touch($this->filepath, $saved_timestamp);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
@@ -40,26 +40,27 @@ class Smarty_Template_Config extends Smarty_Template_Source
|
||||
public $isConfig = true;
|
||||
|
||||
/**
|
||||
* create Source Object container
|
||||
* Name of the Class to compile this resource's contents with
|
||||
*
|
||||
* @param Smarty_Resource $handler Resource Handler this source object communicates with
|
||||
* @param Smarty $smarty Smarty instance this source object belongs to
|
||||
* @param string $resource full template_resource
|
||||
* @param string $type type of resource
|
||||
* @param string $name resource name
|
||||
* @var string
|
||||
*/
|
||||
public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name)
|
||||
{
|
||||
// must clone handler as we change class names
|
||||
$this->handler = clone $handler; // Note: prone to circular references
|
||||
$this->handler->compiler_class = 'Smarty_Internal_Config_File_Compiler';
|
||||
$this->handler->template_lexer_class = 'Smarty_Internal_Configfilelexer';
|
||||
$this->handler->template_parser_class = 'Smarty_Internal_Configfileparser';
|
||||
$this->resource = $resource;
|
||||
$this->type = $type;
|
||||
$this->name = $name;
|
||||
$this->smarty = $smarty;
|
||||
}
|
||||
public $compiler_class = 'Smarty_Internal_Config_File_Compiler';
|
||||
|
||||
/**
|
||||
* Name of the Class to tokenize this resource's contents with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $template_lexer_class = 'Smarty_Internal_Configfilelexer';
|
||||
|
||||
/**
|
||||
* Name of the Class to parse this resource's contents with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $template_parser_class = 'Smarty_Internal_Configfileparser';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* initialize Source Object for given resource
|
||||
@@ -87,9 +88,8 @@ class Smarty_Template_Config extends Smarty_Template_Source
|
||||
if (isset($_incompatible_resources[ $type ])) {
|
||||
throw new SmartyException ("Unable to use resource '{$type}' for config");
|
||||
}
|
||||
$resource = Smarty_Resource::load($_template->smarty, $type);
|
||||
$source = new Smarty_Template_Config($resource, $_template->smarty, $template_resource, $type, $name);
|
||||
$resource->populate($source, $_template);
|
||||
$source = new Smarty_Template_Config($_template->smarty, $template_resource, $type, $name);
|
||||
$source->handler->populate($source, $_template);
|
||||
if (!$source->exists && isset($_template->smarty->default_config_handler_func)) {
|
||||
Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
|
||||
}
|
||||
|
@@ -86,6 +86,13 @@ abstract class Smarty_Template_Resource_Base
|
||||
*/
|
||||
public $includes = array();
|
||||
|
||||
/**
|
||||
* Flag if this is a cache resource
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $isCache = false;
|
||||
|
||||
/**
|
||||
* Process resource
|
||||
*
|
||||
@@ -104,15 +111,18 @@ abstract class Smarty_Template_Resource_Base
|
||||
*/
|
||||
public function getRenderedTemplateCode(Smarty_Internal_Template $_template, $unifunc = null)
|
||||
{
|
||||
$_template->isRenderingCache = $this instanceof Smarty_Template_Cached;
|
||||
$unifunc = isset($unifunc) ? $unifunc : $this->unifunc;
|
||||
$smarty = &$_template->smarty;
|
||||
$_template->isRenderingCache = $this->isCache;
|
||||
$level = ob_get_level();
|
||||
try {
|
||||
if (empty($unifunc) || !is_callable($unifunc)) {
|
||||
if (!isset($unifunc)) {
|
||||
$unifunc = $this->unifunc;
|
||||
}
|
||||
if (empty($unifunc) || !function_exists($unifunc)) {
|
||||
throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
|
||||
}
|
||||
if (isset($_template->smarty->security_policy)) {
|
||||
$_template->smarty->security_policy->startTemplate($_template);
|
||||
if (isset($smarty->security_policy)) {
|
||||
$smarty->security_policy->startTemplate($_template);
|
||||
}
|
||||
//
|
||||
// render compiled or saved template code
|
||||
@@ -126,8 +136,8 @@ abstract class Smarty_Template_Resource_Base
|
||||
if ($_saved_capture_level != count($_template->_cache[ 'capture_stack' ])) {
|
||||
$_template->capture_error();
|
||||
}
|
||||
if (isset($_template->smarty->security_policy)) {
|
||||
$_template->smarty->security_policy->exitTemplate();
|
||||
if (isset($smarty->security_policy)) {
|
||||
$smarty->security_policy->exitTemplate();
|
||||
}
|
||||
$_template->isRenderingCache = false;
|
||||
return null;
|
||||
@@ -137,8 +147,8 @@ abstract class Smarty_Template_Resource_Base
|
||||
while (ob_get_level() > $level) {
|
||||
ob_end_clean();
|
||||
}
|
||||
if (isset($_template->smarty->security_policy)) {
|
||||
$_template->smarty->security_policy->exitTemplate();
|
||||
if (isset($smarty->security_policy)) {
|
||||
$smarty->security_policy->exitTemplate();
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
@@ -102,6 +102,27 @@ class Smarty_Template_Source
|
||||
*/
|
||||
public $content = null;
|
||||
|
||||
/**
|
||||
* Name of the Class to compile this resource's contents with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
|
||||
|
||||
/**
|
||||
* Name of the Class to tokenize this resource's contents with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $template_lexer_class = 'Smarty_Internal_Templatelexer';
|
||||
|
||||
/**
|
||||
* Name of the Class to parse this resource's contents with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $template_parser_class = 'Smarty_Internal_Templateparser';
|
||||
|
||||
/**
|
||||
* create Source Object container
|
||||
*
|
||||
@@ -112,9 +133,10 @@ class Smarty_Template_Source
|
||||
* @param string $name resource name
|
||||
*
|
||||
*/
|
||||
public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name)
|
||||
public function __construct(Smarty $smarty, $resource, $type, $name)
|
||||
{
|
||||
$this->handler = $handler; // Note: prone to circular references
|
||||
$this->handler = isset($smarty->_cache[ 'resource_handlers' ][ $type ]) ? $smarty->_cache[ 'resource_handlers' ][ $type ] :
|
||||
Smarty_Resource::load($smarty, $type);
|
||||
$this->smarty = $smarty;
|
||||
$this->resource = $resource;
|
||||
$this->type = $type;
|
||||
@@ -152,54 +174,15 @@ class Smarty_Template_Source
|
||||
$type = $smarty->default_resource_type;
|
||||
$name = $template_resource;
|
||||
}
|
||||
|
||||
$handler =
|
||||
isset($smarty->_cache[ 'resource_handlers' ][ $type ]) ? $smarty->_cache[ 'resource_handlers' ][ $type ] :
|
||||
Smarty_Resource::load($smarty, $type);
|
||||
// create new source object
|
||||
$source = new Smarty_Template_Source($handler, $smarty, $template_resource, $type, $name);
|
||||
$handler->populate($source, $_template);
|
||||
$source = new Smarty_Template_Source($smarty, $template_resource, $type, $name);
|
||||
$source->handler->populate($source, $_template);
|
||||
if (!$source->exists && isset($_template->smarty->default_template_handler_func)) {
|
||||
Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
|
||||
}
|
||||
return $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* render the uncompiled source
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function renderUncompiled(Smarty_Internal_Template $_template)
|
||||
{
|
||||
$this->handler->renderUncompiled($_template->source, $_template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render uncompiled source
|
||||
*
|
||||
* @param \Smarty_Internal_Template $_template
|
||||
*/
|
||||
public function render(Smarty_Internal_Template $_template)
|
||||
{
|
||||
if ($_template->source->handler->uncompiled) {
|
||||
if ($_template->smarty->debugging) {
|
||||
$_template->smarty->_debug->start_render($_template);
|
||||
}
|
||||
$this->handler->renderUncompiled($_template->source, $_template);
|
||||
if (isset($_template->parent) && $_template->parent->_objType == 2 && !empty($_template->tpl_function)) {
|
||||
$_template->parent->tpl_function =
|
||||
array_merge($_template->parent->tpl_function, $_template->tpl_function);
|
||||
}
|
||||
if ($_template->smarty->debugging) {
|
||||
$_template->smarty->_debug->end_render($_template);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get source time stamp
|
||||
*
|
||||
|
Reference in New Issue
Block a user