diff --git a/src/Resource/ExtendsPlugin.php b/src/Resource/ExtendsPlugin.php index 1f79d516..3ca3f781 100644 --- a/src/Resource/ExtendsPlugin.php +++ b/src/Resource/ExtendsPlugin.php @@ -2,6 +2,10 @@ namespace Smarty\Resource; +use Smarty\Exception; +use Smarty\Template; +use Smarty\Template\Source; + /** * Smarty Internal Plugin Resource Extends * @@ -24,12 +28,12 @@ class ExtendsPlugin extends BasePlugin /** * populate Source Object with metadata from Resource * - * @param \Smarty\Template\Source $source source object - * @param \Smarty\Template $_template template object + * @param Source $source source object + * @param Template|null $_template template object * - * @throws \Smarty\Exception + * @throws Exception */ - public function populate(\Smarty\Template\Source $source, \Smarty\Template $_template = null) + public function populate(Source $source, Template $_template = null) { $uid = ''; $sources = array(); @@ -37,8 +41,7 @@ class ExtendsPlugin extends BasePlugin $smarty = &$source->smarty; $exists = true; foreach ($components as $component) { - /* @var \Smarty\Template\Source $_s */ - $_s = \Smarty\Template\Source::load(null, $smarty, $component); + $_s = Source::load(null, $smarty, $component); if ($_s->type === 'php') { throw new \Smarty\Exception("Resource type {$_s->type} cannot be used with the extends resource type"); } @@ -60,12 +63,12 @@ class ExtendsPlugin extends BasePlugin /** * populate Source Object with timestamp and exists from Resource * - * @param \Smarty\Template\Source $source source object + * @param Source $source source object */ - public function populateTimestamp(\Smarty\Template\Source $source) + public function populateTimestamp(Source $source) { $source->exists = true; - /* @var \Smarty\Template\Source $_s */ + /* @var Source $_s */ foreach ($source->components as $_s) { $source->exists = $source->exists && $_s->exists; } @@ -75,19 +78,19 @@ class ExtendsPlugin extends BasePlugin /** * Load template's source from files into current template object * - * @param \Smarty\Template\Source $source source object + * @param Source $source source object * * @return string template source * @throws \Smarty\Exception if source cannot be loaded */ - public function getContent(\Smarty\Template\Source $source) + public function getContent(Source $source) { if (!$source->exists) { throw new \Smarty\Exception("Unable to load template '{$source->type}:{$source->name}'"); } $_components = array_reverse($source->components); $_content = ''; - /* @var \Smarty\Template\Source $_s */ + /* @var Source $_s */ foreach ($_components as $_s) { // read content $_content .= $_s->getContent(); @@ -98,11 +101,11 @@ class ExtendsPlugin extends BasePlugin /** * Determine basename for compiled filename * - * @param \Smarty\Template\Source $source source object + * @param Source $source source object * * @return string resource's basename */ - public function getBasename(\Smarty\Template\Source $source) + public function getBasename(Source $source) { return str_replace(':', '.', basename($source->filepath)); } diff --git a/src/Resource/FilePlugin.php b/src/Resource/FilePlugin.php index 2972a653..9ac304c6 100644 --- a/src/Resource/FilePlugin.php +++ b/src/Resource/FilePlugin.php @@ -9,7 +9,7 @@ */ namespace Smarty\Resource; -use Smarty\Smarty; + use Smarty\Template; use Smarty\Template\Source; use Smarty\Exception; diff --git a/src/Runtime/InheritanceRuntime.php b/src/Runtime/InheritanceRuntime.php index 50e55b65..ed7e1fdc 100644 --- a/src/Runtime/InheritanceRuntime.php +++ b/src/Runtime/InheritanceRuntime.php @@ -112,9 +112,7 @@ class InheritanceRuntime { ob_end_clean(); $this->state = 2; } - if (isset($template) && (($tpl->parent->_isTplObj() && $tpl->parent->source->type !== 'extends') - || $tpl->smarty->extends_recursion) - ) { + if (isset($template)) { $tpl->_subTemplateRender( $template, $tpl->cache_id, diff --git a/src/Smarty.php b/src/Smarty.php index 2b732d60..7dede602 100644 --- a/src/Smarty.php +++ b/src/Smarty.php @@ -224,15 +224,6 @@ class Smarty extends \Smarty\TemplateBase */ public $merge_compiled_includes = false; - /* - * flag for behaviour when extends: resource and {extends} tag are used simultaneous - * if false disable execution of {extends} in templates called by extends resource. - * (behaviour as versions < 3.1.28) - * - * @var boolean - */ - public $extends_recursion = true; - /** * force cache file creation * @@ -1026,8 +1017,7 @@ class Smarty extends \Smarty\TemplateBase $this->_normalizeTemplateConfig(false); } $_templateId = $this->_getTemplateId($template, $cache_id, $compile_id); - $tpl = null; - if ($this->caching && isset(\Smarty\Template::$isCacheTplObj[ $_templateId ])) { + if ($this->caching && isset(\Smarty\Template::$isCacheTplObj[ $_templateId ])) { $tpl = $do_clone ? clone \Smarty\Template::$isCacheTplObj[ $_templateId ] : \Smarty\Template::$isCacheTplObj[ $_templateId ]; $tpl->inheritance = null; diff --git a/src/Template.php b/src/Template.php index 4598d0aa..6b6f9d4d 100644 --- a/src/Template.php +++ b/src/Template.php @@ -119,10 +119,6 @@ class Template extends TemplateBase { * @var callback[] */ public $endRenderCallbacks = []; - /** - * @var \Smarty\Compiler\CodeFrame - */ - private $codeFrameCompiler; /** * Create template data object @@ -165,8 +161,6 @@ class Template extends TemplateBase { if ($smarty->security_policy && method_exists($smarty->security_policy, 'registerCallBacks')) { $smarty->security_policy->registerCallBacks($this); } - - $this->codeFrameCompiler = new \Smarty\Compiler\CodeFrame($this); } /** @@ -613,7 +607,7 @@ class Template extends TemplateBase { * @return string */ public function createCodeFrame($content = '', $functions = '', $cache = false, \Smarty\Compiler\Template $compiler = null) { - return $this->codeFrameCompiler->create($content, $functions, $cache, $compiler); + return $this->getFrameCompiler()->create($content, $functions, $cache, $compiler); } /** @@ -895,4 +889,8 @@ class Template extends TemplateBase { $i++; } } + + private function getFrameCompiler(): Compiler\CodeFrame { + return new \Smarty\Compiler\CodeFrame($this); + } } diff --git a/src/Template/Compiled.php b/src/Template/Compiled.php index 259b56c7..0e20e3da 100644 --- a/src/Template/Compiled.php +++ b/src/Template/Compiled.php @@ -64,8 +64,7 @@ class Compiled extends ResourceBase { (int)$smarty->config_overwrite * 4; } else { $this->filepath .= (int)$smarty->merge_compiled_includes + (int)$smarty->escape_html * 2 + - (($smarty->merge_compiled_includes && $source->type === 'extends') ? - (int)$smarty->extends_recursion * 4 : 0); + (($smarty->merge_compiled_includes && $source->type === 'extends') ? 4 : 0); } $this->filepath .= '.' . $source->type; $basename = $source->handler->getBasename($source); diff --git a/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php b/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php index bb47a2a0..dd5c9c42 100644 --- a/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php +++ b/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php @@ -10,10 +10,6 @@ use Smarty\Template; /** * class for extends resource tests - * - * - * - * */ class ExtendsResourceTest extends PHPUnit_Smarty { @@ -48,9 +44,15 @@ class ExtendsResourceTest extends PHPUnit_Smarty $this->smarty->compile_id = 1; } $result = $this->smarty->fetch('extends:003_parent.tpl|003_child_prepend.tpl'); - $this->assertStringContainsString("prepend - Default Title", $result, $testName . ' - content'); - $this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure'); + $this->assertStringContainsString( + "prepend - Default Title", $result, $testName . ' - content'); + $this->assertStringContainsString( + "test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", + $result, + $testName . ' - fetch() failure' + ); } + /** * test child/parent template chain with apppend * @dataProvider data @@ -240,57 +242,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty array(true, true, 8, 7, 7, 'caching, merge - exits'), ); } - /** - * test relative includes in {block} - * @dataProvider data2 - */ - public function testCompileBlockExtendsRecursion_034($extends_recursion, $merge, $testNumber, $compileTestNumber, - $renderTestNumber, $testName) - { - if (!property_exists($this->smarty, 'extends_recursion')) { - $this->markTestSkipped('no extends_recursion'); - } else { - $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); - $this->smarty->assign('test', $testNumber); - $this->smarty->setExtendsRecursion($extends_recursion); - $this->smarty->setMergeCompiledIncludes($merge); - $cid = 0; - if ($merge) { - $cid = 1; - } - if ($extends_recursion) { - $cid += 2; - } - $this->smarty->setCompileId($cid); - $result = $this->smarty->fetch('extends:034_parent.tpl|034_grandchild.tpl'); - $this->assertStringContainsString('grandchild - grandchild', $result, $testName . ' - grand'); - $this->assertStringContainsString('parent - parent', $result, $testName . ' - grand'); - $this->assertStringContainsString($extends_recursion ? 'child - child' : 'child - parent', $result, - $testName . ' - grand'); - $this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", - $result, $testName . ' - fetch() failure'); - } - } - public function data2(){ - return array( - /* - * extends_recursion - * merging - * test nr - * result compile nr - * result render nr - * text - */ - array(false, false, 1, 1, 1, 'no EXTENDS; no merge - new'), - array(false, false, 2, 1, 2, 'no EXTENDS; no merge - exits'), - array(true, false, 3, 3, 3, 'EXTENDS; no merge - new'), - array(true, false, 4, 3, 4, 'EXTENDS; no merge - exits'), - array(false, true, 5, 5, 5, 'no EXTENDS; merge - new'), - array(false, true, 6, 5, 6, 'no EXTENDS; merge - exits'), - array(true, true, 7, 7, 7, 'EXTENDS; merge - new'), - array(true, true, 8, 7, 8, 'EXTENDS; merge - exits'), - ); - } }