- updated error checking at template and config default handler

This commit is contained in:
uwetews
2016-08-05 21:29:15 +02:00
parent 04301645d6
commit 25ad0b3b5a
6 changed files with 34 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
 ===== 3.1.30-dev ===== (xx.xx.xx)  ===== 3.1.30-dev ===== (xx.xx.xx)
05.08.2015 05.08.2015
- bugfix compiling of templates failed when the Smarty delimiter did contain '/' https://github.com/smarty-php/smarty/issues/264 - bugfix compiling of templates failed when the Smarty delimiter did contain '/' https://github.com/smarty-php/smarty/issues/264
- updated error checking at template and config default handler
04.08.2015 04.08.2015
- improvement move template function source parameter into extension - improvement move template function source parameter into extension

View File

@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.30-dev/90'; const SMARTY_VERSION = '3.1.30-dev/91';
/** /**
* define variable scopes * define variable scopes

View File

@@ -44,6 +44,8 @@ class Smarty_Internal_Method_RegisterDefaultTemplateHandler
* get default content from template or config resource handler * get default content from template or config resource handler
* *
* @param Smarty_Template_Source $source * @param Smarty_Template_Source $source
*
* @throws \SmartyException
*/ */
public static function _getDefaultTemplate(Smarty_Template_Source $source) public static function _getDefaultTemplate(Smarty_Template_Source $source)
{ {
@@ -59,12 +61,22 @@ class Smarty_Internal_Method_RegisterDefaultTemplateHandler
$source->exists = is_file($_return); $source->exists = is_file($_return);
if ($source->exists) { if ($source->exists) {
$source->timestamp = filemtime($_return); $source->timestamp = filemtime($_return);
} else {
throw new SmartyException("Default handler: Unable to load " .
($source->isConfig ? 'config' : 'template') .
" default file '{$_return}' for '{$source->type}:{$source->name}'");
} }
$source->filepath = $_return; $source->name = $source->filepath = $_return;
$source->uid = sha1($source->filepath); $source->uid = sha1($source->filepath);
} elseif ($_return === true) { } elseif ($_return === true) {
$source->content = $_content; $source->content = $_content;
$source->exists = true;
$source->uid = $source->name = sha1($_content);
$source->handler = Smarty_Resource::load($source->smarty, 'eval'); $source->handler = Smarty_Resource::load($source->smarty, 'eval');
} else {
$source->exists = false;
throw new SmartyException('Default handler: No ' . ($source->isConfig ? 'config' : 'template') .
" default content for '{$source->type}:{$source->name}'");
} }
} }
} }

View File

@@ -146,6 +146,11 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
*/ */
public function render(Smarty_Internal_Template $_template) public function render(Smarty_Internal_Template $_template)
{ {
// checks if template exists
if (!$_template->source->exists) {
$type = $_template->source->isConfig ? 'config' : 'template';
throw new SmartyException("Unable to load {$type} '{$_template->source->type}:{$_template->source->name}'");
}
if ($_template->smarty->debugging) { if ($_template->smarty->debugging) {
if (!isset($_template->smarty->_debug)) { if (!isset($_template->smarty->_debug)) {
$_template->smarty->_debug = new Smarty_Internal_Debug(); $_template->smarty->_debug = new Smarty_Internal_Debug();

View File

@@ -8,7 +8,7 @@
*/ */
/** /**
* Smarty Connfig Resource Data Object * Smarty Config Resource Data Object
* Meta Data Container for Template Files * Meta Data Container for Template Files
* *
* @package Smarty * @package Smarty
@@ -75,21 +75,24 @@ class Smarty_Template_Config extends Smarty_Template_Source
$template_resource = null) $template_resource = null)
{ {
static $_incompatible_resources = array('extends' => true, 'php' => true); static $_incompatible_resources = array('extends' => true, 'php' => true);
if ($_template) {
$smarty = $_template->smarty;
$template_resource = $_template->template_resource; $template_resource = $_template->template_resource;
}
if (empty($template_resource)) { if (empty($template_resource)) {
throw new SmartyException('Missing config name'); throw new SmartyException('Source: Missing name');
} }
// parse resource_name, load resource handler // parse resource_name, load resource handler
list($name, $type) = list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_config_type);
Smarty_Resource::parseResourceName($template_resource, $_template->smarty->default_config_type);
// make sure configs are not loaded via anything smarty can't handle // make sure configs are not loaded via anything smarty can't handle
if (isset($_incompatible_resources[ $type ])) { if (isset($_incompatible_resources[ $type ])) {
throw new SmartyException ("Unable to use resource '{$type}' for config"); throw new SmartyException ("Unable to use resource '{$type}' for config");
} }
$source = new Smarty_Template_Config($_template->smarty, $template_resource, $type, $name); $source = new Smarty_Template_Config($smarty, $template_resource, $type, $name);
$source->handler->populate($source, $_template); $source->handler->populate($source, $_template);
if (!$source->exists && isset($_template->smarty->default_config_handler_func)) { if (!$source->exists && isset($smarty->default_config_handler_func)) {
Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source); Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
$source->handler->populate($source, $_template);
} }
return $source; return $source;
} }

View File

@@ -163,7 +163,7 @@ class Smarty_Template_Source
$template_resource = $_template->template_resource; $template_resource = $_template->template_resource;
} }
if (empty($template_resource)) { if (empty($template_resource)) {
throw new SmartyException('Missing template name'); throw new SmartyException('Source: Missing name');
} }
// parse resource_name, load resource handler, identify unique resource name // parse resource_name, load resource handler, identify unique resource name
if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]([\s\S]*)$/', $template_resource, $match)) { if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]([\s\S]*)$/', $template_resource, $match)) {
@@ -180,6 +180,7 @@ class Smarty_Template_Source
$source->handler->populate($source, $_template); $source->handler->populate($source, $_template);
if (!$source->exists && isset($_template->smarty->default_template_handler_func)) { if (!$source->exists && isset($_template->smarty->default_template_handler_func)) {
Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source); Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
$source->handler->populate($source, $_template);
} }
return $source; return $source;
} }