mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
- updated error checking at template and config default handler
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
===== 3.1.30-dev ===== (xx.xx.xx)
|
||||
05.08.2015
|
||||
- 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
|
||||
- improvement move template function source parameter into extension
|
||||
|
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.30-dev/90';
|
||||
const SMARTY_VERSION = '3.1.30-dev/91';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
|
@@ -44,6 +44,8 @@ class Smarty_Internal_Method_RegisterDefaultTemplateHandler
|
||||
* get default content from template or config resource handler
|
||||
*
|
||||
* @param Smarty_Template_Source $source
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public static function _getDefaultTemplate(Smarty_Template_Source $source)
|
||||
{
|
||||
@@ -59,12 +61,22 @@ class Smarty_Internal_Method_RegisterDefaultTemplateHandler
|
||||
$source->exists = is_file($_return);
|
||||
if ($source->exists) {
|
||||
$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);
|
||||
} elseif ($_return === true) {
|
||||
$source->content = $_content;
|
||||
$source->exists = true;
|
||||
$source->uid = $source->name = sha1($_content);
|
||||
$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}'");
|
||||
}
|
||||
}
|
||||
}
|
@@ -146,6 +146,11 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
*/
|
||||
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 (!isset($_template->smarty->_debug)) {
|
||||
$_template->smarty->_debug = new Smarty_Internal_Debug();
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Connfig Resource Data Object
|
||||
* Smarty Config Resource Data Object
|
||||
* Meta Data Container for Template Files
|
||||
*
|
||||
* @package Smarty
|
||||
@@ -75,21 +75,24 @@ class Smarty_Template_Config extends Smarty_Template_Source
|
||||
$template_resource = null)
|
||||
{
|
||||
static $_incompatible_resources = array('extends' => true, 'php' => true);
|
||||
$template_resource = $_template->template_resource;
|
||||
if (empty($template_resource)) {
|
||||
throw new SmartyException('Missing config name');
|
||||
if ($_template) {
|
||||
$smarty = $_template->smarty;
|
||||
$template_resource = $_template->template_resource;
|
||||
}
|
||||
// parse resource_name, load resource handler
|
||||
list($name, $type) =
|
||||
Smarty_Resource::parseResourceName($template_resource, $_template->smarty->default_config_type);
|
||||
if (empty($template_resource)) {
|
||||
throw new SmartyException('Source: Missing name');
|
||||
}
|
||||
// parse resource_name, load resource handler
|
||||
list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_config_type);
|
||||
// make sure configs are not loaded via anything smarty can't handle
|
||||
if (isset($_incompatible_resources[ $type ])) {
|
||||
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);
|
||||
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);
|
||||
$source->handler->populate($source, $_template);
|
||||
}
|
||||
return $source;
|
||||
}
|
||||
|
@@ -163,7 +163,7 @@ class Smarty_Template_Source
|
||||
$template_resource = $_template->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
|
||||
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);
|
||||
if (!$source->exists && isset($_template->smarty->default_template_handler_func)) {
|
||||
Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
|
||||
$source->handler->populate($source, $_template);
|
||||
}
|
||||
return $source;
|
||||
}
|
||||
|
Reference in New Issue
Block a user