mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 01:44:26 +02:00
Fixed all inheritance issues
This commit is contained in:
@@ -103,7 +103,9 @@ class ExtendsTag extends Inheritance {
|
||||
$inlineUids = '';
|
||||
if (isset($template) && $compiler->getSmarty()->merge_compiled_includes) {
|
||||
$code = $compiler->compileTag('include', [$template, ['scope' => 'parent']]);
|
||||
if (preg_match('/([,][\s]*[\'][a-z0-9]+[\'][,][\s]*[\']content.*[\'])[)]/', $code, $match)) {
|
||||
|
||||
// @TODO this relies on the generated code to have a certain format and is sure to break someday
|
||||
if (preg_match('/(,\s*\'[a-z0-9]+\',\s*\'content.*\')/', $code, $match)) {
|
||||
$inlineUids = $match[1];
|
||||
}
|
||||
}
|
||||
|
@@ -222,9 +222,10 @@ class IncludeTag extends Base {
|
||||
if (isset($_assign)) {
|
||||
$_output .= "ob_start();\n";
|
||||
}
|
||||
$_output .= "\$_smarty_tpl->_subTemplateRender({$fullResourceName}, {$_cache_id}, \$_smarty_tpl->compile_id,
|
||||
{$_caching}, {$_cache_lifetime}, {$_vars}, '{$compiler->getParentCompiler()->mergedSubTemplatesData[$uid][$t_hash]['uid']}',
|
||||
'{$compiler->getParentCompiler()->mergedSubTemplatesData[$uid][$t_hash]['func']}', (int) {$_scope});\n";
|
||||
$_output .= "\$_smarty_tpl->renderSubTemplate({$fullResourceName}, {$_cache_id}, \$_smarty_tpl->compile_id, " .
|
||||
"{$_caching}, {$_cache_lifetime}, {$_vars}, " .
|
||||
"'{$compiler->getParentCompiler()->mergedSubTemplatesData[$uid][$t_hash]['uid']}', " .
|
||||
"'{$compiler->getParentCompiler()->mergedSubTemplatesData[$uid][$t_hash]['func']}', (int) {$_scope});\n";
|
||||
if (isset($_assign)) {
|
||||
$_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean(), false, {$_scope});\n";
|
||||
}
|
||||
@@ -239,7 +240,8 @@ class IncludeTag extends Base {
|
||||
if (isset($_assign)) {
|
||||
$_output .= "ob_start();\n";
|
||||
}
|
||||
$_output .= "\$_smarty_tpl->_subTemplateRender({$fullResourceName}, $_cache_id, \$_smarty_tpl->compile_id, $_caching, $_cache_lifetime, $_vars, null, null, (int) {$_scope});\n";
|
||||
$_output .= "\$_smarty_tpl->renderSubTemplate({$fullResourceName}, $_cache_id, \$_smarty_tpl->compile_id, " .
|
||||
"$_caching, $_cache_lifetime, $_vars, null, null, (int) {$_scope});\n";
|
||||
if (isset($_assign)) {
|
||||
$_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean(), false, {$_scope});\n";
|
||||
}
|
||||
|
@@ -24,42 +24,42 @@ class InheritanceRuntime {
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $state = 0;
|
||||
private $state = 0;
|
||||
|
||||
/**
|
||||
* Array of root child {block} objects
|
||||
*
|
||||
* @var \Smarty\Runtime\Block[]
|
||||
*/
|
||||
public $childRoot = [];
|
||||
private $childRoot = [];
|
||||
|
||||
/**
|
||||
* inheritance template nesting level
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $inheritanceLevel = 0;
|
||||
private $inheritanceLevel = 0;
|
||||
|
||||
/**
|
||||
* inheritance template index
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $tplIndex = -1;
|
||||
private $tplIndex = -1;
|
||||
|
||||
/**
|
||||
* Array of template source objects
|
||||
*
|
||||
* @var Source[]
|
||||
*/
|
||||
public $sources = [];
|
||||
private $sources = [];
|
||||
|
||||
/**
|
||||
* Stack of source objects while executing block code
|
||||
*
|
||||
* @var Source[]
|
||||
*/
|
||||
public $sourceStack = [];
|
||||
private $sourceStack = [];
|
||||
|
||||
/**
|
||||
* Initialize inheritance
|
||||
@@ -71,6 +71,7 @@ class InheritanceRuntime {
|
||||
public function init(Template $tpl, $initChild, $blockNames = []) {
|
||||
// if called while executing parent template it must be a sub-template with new inheritance root
|
||||
if ($initChild && $this->state === 3 && (strpos($tpl->template_resource, 'extendsall') === false)) {
|
||||
$tpl->setInheritance(clone $tpl->getSmarty()->getRuntime('Inheritance'));
|
||||
$tpl->getInheritance()->init($tpl, $initChild, $blockNames);
|
||||
return;
|
||||
}
|
||||
@@ -112,7 +113,7 @@ class InheritanceRuntime {
|
||||
$this->state = 2;
|
||||
}
|
||||
if (isset($template)) {
|
||||
$tpl->_subTemplateRender(
|
||||
$tpl->renderSubTemplate(
|
||||
$template,
|
||||
$tpl->cache_id,
|
||||
$tpl->compile_id,
|
||||
|
@@ -105,6 +105,10 @@ class Template extends TemplateBase {
|
||||
*/
|
||||
private $right_delimiter = null;
|
||||
|
||||
/**
|
||||
* @var InheritanceRuntime|null
|
||||
*/
|
||||
private $inheritance;
|
||||
|
||||
/**
|
||||
* Create template data object
|
||||
@@ -242,7 +246,7 @@ class Template extends TemplateBase {
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function _subTemplateRender(
|
||||
public function renderSubTemplate(
|
||||
$template_name,
|
||||
$cache_id,
|
||||
$compile_id,
|
||||
@@ -258,6 +262,7 @@ class Template extends TemplateBase {
|
||||
|
||||
$tpl = $this->getSmarty()->createTemplate($template_name, $cache_id, $compile_id, $this, $caching, $cache_lifetime, $baseFilePath);
|
||||
$tpl->setCached($this->getCached()); // re-use the same Cache object across subtemplates to gather hashes and file dependencies.
|
||||
$tpl->setInheritance($this->getInheritance()); // re-use the same Inheritance object inside the inheritance tree
|
||||
|
||||
if ($scope) {
|
||||
$tpl->setDefaultScope($scope);
|
||||
@@ -512,7 +517,21 @@ class Template extends TemplateBase {
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getInheritance(): InheritanceRuntime {
|
||||
return $this->getSmarty()->getRuntime('Inheritance');
|
||||
if (is_null($this->inheritance)) {
|
||||
$this->inheritance = clone $this->getSmarty()->getRuntime('Inheritance');
|
||||
}
|
||||
return $this->inheritance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new InheritanceRuntime object.
|
||||
*
|
||||
* @param InheritanceRuntime $inheritanceRuntime
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setInheritance(InheritanceRuntime $inheritanceRuntime) {
|
||||
$this->inheritance = $inheritanceRuntime;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -10,10 +10,6 @@ use Smarty\Template;
|
||||
|
||||
/**
|
||||
* class for block extends compiler tests
|
||||
*
|
||||
*
|
||||
* @preserveGlobalState disabled
|
||||
*
|
||||
*/
|
||||
class CompileBlockExtendsTest extends PHPUnit_Smarty
|
||||
{
|
||||
|
Reference in New Issue
Block a user