diff --git a/src/Compile/Tag/BlockClose.php b/src/Compile/Tag/BlockClose.php index 94579ac7..992d4d94 100644 --- a/src/Compile/Tag/BlockClose.php +++ b/src/Compile/Tag/BlockClose.php @@ -84,9 +84,9 @@ class BlockClose extends Inheritance { $compiler->parser->current_buffer = $_buffer; $output = "_cache['blockNesting'] === 1) { - $output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name);\n"; + $output .= "\$_smarty_tpl->getInheritance()->instanceBlock(\$_smarty_tpl, '$_className', $_name);\n"; } else { - $output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name, \$this->tplIndex);\n"; + $output .= "\$_smarty_tpl->getInheritance()->instanceBlock(\$_smarty_tpl, '$_className', $_name, \$this->tplIndex);\n"; } $output .= "?>\n"; --$compiler->_cache['blockNesting']; diff --git a/src/Compile/Tag/Child.php b/src/Compile/Tag/Child.php index 6c1dc925..b775cec9 100644 --- a/src/Compile/Tag/Child.php +++ b/src/Compile/Tag/Child.php @@ -71,7 +71,7 @@ class Child extends Base { if (isset($_assign)) { $output .= "ob_start();\n"; } - $output .= '$_smarty_tpl->inheritance->call' . $this->blockType . '($_smarty_tpl, $this' . + $output .= '$_smarty_tpl->getInheritance()->call' . $this->blockType . '($_smarty_tpl, $this' . ($this->blockType === 'Child' ? '' : ", {$tag}") . ");\n"; if (isset($_assign)) { $output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n"; diff --git a/src/Compile/Tag/ExtendsTag.php b/src/Compile/Tag/ExtendsTag.php index da2bc223..a74919e4 100644 --- a/src/Compile/Tag/ExtendsTag.php +++ b/src/Compile/Tag/ExtendsTag.php @@ -109,7 +109,7 @@ class ExtendsTag extends Inheritance { } $compiler->parser->template_postfix[] = new \Smarty\ParseTree\Tag( $compiler->parser, - 'inheritance->endChild($_smarty_tpl' . + 'getInheritance()->endChild($_smarty_tpl' . (isset($template) ? ", {$template}{$inlineUids}" : '') . ");\n?>" diff --git a/src/Compile/Tag/IncludeTag.php b/src/Compile/Tag/IncludeTag.php index 7e6232cb..ca6e364d 100644 --- a/src/Compile/Tag/IncludeTag.php +++ b/src/Compile/Tag/IncludeTag.php @@ -287,9 +287,6 @@ class IncludeTag extends Base { $uid = $tpl->source->type . $tpl->source->uid; if ($tpl->source->exists) { $compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['uid'] = $tpl->source->uid; - if (isset($compiler->template->inheritance)) { - $tpl->inheritance = clone $compiler->template->inheritance; - } $tpl->compiled = new Compiled(); $tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash; $tpl->loadCompiler(); diff --git a/src/Compile/Tag/Inheritance.php b/src/Compile/Tag/Inheritance.php index 49c8173f..6764651a 100644 --- a/src/Compile/Tag/Inheritance.php +++ b/src/Compile/Tag/Inheritance.php @@ -29,7 +29,7 @@ abstract class Inheritance extends Base */ public static function postCompile(\Smarty\Compiler\Template $compiler, $initChildSequence = false) { - $compiler->prefixCompiledCode .= "_loadInheritance();\n\$_smarty_tpl->inheritance->init(\$_smarty_tpl, " . + $compiler->prefixCompiledCode .= "getInheritance()->init(\$_smarty_tpl, " . var_export($initChildSequence, true) . ");\n?>\n"; } diff --git a/src/Runtime/InheritanceRuntime.php b/src/Runtime/InheritanceRuntime.php index a5b8a107..2dd6ec52 100644 --- a/src/Runtime/InheritanceRuntime.php +++ b/src/Runtime/InheritanceRuntime.php @@ -71,8 +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->inheritance = new InheritanceRuntime(); - $tpl->inheritance->init($tpl, $initChild, $blockNames); + $tpl->getInheritance()->init($tpl, $initChild, $blockNames); return; } ++$this->tplIndex; @@ -227,7 +226,8 @@ class InheritanceRuntime { if (isset($block->parent)) { $this->callBlock($block->parent, $tpl); } else { - throw new Exception("inheritance: illegal '{$tag}' used in child template '{$tpl->inheritance->sources[$block->tplIndex]->filepath}' block '{$block->name}'"); + throw new Exception("inheritance: illegal '{$tag}' used in child template '" . + "{$tpl->getInheritance()->sources[$block->tplIndex]->filepath}' block '{$block->name}'"); } } diff --git a/src/Template.php b/src/Template.php index bd4fb61c..9b685d52 100644 --- a/src/Template.php +++ b/src/Template.php @@ -33,13 +33,6 @@ class Template extends TemplateBase { */ public $source = null; - /** - * Inheritance runtime extension - * - * @var InheritanceRuntime - */ - public $inheritance = null; - /** * Template resource * @@ -479,21 +472,21 @@ class Template extends TemplateBase { } /** - * Load inheritance object + * Helper function for InheritanceRuntime object + * + * @return InheritanceRuntime + * @throws Exception */ - public function _loadInheritance() { - if (!isset($this->inheritance)) { - $this->inheritance = new InheritanceRuntime(); - } + public function getInheritance(): InheritanceRuntime { + return $this->_getSmartyObj()->getRuntime('Inheritance'); } /** - * Unload inheritance object + * Unload event callbacks */ private function _cleanUp() { $this->startRenderCallbacks = []; $this->endRenderCallbacks = []; - $this->inheritance = null; } /**