- compile locking by touching old compiled files to avoid concurrent compilations

This commit is contained in:
Uwe.Tews
2010-03-31 16:23:01 +00:00
parent 24d5ad78f3
commit b52e9f1ac8
7 changed files with 278 additions and 280 deletions

View File

@@ -1,3 +1,6 @@
31/03/2010
- compile locking by touching old compiled files to avoid concurrent compilations
29/03/2010 29/03/2010
- bugfix allow array definitions as modifier parameter - bugfix allow array definitions as modifier parameter
- bugfix observe compile_check property when loading config files - bugfix observe compile_check property when loading config files

View File

@@ -129,6 +129,8 @@ class Smarty extends Smarty_Internal_Data {
public $force_compile = false; public $force_compile = false;
// check template for modifications? // check template for modifications?
public $compile_check = true; public $compile_check = true;
// locking concurrent compiles
public $compile_locking = true;
// use sub dirs for compiled/cached files? // use sub dirs for compiled/cached files?
public $use_sub_dirs = false; public $use_sub_dirs = false;
// compile_error? // compile_error?

View File

@@ -173,88 +173,96 @@ class Smarty_Internal_Config {
{ {
return $this->mustCompile === null ? return $this->mustCompile === null ?
$this->mustCompile = ($this->smarty->force_compile || $this->smarty->compile_check && $this->getCompiledTimestamp () !== $this->getTimestamp ()): $this->mustCompile = ($this->smarty->force_compile || $this->smarty->compile_check && $this->getCompiledTimestamp () !== $this->getTimestamp ()):
$this->mustCompile; $this->mustCompile;
} }
/** /**
* Returns the compiled config file * Returns the compiled config file
* *
* It checks if the config file must be compiled or just read the compiled version * It checks if the config file must be compiled or just read the compiled version
* *
* @return string the compiled config file * @return string the compiled config file
*/ */
public function getCompiledConfig () public function getCompiledConfig ()
{ {
if ($this->compiled_config === null) { if ($this->compiled_config === null) {
// see if template needs compiling. // see if template needs compiling.
if ($this->mustCompile()) { if ($this->mustCompile()) {
$this->compileConfigSource(); $this->compileConfigSource();
} else {
$this->compiled_config = file_get_contents($this->getCompiledFilepath());
}
}
return $this->compiled_config;
}
/**
* Compiles the config files
*/
public function compileConfigSource ()
{
// compile template
if (!is_object($this->compiler_object)) {
// load compiler
$this->compiler_object = new Smarty_Internal_Config_File_Compiler($this->smarty);
}
// call compiler
if ($this->compiler_object->compileSource($this)) {
// compiling succeded
// write compiled template
Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->getCompiledConfig(), $this->smarty);
// make template and compiled file timestamp match
touch($this->getCompiledFilepath(), $this->getTimestamp());
} else { } else {
// error compiling template $this->compiled_config = file_get_contents($this->getCompiledFilepath());
throw new Exception("Error compiling template {$this->getConfigFilepath ()}");
return false;
} }
} }
return $this->compiled_config;
}
/* /**
* Compiles the config files
*/
public function compileConfigSource ()
{
// compile template
if (!is_object($this->compiler_object)) {
// load compiler
$this->compiler_object = new Smarty_Internal_Config_File_Compiler($this->smarty);
}
// compile locking
if ($this->smarty->compile_locking) {
if ($saved_timestamp = $this->getCompiledTimestamp()) {
touch($this->getCompiledFilepath());
}
}
// call compiler
try {
$this->compiler_object->compileSource($this);
}
catch (Exception $e) {
// restore old timestamp in case of error
if ($this->smarty->compile_locking && $saved_timestamp) {
touch($this->getCompiledFilepath(), $saved_timestamp);
}
throw $e;
}
// compiling succeded
// write compiled template
Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->getCompiledConfig(), $this->smarty);
}
/*
* load config variables * load config variables
* *
* @param mixed $sections array of section names, single section or null * @param mixed $sections array of section names, single section or null
* @param object $scope global,parent or local * @param object $scope global,parent or local
*/ */
public function loadConfigVars ($sections = null, $scope) public function loadConfigVars ($sections = null, $scope)
{ {
if (isset($this->template)) { if (isset($this->template)) {
$this->template->properties['file_dependency'][sha1($this->getConfigFilepath())] = array($this->getConfigFilepath(), $this->getTimestamp()); $this->template->properties['file_dependency'][sha1($this->getConfigFilepath())] = array($this->getConfigFilepath(), $this->getTimestamp());
} else {
$this->smarty->properties['file_dependency'][sha1($this->getConfigFilepath())] = array($this->getConfigFilepath(), $this->getTimestamp());
}
$config_data = unserialize($this->getCompiledConfig());
// var_dump($config_data);
// copy global config vars
foreach ($config_data['vars'] as $variable => $value) {
if ($this->smarty->config_overwrite || !isset($scope->config_vars[$variable])) {
$scope->config_vars[$variable] = $value;
} else { } else {
$this->smarty->properties['file_dependency'][sha1($this->getConfigFilepath())] = array($this->getConfigFilepath(), $this->getTimestamp()); $scope->config_vars[$variable] = array_merge((array)$scope->config_vars[$variable], (array)$value);
} }
$config_data = unserialize($this->getCompiledConfig()); }
// var_dump($config_data); // scan sections
// copy global config vars foreach ($config_data['sections'] as $this_section => $dummy) {
foreach ($config_data['vars'] as $variable => $value) { if ($sections == null || in_array($this_section, (array)$sections)) {
if ($this->smarty->config_overwrite || !isset($scope->config_vars[$variable])) { foreach ($config_data['sections'][$this_section]['vars'] as $variable => $value) {
$scope->config_vars[$variable] = $value; if ($this->smarty->config_overwrite || !isset($scope->config_vars[$variable])) {
} else { $scope->config_vars[$variable] = $value;
$scope->config_vars[$variable] = array_merge((array)$scope->config_vars[$variable], (array)$value); } else {
} $scope->config_vars[$variable] = array_merge((array)$scope->config_vars[$variable], (array)$value);
}
// scan sections
foreach ($config_data['sections'] as $this_section => $dummy) {
if ($sections == null || in_array($this_section, (array)$sections)) {
foreach ($config_data['sections'][$this_section]['vars'] as $variable => $value) {
if ($this->smarty->config_overwrite || !isset($scope->config_vars[$variable])) {
$scope->config_vars[$variable] = $value;
} else {
$scope->config_vars[$variable] = array_merge((array)$scope->config_vars[$variable], (array)$value);
}
} }
} }
} }
} }
} }
}
?> ?>

View File

@@ -14,7 +14,6 @@
* Main config file compiler class * Main config file compiler class
*/ */
class Smarty_Internal_Config_File_Compiler { class Smarty_Internal_Config_File_Compiler {
public $compile_error = false;
/** /**
* Initialize compiler * Initialize compiler
*/ */
@@ -59,12 +58,6 @@ class Smarty_Internal_Config_File_Compiler {
$parser->doParse(0, 0); $parser->doParse(0, 0);
$config->compiled_config = serialize($this->config_data); $config->compiled_config = serialize($this->config_data);
if (!$this->compile_error) {
return true;
} else {
// compilation error
return false;
}
} }
/** /**
* display compiler error messages without dying * display compiler error messages without dying
@@ -107,8 +100,6 @@ class Smarty_Internal_Config_File_Compiler {
$error_text .= ' - Unexpected "' . $this->lex->value . '", expected one of: ' . implode(' , ', $expect); $error_text .= ' - Unexpected "' . $this->lex->value . '", expected one of: ' . implode(' , ', $expect);
} }
throw new Exception($error_text); throw new Exception($error_text);
// set error flag
$this->compile_error = true;
} }
} }

View File

@@ -1,22 +1,22 @@
<?php <?php
/** /**
* Smarty Internal Plugin Smarty Template Compiler Base * Smarty Internal Plugin Smarty Template Compiler Base
* *
* This file contains the basic classes and methodes for compiling Smarty templates with lexer/parser * This file contains the basic classes and methodes for compiling Smarty templates with lexer/parser
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
require_once("smarty_internal_parsetree.php"); require_once("smarty_internal_parsetree.php");
/** /**
* Class SmartyTemplateCompiler * Class SmartyTemplateCompiler
*/ */
class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCompilerBase { class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCompilerBase {
/** /**
* Initialize compiler * Initialize compiler
*/ */
public function __construct($lexer_class, $parser_class, $smarty) public function __construct($lexer_class, $parser_class, $smarty)
{ {
$this->smarty = $smarty; $this->smarty = $smarty;
@@ -27,11 +27,11 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
} }
/** /**
* Methode to compile a Smarty template * Methode to compile a Smarty template
* *
* @param $_content template source * @param $_content template source
* @return bool true if compiling succeeded, false if it failed * @return bool true if compiling succeeded, false if it failed
*/ */
protected function doCompile($_content) protected function doCompile($_content)
{ {
/* here is where the compiling takes place. Smarty /* here is where the compiling takes place. Smarty
@@ -39,11 +39,11 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
then written to compiled files. */ then written to compiled files. */
// init the lexer/parser to compile the template // init the lexer/parser to compile the template
$this->lex = new $this->lexer_class($_content, $this); $this->lex = new $this->lexer_class($_content, $this);
$this->parser = new $this->parser_class($this->lex, $this); $this->parser = new $this->parser_class($this->lex, $this);
if (isset($this->smarty->_parserdebug)) $this->parser->PrintTrace(); if (isset($this->smarty->_parserdebug)) $this->parser->PrintTrace();
// get tokens from lexer and parse them // get tokens from lexer and parse them
while ($this->lex->yylex() && !$this->abort_and_recompile) { while ($this->lex->yylex() && !$this->abort_and_recompile) {
if (isset($this->smarty->_parserdebug)) echo "<pre>Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token ".htmlentities($this->lex->value)."</pre>"; if (isset($this->smarty->_parserdebug)) echo "<pre>Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token " . htmlentities($this->lex->value) . "</pre>";
$this->parser->doParse($this->lex->token, $this->lex->value); $this->parser->doParse($this->lex->token, $this->lex->value);
} }
@@ -59,15 +59,9 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
list($_open_tag, $_data) = array_pop($this->_tag_stack); list($_open_tag, $_data) = array_pop($this->_tag_stack);
$this->trigger_template_error("unclosed {" . $_open_tag . "} tag"); $this->trigger_template_error("unclosed {" . $_open_tag . "} tag");
} }
// return compiled code
if (!$this->compile_error) { // return str_replace(array("? >\n<?php","? ><?php"), array('',''), $this->parser->retvalue);
// return compiled code return $this->parser->retvalue;
// return str_replace(array("? >\n<?php","? ><?php"), array('',''), $this->parser->retvalue);
return $this->parser->retvalue;
} else {
// compilation error
return false;
}
} }
} }

View File

@@ -1,18 +1,18 @@
<?php <?php
/** /**
* Smarty Internal Plugin Template * Smarty Internal Plugin Template
* *
* This file contains the Smarty template engine * This file contains the Smarty template engine
* *
* @package Smarty * @package Smarty
* @subpackage Templates * @subpackage Templates
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Main class with template data structures and methods * Main class with template data structures and methods
*/ */
class Smarty_Internal_Template extends Smarty_Internal_Data { class Smarty_Internal_Template extends Smarty_Internal_Data {
// object cache // object cache
public $compiler_object = null; public $compiler_object = null;
@@ -71,16 +71,16 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
public $saved_modifer = null; public $saved_modifer = null;
public $smarty = null; public $smarty = null;
/** /**
* Create template data object * Create template data object
* *
* Some of the global Smarty settings copied to template scope * Some of the global Smarty settings copied to template scope
* It load the required template resources and cacher plugins * It load the required template resources and cacher plugins
* *
* @param string $template_resource template resource string * @param string $template_resource template resource string
* @param object $_parent back pointer to parent object with variables or null * @param object $_parent back pointer to parent object with variables or null
* @param mixed $_cache_id cache id or null * @param mixed $_cache_id cache id or null
* @param mixed $_compile_id compile id or null * @param mixed $_compile_id compile id or null
*/ */
public function __construct($template_resource, $smarty, $_parent = null, $_cache_id = null, $_compile_id = null, $_caching = null, $_cache_lifetime = null) public function __construct($template_resource, $smarty, $_parent = null, $_cache_id = null, $_compile_id = null, $_caching = null, $_cache_lifetime = null)
{ {
$this->smarty = &$smarty; $this->smarty = &$smarty;
@@ -109,12 +109,12 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Returns the template filepath * Returns the template filepath
* *
* The template filepath is determined by the actual resource handler * The template filepath is determined by the actual resource handler
* *
* @return string the template filepath * @return string the template filepath
*/ */
public function getTemplateFilepath () public function getTemplateFilepath ()
{ {
return $this->template_filepath === null ? return $this->template_filepath === null ?
@@ -123,12 +123,12 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Returns the timpestamp of the template source * Returns the timpestamp of the template source
* *
* The template timestamp is determined by the actual resource handler * The template timestamp is determined by the actual resource handler
* *
* @return integer the template timestamp * @return integer the template timestamp
*/ */
public function getTemplateTimestamp () public function getTemplateTimestamp ()
{ {
return $this->template_timestamp === null ? return $this->template_timestamp === null ?
@@ -137,12 +137,12 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Returns the template source code * Returns the template source code
* *
* The template source is being read by the actual resource handler * The template source is being read by the actual resource handler
* *
* @return string the template source * @return string the template source
*/ */
public function getTemplateSource () public function getTemplateSource ()
{ {
if ($this->template_source === null) { if ($this->template_source === null) {
@@ -154,12 +154,12 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Returns if the template is existing * Returns if the template is existing
* *
* The status is determined by the actual resource handler * The status is determined by the actual resource handler
* *
* @return boolean true if the template exists * @return boolean true if the template exists
*/ */
public function isExisting ($error = false) public function isExisting ($error = false)
{ {
if ($this->isExisting === null) { if ($this->isExisting === null) {
@@ -172,12 +172,12 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Returns if the current template must be compiled by the Smarty compiler * Returns if the current template must be compiled by the Smarty compiler
* *
* It does compare the timestamps of template source and the compiled templates and checks the force compile configuration * It does compare the timestamps of template source and the compiled templates and checks the force compile configuration
* *
* @return boolean true if the template must be compiled * @return boolean true if the template must be compiled
*/ */
public function mustCompile () public function mustCompile ()
{ {
$this->isExisting(true); $this->isExisting(true);
@@ -190,10 +190,10 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Returns the compiled template filepath * Returns the compiled template filepath
* *
* @return string the template filepath * @return string the template filepath
*/ */
public function getCompiledFilepath () public function getCompiledFilepath ()
{ {
return $this->compiled_filepath === null ? return $this->compiled_filepath === null ?
@@ -202,10 +202,10 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Returns the timpestamp of the compiled template * Returns the timpestamp of the compiled template
* *
* @return integer the template timestamp * @return integer the template timestamp
*/ */
public function getCompiledTimestamp () public function getCompiledTimestamp ()
{ {
return $this->compiled_timestamp === null ? return $this->compiled_timestamp === null ?
@@ -214,12 +214,12 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Returns the compiled template * Returns the compiled template
* *
* It checks if the template must be compiled or just read from the template resource * It checks if the template must be compiled or just read from the template resource
* *
* @return string the compiled template * @return string the compiled template
*/ */
public function getCompiledTemplate () public function getCompiledTemplate ()
{ {
if ($this->compiled_template === null) { if ($this->compiled_template === null) {
@@ -236,10 +236,10 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Compiles the template * Compiles the template
* *
* If the template is not evaluated the compiled template is saved on disk * If the template is not evaluated the compiled template is saved on disk
*/ */
public function compileTemplateSource () public function compileTemplateSource ()
{ {
if (!$this->resource_object->isEvaluated) { if (!$this->resource_object->isEvaluated) {
@@ -255,17 +255,27 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
$this->smarty->loadPlugin($this->resource_object->compiler_class); $this->smarty->loadPlugin($this->resource_object->compiler_class);
$this->compiler_object = new $this->resource_object->compiler_class($this->resource_object->template_lexer_class, $this->resource_object->template_parser_class, $this->smarty); $this->compiler_object = new $this->resource_object->compiler_class($this->resource_object->template_lexer_class, $this->resource_object->template_parser_class, $this->smarty);
} }
// call compiler // compile locking
if ($this->compiler_object->compileTemplate($this)) { if ($this->smarty->compile_locking && !$this->resource_object->isEvaluated) {
// compiling succeded if ($saved_timestamp = $this->getCompiledTimestamp()) {
if (!$this->resource_object->isEvaluated) { touch($this->getCompiledFilepath());
// write compiled template
Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->compiled_template, $this->smarty);
} }
} else { }
// error compiling template // call compiler
throw new Exception("Error compiling template {$this->getTemplateFilepath ()}"); try {
return false; $this->compiler_object->compileTemplate($this);
}
catch (Exception $e) {
// restore old timestamp in case of error
if ($this->smarty->compile_locking && !$this->resource_object->isEvaluated && $saved_timestamp) {
touch($this->getCompiledFilepath(), $saved_timestamp);
}
throw $e;
}
// compiling succeded
if (!$this->resource_object->isEvaluated) {
// write compiled template
Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->compiled_template, $this->smarty);
} }
if ($this->smarty->debugging) { if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_compile($this); Smarty_Internal_Debug::end_compile($this);
@@ -273,12 +283,12 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Returns the filepath of the cached template output * Returns the filepath of the cached template output
* *
* The filepath is determined by the actual cache resource * The filepath is determined by the actual cache resource
* *
* @return string the cache filepath * @return string the cache filepath
*/ */
public function getCachedFilepath () public function getCachedFilepath ()
{ {
return $this->cached_filepath === null ? return $this->cached_filepath === null ?
@@ -287,12 +297,12 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Returns the timpestamp of the cached template output * Returns the timpestamp of the cached template output
* *
* The timestamp is determined by the actual cache resource * The timestamp is determined by the actual cache resource
* *
* @return integer the template timestamp * @return integer the template timestamp
*/ */
public function getCachedTimestamp () public function getCachedTimestamp ()
{ {
return $this->cached_timestamp === null ? return $this->cached_timestamp === null ?
@@ -301,10 +311,10 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Returns the cached template output * Returns the cached template output
* *
* @return string |booelan the template content or false if the file does not exist * @return string |booelan the template content or false if the file does not exist
*/ */
public function getCachedContent () public function getCachedContent ()
{ {
return $this->rendered_content === null ? return $this->rendered_content === null ?
@@ -313,8 +323,8 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Writes the cached template output * Writes the cached template output
*/ */
public function writeCachedContent ($content) public function writeCachedContent ($content)
{ {
if ($this->resource_object->isEvaluated || !($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED)) { if ($this->resource_object->isEvaluated || !($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED)) {
@@ -326,12 +336,12 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Checks of a valid version redered HTML output is in the cache * Checks of a valid version redered HTML output is in the cache
* *
* If the cache is valid the contents is stored in the template object * If the cache is valid the contents is stored in the template object
* *
* @return boolean true if cache is valid * @return boolean true if cache is valid
*/ */
public function isCached () public function isCached ()
{ {
if ($this->isCached === null) { if ($this->isCached === null) {
@@ -385,12 +395,12 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Render the output using the compiled template or the PHP template source * Render the output using the compiled template or the PHP template source
* *
* The rendering process is accomplished by just including the PHP files. * The rendering process is accomplished by just including the PHP files.
* The only exceptions are evaluated templates (string template). Their code has * The only exceptions are evaluated templates (string template). Their code has
* to be evaluated * to be evaluated
*/ */
public function renderTemplate () public function renderTemplate ()
{ {
if ($this->resource_object->usesCompiler) { if ($this->resource_object->usesCompiler) {
@@ -504,13 +514,13 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Returns the rendered HTML output * Returns the rendered HTML output
* *
* If the cache is valid the cached content is used, otherwise * If the cache is valid the cached content is used, otherwise
* the output is rendered from the compiled template or PHP template source * the output is rendered from the compiled template or PHP template source
* *
* @return string rendered HTML output * @return string rendered HTML output
*/ */
public function getRenderedTemplate () public function getRenderedTemplate ()
{ {
// disable caching for evaluated code // disable caching for evaluated code
@@ -530,14 +540,14 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Parse a template resource in its name and type * Parse a template resource in its name and type
* Load required resource handler * Load required resource handler
* *
* @param string $template_resource template resource specification * @param string $template_resource template resource specification
* @param string $resource_type return resource type * @param string $resource_type return resource type
* @param string $resource_name return resource name * @param string $resource_name return resource name
* @param object $resource_handler return resource handler object * @param object $resource_handler return resource handler object
*/ */
public function parseResourceName($template_resource, &$resource_type, &$resource_name, &$resource_handler) public function parseResourceName($template_resource, &$resource_type, &$resource_name, &$resource_handler)
{ {
if (empty($template_resource)) if (empty($template_resource))
@@ -554,8 +564,8 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* get system filepath to template * get system filepath to template
*/ */
public function buildTemplateFilepath ($file = null) public function buildTemplateFilepath ($file = null)
{ {
if ($file == null) { if ($file == null) {
@@ -590,8 +600,8 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Update Smarty variables in other scopes * Update Smarty variables in other scopes
*/ */
public function updateParentVariables ($scope = SMARTY_LOCAL_SCOPE) public function updateParentVariables ($scope = SMARTY_LOCAL_SCOPE)
{ {
$has_root = false; $has_root = false;
@@ -645,12 +655,12 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Split a template resource in its name and type * Split a template resource in its name and type
* *
* @param string $template_resource template resource specification * @param string $template_resource template resource specification
* @param string $resource_type return resource type * @param string $resource_type return resource type
* @param string $resource_name return resource name * @param string $resource_name return resource name
*/ */
protected function getResourceTypeName ($template_resource, &$resource_type, &$resource_name) protected function getResourceTypeName ($template_resource, &$resource_type, &$resource_name)
{ {
if (strpos($template_resource, ':') === false) { if (strpos($template_resource, ':') === false) {
@@ -671,11 +681,11 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Load template resource handler by type * Load template resource handler by type
* *
* @param string $resource_type template resource type * @param string $resource_type template resource type
* @return object resource handler object * @return object resource handler object
*/ */
protected function loadTemplateResourceHandler ($resource_type) protected function loadTemplateResourceHandler ($resource_type)
{ {
// try registered resource // try registered resource
@@ -718,8 +728,8 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Create property header * Create property header
*/ */
public function createPropertyHeader ($cache = false) public function createPropertyHeader ($cache = false)
{ {
$plugins_string = ''; $plugins_string = '';
@@ -769,8 +779,8 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* Decode saved properties from compiled template and cache files * Decode saved properties from compiled template and cache files
*/ */
public function decodeProperties ($properties) public function decodeProperties ($properties)
{ {
$this->has_nocache_code = $properties['has_nocache_code']; $this->has_nocache_code = $properties['has_nocache_code'];
@@ -788,21 +798,21 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
} }
/** /**
* wrapper for display * wrapper for display
*/ */
public function display () public function display ()
{ {
return $this->smarty->display($this); return $this->smarty->display($this);
} }
/** /**
* wrapper for fetch * wrapper for fetch
*/ */
public function fetch () public function fetch ()
{ {
return $this->smarty->fetch($this); return $this->smarty->fetch($this);
} }
/** /**
* lazy loads (valid) property objects * lazy loads (valid) property objects
* *
@@ -818,10 +828,10 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
// Smarty 2 BC // Smarty 2 BC
$this->_version = self::SMARTY_VERSION; $this->_version = self::SMARTY_VERSION;
return $this->_version; return $this->_version;
} }
return null; return null;
} }
/** /**
* Takes unknown class methods and lazy loads sysplugin files for them * Takes unknown class methods and lazy loads sysplugin files for them
* class name format: Smarty_Method_MethodName * class name format: Smarty_Method_MethodName
@@ -852,12 +862,12 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
else else
return $this->$property_name = $args[0]; return $this->$property_name = $args[0];
} }
} }
} }
/** /**
* wrapper for template class * wrapper for template class
*/ */
class Smarty_Template extends Smarty_Internal_Template { class Smarty_Template extends Smarty_Internal_Template {
} }

View File

@@ -50,8 +50,6 @@ class Smarty_Internal_TemplateCompilerBase {
// flag for nochache sections // flag for nochache sections
$this->nocache = false; $this->nocache = false;
$this->tag_nocache = false; $this->tag_nocache = false;
// assume successfull compiling
$this->compile_error = false;
// save template object in compiler class // save template object in compiler class
$this->template = $template; $this->template = $template;
$this->smarty->_current_file = $this->template->getTemplateFilepath(); $this->smarty->_current_file = $this->template->getTemplateFilepath();
@@ -82,22 +80,16 @@ class Smarty_Internal_TemplateCompilerBase {
} }
// call compiler // call compiler
$_compiled_code = $this->doCompile($_content); $_compiled_code = $this->doCompile($_content);
} while ($this->abort_and_recompile); } while ($this->abort_and_recompile);
if (!$this->compile_error) { // return compiled code to template object
// return compiled code to template object if ($template->suppressFileDependency) {
if ($template->suppressFileDependency) { $template->compiled_template = $_compiled_code;
$template->compiled_template = $_compiled_code;
} else {
$template->compiled_template = $template_header . $template->createPropertyHeader() . $_compiled_code;
}
// run postfilter if required
if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) {
$template->compiled_template = Smarty_Internal_Filter_Handler::runFilter('post', $template->compiled_template, $this->smarty, $template);
}
return true;
} else { } else {
// compilation error $template->compiled_template = $template_header . $template->createPropertyHeader() . $_compiled_code;
return false; }
// run postfilter if required
if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) {
$template->compiled_template = Smarty_Internal_Filter_Handler::runFilter('post', $template->compiled_template, $this->smarty, $template);
} }
} }
@@ -429,9 +421,7 @@ class Smarty_Internal_TemplateCompilerBase {
// output parser error message // output parser error message
$error_text .= ' - Unexpected "' . $this->lex->value . '", expected one of: ' . implode(' , ', $expect); $error_text .= ' - Unexpected "' . $this->lex->value . '", expected one of: ' . implode(' , ', $expect);
} }
throw new Exception($error_text); throw new Exception($error_text);
// set error flag
$this->compile_error = true;
} }
} }